這是堅持技術寫做計劃(含翻譯)的第10篇,定個小目標999,每週最少2篇。php
本文主要講解如何使用cloudboot簡單批量安裝rancheros。html
cloudboot是 雲霽科技 科技開源的一款簡單易用的裝機系統,相似 cobbler ,可是功能更強大,更易用。(可參考我以前寫的 007-Cobbler批量自動化部署Windows10和Server 2019 和 006-Cobbler批量自動化部署CentOS/Ubuntu/Windows) 前端
rancheros 是 rancher lab 開源的一款容器操做系統,相似coreos,RancherOS是RancherLab設計的小巧、專用的容器操做系統,可用安裝到服務器本地硬盤中,也能夠部署到公有云上,或者配合DockerMachine使用。與Ubuntu和CentOS不一樣,RancherOS使用cloud-config.yml配置文件來管理機器的配置信息,包括系統啓動時的服務、網絡相關的配置信息、存儲配置、容器配置等等,均可以放到配置文件中進行管理。linux
參考 cloudboot一鍵部署 很少贅述nginx
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
複製代碼
參考 rancheros#docs#iPXE 和 cloudboot PXE模板定製規範git
從【模板管理】->【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.1github
把docker mirror換成實際的加速器,若是不須要,能夠刪除,ssh_authorized_keys 換成真實的ssh keydocker
#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
json
#!/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 複製代碼
從vmware建立 空盤 -> 其餘Linux4.x或更高版本內核64位,2核2G虛擬機,而後上電
虛擬機會從PXE拉取cloudboot的bootos 安裝到內存中,而且往cloudboot上註冊待錄入的設備(待屏幕變藍色)
http://${cloudboot host}/#/dashboard/device/scan/list
會發現新設備,選中後,點擊錄入新設備
bootos會自動輪詢是否有自動裝機任務,因此靜候便可。若是等不及,能夠在錄入成功後,手動重啓虛擬機。
在【正在安裝的設備】中,會自動出現要安裝的設備
點擊【詳情】會在滾動模式下試試看到安裝進度
在【設備列表】能夠看到已安裝成功的設備
不知道爲嘛,安裝後須要重啓一下虛擬機後,才能使用ssh進行鏈接。
根據rancher labs 大神腩哥指點
booting from ISO 首次啓動,整個系統都在內存中。
執行ros install後,安裝bootloader和initrd/vmlinuz到磁盤。
再次啓動後,就是完整的運行在硬盤上的操做系統。
實際上是正規操做,能夠在 cloud config 配置自定義服務,這樣裝機後,就能夠直接啓動服務,不須要ssh到ros上,手動執行命令,例如配置rancher client的添加主機的命令,這樣就能夠直接添加到已有集羣。 更多參考 Custom System Services
#cloud-config
rancher:
services:
nginxapp:
image: nginx
restart: always
複製代碼
山東濟南的小夥伴歡迎投簡歷啊 加入咱們 , 一塊兒搞事情。
長期招聘,Java程序員,大數據工程師,運維工程師,前端工程師。