RancherOS是Rancher Labs設計的小巧、專用的容器操做系統。本文詳細介紹瞭如何使用CloudBoot簡單批量安裝RancherOS。html
做者簡介前端
趙安家,山東順能網絡全棧研發工程師。前端後端通吃,DevOps、安全、培訓都有涉獵,負責了公司從單體服務遷移至微服務的項目。linux
介紹nginx
CloudBootgit
CloudBoot是雲霽科技科技開源的一款簡單易用的裝機系統,相似Cobbler ,可是功能更強大,更易用。(詳情可參閱參考資料的連接)github
RancherOSdocker
RancherOS是Rancher Labs開源的一款容器操做系統,相似coreOS,RancherOS是Rancher Labs設計的小巧、專用的容器操做系統,可用安裝到服務器本地硬盤中,也能夠部署到公有云上,或者配合DockerMachine使用。與Ubuntu和CentOS不一樣,RancherOS使用cloud-config.yml配置文件來管理機器的配置信息,包括系統啓動時的服務、網絡相關的配置信息、存儲配置、容器配置等等,均可以放到配置文件中進行管理。json
安裝cloudbootvim
可參閱CloudBoot一鍵部署 :後端
http://idcos.github.io/osinstall-doc/environment/%E4%B8%80%E9%94%AE%E9%83%A8%E7%BD%B2.html
掛載RancherOS鏡像
wget -P /tmp/ http://releases.rancher.com/os/latest/rancheros.iso mkdir -p $PWD/cloudboot/deploy/iso/rancheros/1.5.1/ mount -o loop /tmp/rancheros.iso /media rsync -a /media/ $PWD/cloudboot/deploy/iso/rancheros/1.5.1/ umount /media
建立軟鏈接
docker exec -it cloudboot /bin/sh ln -s /data/iso/rancheros /home/www/rancheros
注意:
CloudBoot默認用戶名密碼是 admin/admin
登錄後須要配置dhcp(【系統管理】-> 【系統設置】)
須要配置網段(【網段管理】->【應用網段】)
本文講的是VMware,因此不須要配置OOB
須要配置設備位置(【模板管理】->【位置管理】)
若是CloudBoot和RancherOS都裝在VMware虛擬機裏,須要把VMware的網絡設置中的dhcp去掉,不然會衝突
pxe安裝RancherOS
參考RancherOS#docs#iPXE和CloudBoot PXE模板定製規範
RancherOS#docs#iPXE:https://rancher.com/docs/os/v1.x/en/installation/running-rancheros/server/pxe/
CloudBoot PXE模板定製規範:http://idcos.github.io/osinstall-doc/os/PXE%E6%A8%A1%E6%9D%BF%E5%AE%9A%E5%88%B6%E8%A7%84%E8%8C%83.html
PXE模板管理
從【模板管理】->【PXE模板管理】 新增RancherOS-1.5.1
DEFAULT rancheros LABEL rancheros KERNEL http://osinstall.idcos.com/rancheros/1.5.1/boot/vmlinuz-4.14.85-rancher APPEND initrd=http://osinstall.idcos.com/rancheros/1.5.1/boot/initrd-v1.5.1 rancher.cloud_init.datasources=[url:http://osinstall.idcos.com/api/osinstall/v1/device/getSystemBySn?sn={sn}] rancher.autologin=tty1 rancher.autologin=ttyS0 rancher.autologin=ttyS1 rancher.autologin=ttyS1 console=tty1 console=ttyS0 console=ttyS1 printk.devkmsg=on panic=10 IPAPPEND 2
系統模板管理
從【模板管理】->【系統模板管理】 新增rancheros-1.5.1
把docker mirror換成實際的加速器,若是不須要,能夠刪除,ssh_authorized_keys 換成真實的ssh key
#cloud-config rancher: console: alpine docker: registry_mirror: "https://xxx.mirror.aliyuncs.com" runcmd: - sh -c 'curl http://osinstall.idcos.com/scripts/rancheros.sh | bash' ssh_authorized_keys: - ssh-rsa AAAA....ZZZZ user@user
自定義腳本
在CloudBoot宿主機上,運行 docker exec -it cloudboot /bin/sh ,而後運行 vim /home/www/scripts/rancheros.sh
#!/bin/bash progress() { curl -H "Content-Type: application/json" -X POST -d "{\"Sn\":\"$_sn\",\"Title\":\"$1\",\"InstallProgress\":$2,\"InstallLog\":\"$3\"}" http://osinstall.idcos.com/api/osinstall/v1/report/deviceInstallInfo } _sn=$(sed q /sys/class/net/eth0/address)
progress "配置主機名和網絡" 0.7 "6YWN572u5Li75py65ZCN5ZKM572R57uc"
# config network curl -o /tmp/networkinfo "http://osinstall.idcos.com/api/osinstall/v1/device/getNetworkBySn?sn=${_sn}&type=raw" source /tmp/networkinfo cat > /etc/network/interfaces <<EOF auto lo iface lo inet loopback auto eth0 iface eth0 inet static address $IPADDR netmask $NETMASK gateway $GATEWAY EOF echo "$HOSTNAME" > /etc/hostname sudo hostname "$HOSTNAME"
progress "配置alpine鏡像源" 0.8 "6YWN572uYWxwaW5l6ZWc5YOP5rqQ"
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
progress "安裝完成" 1 "5a6J6KOF5a6M5oiQ"
sudo ros install -c http://osinstall.idcos.com/api/osinstall/v1/device/getSystemBySn?sn=$_sn" -d /dev/sda -f
自動化安裝RancherOS
從VMware建立 空盤 -> 其餘Linux4.x或更高版本內核64位,2核2G虛擬機,而後上電 虛擬機會從PXE拉取CloudBoot的bootos 安裝到內存中,而且往CloudBoot上註冊待錄入的設備(待屏幕變藍色)
從 http://${cloudboot host}/#/dashboard/device/scan/list 會發現新設備,選中後,點擊錄入新設備
bootos會自動輪詢是否有自動裝機任務,因此靜候便可。若是等不及,能夠在錄入成功後,手動重啓虛擬機。
在【正在安裝的設備】中,會自動出現要安裝的設備
點擊【詳情】會在滾動模式下試試看到安裝進度
在【設備列表】能夠看到已安裝成功的設備
注意
和Rancher Labs架構師張智博討論後,張智博指出
booting from ISO 首次啓動,整個系統都在內存中。 執行ros install後,安裝bootloader和initrd/vmlinuz到磁盤。 再次啓動後,就是完整的運行在硬盤上的操做系統。
腦洞
能夠在 cloud config 配置自定義服務,這樣裝機後,就能夠直接啓動服務,不須要ssh到ros上,手動執行命令,例如配置Rancher client的添加主機的命令,這樣就能夠直接添加到已有集羣。
更多參考 Custom System Services:
https://rancher.com/docs/os/v1.x/en/installation/system-services/custom-system-services/
#cloud-config rancher: services: nginxapp: image: nginx restart: always
參考資料