聊一聊 Cobbler 3.x 部署實戰(zhàn)
在大批量安裝Linux服務(wù)器系統(tǒng)時,如果手動安裝,則需要花費大量的時間,而使用PXE安裝時,會相對輕松很多。
Cobbler是一個將PXE整套流程合在一起的工具,可以幫我們快速的搭建好PXE安裝所需的各種工具,并且在配置中也更方便。
本文將介紹如何部署Cobbler環(huán)境,并且安裝CentOS7、Ubuntu18作為測試。
文章結(jié)構(gòu)
- 安裝并配置Cobbler
- 安裝Ubuntu18、CentOS7測試
- 常用的操作及報錯處理
部署前的準(zhǔn)備
一臺CentOS8的系統(tǒng),作為cobbler服務(wù)端
- 待安裝的測試機(jī)
- 建議使用VMWare的虛機(jī),啟動比較快,測試方便
詳細(xì)步驟
Cobbler安裝與配置
在準(zhǔn)備好的CentOS8中,按如下步驟操作:
系統(tǒng)的相關(guān)優(yōu)化配置
- 關(guān)閉selinux
- vim /etc/selinux/config
- SELINUX=disabled
調(diào)整后重啟一下系統(tǒng)
- 關(guān)閉firewalld
- systemctl stop firewalld && systemctl disable firewalld
安裝Cobbler及相關(guān)的軟件包
- dnf install epel-release -y && dnf module enable cobbler -y && dnf install cobbler tftp dhcp-server cobbler-web yum-utils pykickstart debmirror fence-agents vim wget -y
生成一個加密密碼,安裝后的系統(tǒng)會將其作為root密碼使用
- # 按照提示輸入兩次想要設(shè)置的密碼,并將生成的加密密碼保存好
- # 以下命令生成的加密密碼的明文是 “password”
- openssl passwd -1
- Password:
- Verifying - Password:
- $1$rLza5zNH$xLKFqWoK32/IA/zslG3Up0
修改cobbler的主配置文件 /etc/cobbler/setting
- # 將 server 和 next_server 修改為本機(jī)的IP地址
- server: 10.1.1.1
- next_server: 10.1.1.1
- manage_tftpd: 1
- manage_dhcp: 1
- # 這里填寫上一步生成的加密密碼
- default_password_crypted: $1$rLza5zNH$xLKFqWoK32/IA/zslG3Up0
修改DHCP的配置模板 /etc/cobbler/dhcp.template
dhcp的模板內(nèi)容較多,僅修改下面設(shè)置中的部分內(nèi)容即可
- # 僅修改以下部分配置即可,根據(jù)自己的測試環(huán)境修改 網(wǎng)關(guān)與待分配的IP
- subnet 10.1.1.0 netmask 255.255.255.0 {
- option routers 10.1.1.254;
- option domain-name-servers 223.5.5.5;
- option subnet-mask 255.255.255.0;
- range dynamic-bootp 10.1.1.100 10.1.1.200;
- filename "/pxelinux.0";
- default-lease-time 21600;
- max-lease-time 43200;
- next-server $next_server;
編輯 /etc/cobbler/tftpd.template
- # default: off
- # description: The tftp server serves files using the trivial file transfer \
- # protocol. The tftp protocol is often used to boot diskless \
- # workstations, download configuration files to network-aware printers, \
- # and to start the installation process for some operating systems.
- service tftp
- {
- disable = no
- socket_type = dgram
- protocol = udp
- wait = yes
- user = $user
- server = $binary
- server_args = -B 1380 -v -s $args
- per_source = 11
- cps = 100 2
- flags = IPv4
- }
開啟相關(guān)的服務(wù)
- systemctl restart cobblerd tftp dhcp && systemctl enable cobblerd tftp dhcpd
執(zhí)行命令 cobbler get-loaders下載相關(guān)的loader組件
執(zhí)行 cobbler check檢查配置,并解決出現(xiàn)的問題
- vim /etc/debmirror.conf
- # 注釋掉以下兩行
- #@dists="sid";
- #@arches="i386";
反復(fù)執(zhí)行 cobbler check,將問題處理完成
執(zhí)行 cobbler sync 生成配置文件并自動重啟相關(guān)的服務(wù)
配置Ubuntu18與CentOS7的鏡像
下載鏡像
- # 下載 ubuntu18 鏡像
- # 注意要從如下鏈接下載,不要在各大鏡像源下載帶 “live” 字樣的系統(tǒng),有 “live” 字樣的操作系統(tǒng)不適用于 seed 文件安裝
- wget http://cdimage.ubuntu.com/ubuntu/releases/bionic/release/ubuntu-18.04.5-server-amd64.iso
- # 下載 centos7鏡像
- wget http://mirrors.163.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-Minimal-2009.iso
掛載鏡像到本地
- mkdir -p /mnt/ubuntu18; mkdir -pv /mnt/centos7
- mount -t iso9660 -o loop,ro /root/ubuntu-18.04.5-server-amd64.iso /mnt/ubuntu18
- mount -t iso9660 -o loop,ro /root/CentOS-7-x86_64-Minimal-2009.iso /mnt/centos7
導(dǎo)入
- cobbler import --name=ubuntu1804 --path=/mnt/ubuntu18
- cobbler import --name=centos7 --path=/mnt/centos7
創(chuàng)建system
- # 獲取到profile的名稱
- cobbler profile list
- # 上一步獲取的 profile 名稱填到 --profile 后面
- cobbler system add --name=ubuntu1804 --profile=ubuntu1804-x86_64
- cobbler system add --name=centos7 --profile=centos7-x86_64
編輯 ubuntu18的seed文件
打開cobbler的web控制臺:https://ip/cobbler_web,用戶名密碼均為 cobbler
點擊左側(cè)的“Templates”,Edit 右側(cè)的 sample.seed,復(fù)制全部內(nèi)容,并新建一個Template文件,可命名為 ubuntu1804.seed
這里僅列出需要修改的地方
- # 我這里調(diào)整了文件系統(tǒng)格式為 ext4,分區(qū)為自動,也可根據(jù)自己的情況調(diào)整
- d-i partman-auto/disk string /dev/sda
- d-i partman-auto/choose_recipe select atomic
- d-i partman-auto/method string regular
- d-i partman-lvm/device_remove_lvm boolean true
- d-i partman-md/device_remove_md boolean true
- d-i partman-partitioning/confirm_write_new_label boolean true
- d-i partman/choose_partition select finish
- d-i partman/confirm boolean true
- d-i partman/confirm_nooverwrite boolean true
- d-i partman/default_filesystem string ext4
- d-i partman/mount_style select uuid
- # 該命令表示可以從 cobbler 的指定目錄下載 os 初始化的腳本,該腳本用于配置 IP 地址或其他的操作
- # 該腳本可以放到 /var/www/cobbler/pub/commands/ 內(nèi)
- d-i preseed/late_command string wget -P /target/root http://$http_server/cblr/pub/commands/ubuntu18_os_start.sh; \
- uname -a
編輯centos的kickstart文件
打開cobbler的web控制臺:https://ip:cobbler_web,用戶名密碼均為 cobbler
點擊左側(cè)的“Templates”,Edit 右側(cè)的 default.ks,復(fù)制全部內(nèi)容,并新建一個Template文件,可命名為 centos7.ks
這里僅列出需要修改的地方
- # Partition clearing information
- # xfs 文件系統(tǒng),boot 分配1g,其余分給 / ,沒有 swap分區(qū)
- clearpart --all --initlabel
- part /boot --asprimary --fstype="xfs" --ondisk=sda --size=1024
- part / --asprimary --fstype="xfs" --ondisk=sda --grow --size=5000
- # 下載 os 初始化的腳本
- curl -o /root/centos7_os_start.sh http://$server/cblr/pub/commands/centos7_os_start.sh
其他配置
完成以上步驟后,cobbler sync 同步一下配置文件
ubuntu 18需要執(zhí)行如下命令,否則 PXE啟動時會報識別光驅(qū)的錯誤,每次 cobbler sync 后,都需要執(zhí)行如下命令
- cp /mnt/ubuntu18/install/netboot/ubuntu-installer/amd64/initrd.gz /var/lib/tftpboot/images/ubuntu1804-x86_64/
安裝測試
創(chuàng)建一臺虛機(jī),注意網(wǎng)卡要和Cobbler在同一個VLAN或廣播域,該網(wǎng)段內(nèi)不要有其他的DHCP服務(wù)器
注意:內(nèi)存要4G或以上,否則會安裝不成功
開機(jī)啟動
選擇 ubuntu18或centos安裝即可,ubuntu18的 hwe 版本的內(nèi)核比較新,對硬件支持更好,可根據(jù)需求選擇
等待自動安裝完成
日常操作與問題解決
cobbler sync 命令
該命令比較常用,很重要,執(zhí)行后會將 /etc/cobbler/ 下的 xxx.template 文件解析后寫到各自的配置文件或 tftp 根目錄以及 /var/www/cobbler 中
執(zhí)行后會重啟部分服務(wù),例如 dhcpd
centos8中安裝cobbler和 centos7安裝的差異
centos8 epel源中的cobbler是3.x版本比較新,建議使用
centos7安裝cobbler在執(zhí)行 get-loaders時會報錯,但是多次執(zhí)行可能會成功
PXE 啟動時報 PXE-E3B TFTP Error
查看一下 /var/lib/tftpboot/grub ,可能沒有 grub.0,如果沒有的話,執(zhí)行一下 /usr/share/cobbler/bin/mkgrub.sh ,會有報錯,但先不用管
到 /var/lib/cobbler/loaders/ 看一下,確認(rèn)是否有 grub 文件夾,如果有的話,應(yīng)該就沒問題了,再 cobbler sync 一下就可以了
參考文檔:
· 官方文檔-Quickstart
· https://asciinema.org/a/351156
· https://askubuntu.com/questions/1235723/automated-20-04-server-installation-using-pxe-and-live-server-image
· https://wiki.ubuntu.com/UEFI/PXE-netboot-install
· https://ubuntu.com/server/docs/install/netboot-amd64