安裝 CoreOS – 設定 Hostname

Loading

先來看一下 cloud-config.yaml 關於 Hostname 的設定檔.

#cloud-config
hostname: coreos1
# include one or more SSH public keys
ssh_authorized_keys:
  - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5wZYPD/mBs+9O9CrUxdg9kpOus24VrMuNncdt4BRc4iF5npV90HYe5j/y3IG6+2MRbAb2edyf/FUcaJHN/V+i123456yuqyAT2rv9T0eB2+wpmYCUQzqZscJP2uLK8jMhezKWS0l7X5CgJf+d17VooS6CADR9MyTbku3upKp5yEnsCfB+pBLGdrqCUTnGHPfJcLTBIvuMriz/kae0azxcderfbw7YWR8oKdWjKYKlznnBmH6VYFcgv/jSXbRbdZjKNSXIm2xIj6TIIJmo6sWhptcGohi467ODyrzCDioXD1MsYx6ImTMcY5mzL2RDePAW7CM4gWIMaIxDeL5e10SX ben@appledeAir

這個設定檔只有 hostname 與 ssh-rsa (ssh_authorized_keys 預設的使用者為 core ) 關於 SSH-RSA 請參考 https://benjr.tw/96318

Hostname

設定 hostname 為 coreos1 ,沒有設定就會使用預設 localhost 為 Hostname.

CoreOS 光碟開機後就進入文字模式,直接透過指令 #coreos-install 來安裝.這次有透過 -c 來指定 cloud-init config .

core@localhost ~ $ # sudo coreos-install -d /dev/sda -C stable -c ~/cloud-config.yaml
2016/12/21 09:41:12 Checking availability of "local-file"
2016/12/21 09:41:12 Fetching user-data from datasource of type "local-file"
Downloading the signature for https://stable.release.core-os.net/amd64-usr/1185.3.0/coreos_production_image.bin.bz2...
2016-12-21 09:41:14 URL:https://stable.release.core-os.net/amd64-usr/1185.3.0/coreos_production_image.bin.bz2.sig [543/543] -> "/tmp/coreos-install.fmCj9mKD5k/coreos_production_image.bin.bz2.sig" [1]
Downloading, writing and verifying coreos_production_image.bin.bz2...
...
Success! CoreOS stable 1185.3.0 is installed on /dev/sda
core@localhost ~ $ sudo reboot

使用的參數:
-d ( DEVICE ) – Install CoreOS to the given device.
-C ( CHANNEL ) – Release channel to use (e.g. stable, beta)
-c ( CLOUD ) – Insert a cloud-init config to be executed on boot.

重開機後就可以透過 SSH 來連線.

安裝完之後想修改 CoreOS hostname ,請使用下面指令來修改.需要重開機才會生效.

core@localhost ~ $ sudo hostnamectl set-hostname coreos1
core@localhost ~ $ sudo reboot
core@coreos1 ~ $

臨時性的修改可以透過下面的 指令+修改設定檔 來暫時修改,但重開機就會失效.

core@coreos1 ~ $ vi ~/cloud-config.yaml
#cloud-config
hostname: coreos001
# include one or more SSH public keys
ssh_authorized_keys:
  - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5wZYPD/mBs+9O9CrUxdg9kpOus24VrMuNncdt4BRc4iF5npV90HYe5j/y3IG6+2MRbAb2edyf/FUcaJHN/V+i123456yuqyAT2rv9T0eB2+wpmYCUQzqZscJP2uLK8jMhezKWS0l7X5CgJf+d17VooS6CADR9MyTbku3upKp5yEnsCfB+pBLGdrqCUTnGHPfJcLTBIvuMriz/kae0azxcderfbw7YWR8oKdWjKYKlznnBmH6VYFcgv/jSXbRbdZjKNSXIm2xIj6TIIJmo6sWhptcGohi467ODyrzCDioXD1MsYx6ImTMcY5mzL2RDePAW7CM4gWIMaIxDeL5e10SX ben@appledeAir

core@coreos1 ~ $ sudo coreos-cloudinit --from-file ~/cloud-config.yaml 
2017/01/23 01:44:26 Checking availability of "local-file"
2017/01/23 01:44:26 Fetching user-data from datasource of type "local-file"
2017/01/23 01:44:26 Fetching meta-data from datasource of type "local-file"
2017/01/23 01:44:26 Parsing user-data as cloud-config
2017/01/23 01:44:26 Merging cloud-config from meta-data and user-data
2017/01/23 01:44:26 Set hostname to coreos001
2017/01/23 01:44:26 Authorized SSH keys for core user
2017/01/23 01:44:26 Ensuring runtime unit file "etcd.service" is unmasked
2017/01/23 01:44:26 Ensuring runtime unit file "etcd2.service" is unmasked
2017/01/23 01:44:26 Ensuring runtime unit file "fleet.service" is unmasked
2017/01/23 01:44:26 Ensuring runtime unit file "locksmithd.service" is unmasked
core@coreos1 ~ $ logout
Connection to 172.16.15.129 closed.

透過 ssh 重新遠端連線,登入後會發現 hostname 變不一樣了.

appledeAir:~ ben$ ssh core@172.16.15.129
Enter passphrase for key '/Users/ben/.ssh/id_rsa': 
Last login: Mon Jan 23 01:51:08 UTC 2017 from 172.16.15.1 on pts/0
Container Linux by CoreOS stable (1235.6.0)
core@coreos001 ~ $
沒有解決問題,試試搜尋本站其他內容

One thought on “安裝 CoreOS – 設定 Hostname

  1. 自動引用通知: CoreOS 設定檔 – Benjr.tw

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料