1. 安装Cobbler及依赖组件
在Ubuntu服务器上,通过APT包管理器安装Cobbler核心工具、DHCP服务器、TFTP服务器及Web界面等依赖:
sudo apt update sudo apt install cobbler cobbler-web isc-dhcp-server tftpd-hpa xinetd -y 2. 配置DHCP服务器(提供IP与引导文件)
编辑DHCP配置文件/etc/dhcp/dhcpd.conf,添加子网范围、网关、DNS及PXE引导参数(需替换为实际网络环境值):
subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.100 192.168.1.200; # 动态IP分配范围 option routers 192.168.1.1; # 默认网关 option domain-name-servers 8.8.8.8, 8.8.4.4; # DNS服务器 filename "pxelinux.0"; # PXE引导文件名 next-server 192.168.1.2; # Cobbler服务器IP(即本机) } 指定DHCP监听接口(编辑/etc/default/isc-dhcp-server,将INTERFACESv4设置为服务器网卡,如eth0),重启DHCP服务:
sudo systemctl restart isc-dhcp-server 3. 配置TFTP服务器(提供引导文件与安装源)
编辑TFTP配置文件/etc/xinetd.d/tftp,设置TFTP根目录为Cobbler默认路径:
server_args = -s /var/lib/tftpboot 重启xinetd服务使配置生效:
sudo systemctl restart xinetd 4. 配置Cobbler基础参数
启动Cobbler服务并设置开机自启:
sudo systemctl start cobblerd sudo systemctl enable cobblerd 运行cobbler check检查配置完整性,根据提示修复问题(如同步时间、安装缺失工具):
sudo cobbler check 若提示“default_password_crypted未设置”,可通过以下命令生成加密密码并更新(替换your_password为实际root密码):
DEFAULT_PASSWORD=$(openssl passwd -1 "your_password") sudo sed -i "s/default_password_crypted:.*/default_password_crypted: $DEFAULT_PASSWORD/" /etc/cobbler/settings 5. 导入Ubuntu操作系统镜像
将Ubuntu ISO镜像挂载至本地目录(如/mnt/ubuntu-24.04),再通过Cobbler导入(替换为实际ISO路径):
sudo mkdir -p /mnt/ubuntu-24.04 sudo mount -o loop /path/to/ubuntu-24.04-live-server-amd64.iso /mnt/ubuntu-24.04 sudo cobbler import --path=/mnt/ubuntu-24.04 --name=ubuntu-24.04 --arch=amd64 导入完成后,Cobbler会生成对应的distro(如ubuntu-24.04-x86_64)。
6. 创建Kickstart自动化配置文件
在/var/lib/cobbler/kickstarts/目录下创建Kickstart文件(如ubuntu-24.04.ks),定义系统安装参数(需根据Ubuntu版本调整):
# Kickstart file for Ubuntu 24.04 LTS d-i debian-installer/locale string en_US.UTF-8 d-i keyboard-configuration/xkb-keymap select us d-i netcfg/choose_interface select auto d-i netcfg/get_hostname string ubuntu-auto d-i netcfg/get_domain string local.lan d-i mirror/country string manual d-i mirror/http/hostname string archive.ubuntu.com d-i mirror/http/directory string /ubuntu d-i mirror/http/proxy string d-i clock-setup/utc boolean true d-i time/zone string Asia/Shanghai d-i partman-auto/method string lvm 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 passwd/user-fullname string Ubuntu Admin d-i passwd/username string ubuntu d-i passwd/user-password password your_password d-i passwd/user-password-again password your_password d-i user-setup/allow-password-weak boolean true d-i user-setup/encrypt-home boolean false tasksel tasksel/first multiselect standard, ssh-server d-i pkgsel/include string curl wget vim d-i grub-installer/only_debian boolean true d-i grub-installer/with_other_os boolean false d-i finish-install/reboot_in_progress note 保存后,可通过cobbler profile edit命令关联Profile与Kickstart文件。
7. 创建Cobbler Profile(绑定Distro与Kickstart)
创建Profile(如ubuntu-24.04-profile),将导入的distro(ubuntu-24.04-x86_64)与Kickstart文件关联:
sudo cobbler profile add \ --name=ubuntu-24.04-profile \ --distro=ubuntu-24.04-x86_64 \ --kickstart=/var/lib/cobbler/kickstarts/ubuntu-24.04.ks 若需使用云初始化(cloud-init),可修改Profile的kernel_options,添加autoinstall参数(指向Cobbler托管的cloud-init配置):
sudo cobbler profile edit \ --name=ubuntu-24.04-profile \ --kernel-options="autoinstall ds=nocloud-net;s=http://192.168.1.2/cblr/pub/cloud-init/ubuntu-24.04/" 8. 添加目标系统(绑定MAC地址实现全自动)
通过MAC地址绑定目标设备,实现PXE启动时自动匹配Profile并安装(替换为实际MAC地址与IP):
sudo cobbler system add \ --name=ubuntu-auto-01 \ --profile=ubuntu-24.04-profile \ --interface=eth0 \ --mac=00:1A:2B:3C:4D:5E \ --ip-address=192.168.1.100 \ --subnet=255.255.255.0 \ --gateway=192.168.1.1 \ --name-servers="8.8.8.8 114.114.114.114" \ --static=true \ --netboot-enabled=true 批量添加设备时,可将MAC地址、IP等信息写入脚本,循环执行cobbler system add命令。
9. 同步配置并启动自动化安装
修改配置后,运行cobbler sync将更改同步至TFTP、DHCP等服务:
sudo cobbler sync 此时,目标设备通过PXE启动时,将自动获取IP、下载引导文件、读取Kickstart配置,完成Ubuntu系统的无人值守安装。