Cobbler实现Ubuntu批量更新的核心思路
Cobbler本质是自动化部署工具,无法直接实现“在线增量更新”(如apt upgrade),但可通过批量部署新版本Ubuntu系统镜像的方式,达到“批量更新”的效果。其核心逻辑是:将新版本Ubuntu的ISO镜像导入Cobbler,配置对应的PXE启动和自动安装流程,然后让目标客户端通过PXE网络启动,自动安装新系统,替代旧版本。
sudo apt update
sudo apt install -y cobbler cobbler-web dhcp3-server tftpd-hpa xinetd
sudo systemctl enable --now cobblerd httpd dhcpd tftpd-hpa xinetd
sudo cobbler check,根据提示修复问题(如设置server、next_server为本机IP,配置DHCP模板等)。/tmp/ubuntu-24.04.iso)。cobbler import命令将ISO导入,生成对应的“distro”(系统镜像)和“profile”(安装配置):sudo cobbler import --path=/tmp --name=ubuntu-24.04 --arch=amd64
--path:ISO文件所在目录;--name:自定义镜像名称(便于后续识别);--arch:系统架构(如amd64、i386)。为了让客户端自动完成安装,需创建Kickstart配置文件(定义分区、用户、软件源等参数):
sudo cp /var/lib/cobbler/kickstarts/ubuntu.seed /var/lib/cobbler/kickstarts/ubuntu-24.04.seed
/var/lib/cobbler/kickstarts/ubuntu-24.04.seed,关键参数如下:# 设置root密码(用openssl加密,如:openssl passwd -1 "yourpassword")
rootpw --iscrypted $6$your_encrypted_password
# 配置自动分区(推荐使用LVM)
part / --fstype ext4 --size 1 --grow
part swap --size 2048
# 配置软件源(指向Cobbler托管的镜像)
d-i mirror/country string manual
d-i mirror/http/hostname string localhost
d-i mirror/http/directory string /cobbler/ks_mirror/ubuntu-24.04
d-i mirror/http/proxy string
# 配置网络(静态IP或DHCP)
d-i netcfg/choose_interface select auto
d-i netcfg/get_ipaddress string 192.168.1.100
d-i netcfg/get_netmask string 255.255.255.0
d-i netcfg/get_gateway string 192.168.1.1
d-i netcfg/get_nameservers string 8.8.8.8
d-i netcfg/confirm_static boolean true
# 安装完成后重启
d-i finish-install/reboot_in_progress note
sudo cobbler profile edit --name=ubuntu-24.04 --kickstart=/var/lib/cobbler/kickstarts/ubuntu-24.04.seed
sudo cobbler system add --name=ubuntu-client1 --profile=ubuntu-24.04 --mac-address=aa:bb:cc:dd:ee:ff --netboot-enabled=true
--name:客户端名称;--profile:对应的Profile名称;--mac-address:客户端网卡MAC地址(必填,确保快速匹配);--netboot-enabled:启用网络启动。sudo cobbler sync
cobbler system edit命令批量添加客户端(可通过CSV文件解析MAC地址);http://server_ip/cobbler_web)查看部署状态。amd64适用于大多数PC)。通过以上步骤,可实现Ubuntu系统的批量网络部署,替代传统手动安装,大幅提升效率。需注意的是,Cobbler的“更新”本质是“重新部署新系统”,而非在线升级,因此需提前规划好停机时间。