Ubuntu下Cobbler安装配置指南
在开始安装前,确保Ubuntu服务器满足以下条件:
sudo apt update && sudo apt upgrade -ysudo systemctl stop ufw && sudo systemctl disable ufw/etc/selinux/config,将SELINUX=enforcing改为SELINUX=disabled,并执行setenforce 0。Cobbler需要依赖DHCP、TFTP、HTTP等服务,通过以下命令安装:
sudo apt install cobbler cobbler-web dhcp3-server tftpd-hpa xinetd -y
安装完成后,启动Cobbler主服务并设置开机自启:
sudo systemctl start cobblerd
sudo systemctl enable cobblerd
运行sudo cobbler check命令,检查系统配置是否存在问题。常见需修复的问题及解决方法:
The 'server' field in /etc/cobbler/settings must be set to the IP address of this server./etc/cobbler/settings,设置server为服务器本机IP(如192.168.1.2)。The 'next_server' field in /etc/cobbler/settings must point to the TFTP server (usually the same as the Cobbler server)./etc/cobbler/settings,设置next_server为TFTP服务器IP(通常与server相同)。Default password for kickstart files is not set.ubuntu123的加密串):openssl passwd -1 ubuntu123,然后编辑/etc/cobbler/settings,设置default_password_crypted为生成的加密串。编辑/etc/xinetd.d/tftp文件,修改server_args参数,指定TFTP根目录为/var/lib/tftpboot:
sudo sed -i 's/server_args = -s \/var\/lib\/tftpboot$/server_args = -s \/var\/lib\/tftpboot/' /etc/xinetd.d/tftp
重启xinetd服务使配置生效:
sudo systemctl restart xinetd
Cobbler需要通过DHCP为客户端分配IP地址,并告知PXE启动所需的next-server(TFTP服务器)和filename(引导文件)。
编辑/etc/dhcp/dhcpd.conf文件,添加以下内容(根据实际网络环境修改):
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/TFTP服务器IP
}
指定DHCP服务监听的网络接口(如eth0):
sudo sed -i 's/INTERFACESv4=""/INTERFACESv4="eth0"/' /etc/default/isc-dhcp-server
重启DHCP服务:
sudo systemctl restart isc-dhcp-server
Cobbler通过导入操作系统ISO镜像生成可部署的系统镜像。以Ubuntu Server 20.04为例:
/tmp):cp /path/to/ubuntu-20.04.iso /tmp/
cobbler import命令导入镜像,指定镜像路径、名称(后续配置Profile时使用):sudo cobbler import --path=/tmp/ --name=ubuntu-20.04
导入完成后,Cobbler会在/var/www/cobbler/ks_mirror/ubuntu-20.04/目录下生成系统镜像。Profile定义了客户端系统的部署配置(如使用哪个系统镜像、Kickstart文件等)。
编辑默认的Kickstart文件(用于自动化安装):
sudo nano /var/lib/cobbler/kickstarts/default.seed
在文件中添加以下基础配置(根据需求调整):
# Kickstart file automatically generated by anaconda.
text
lang en_US.UTF-8
keyboard us
timezone UTC
rootpw --plaintext ubuntu123
auth --enableshadow --passalgo=sha512
selinux --disabled
firewall --disabled
network --bootproto=dhcp --device=eth0 --onboot=yes
bootloader --location=mbr
zerombr
clearpart --all --initlabel
part / --fstype=ext4 --size=10000
part swap --size=2048
%packages
@^minimal
openssh-server
vim
%end
%post
echo "System installed successfully!" > /etc/motd
%end
创建Profile,关联系统镜像和Kickstart文件:
sudo cobbler profile add --name=ubuntu-20.04 --distro=ubuntu-20.04-x86_64 --kickstart=/var/lib/cobbler/kickstarts/default.seed
其中,--distro参数可通过sudo cobbler distro list查看(即导入镜像时生成的名称)。
为Profile启用PXE启动,允许客户端通过网络启动:
sudo cobbler system add --name=ubuntu-20.04 --profile=ubuntu-20.04
sudo cobbler system edit --name=ubuntu-20.04 --netboot-enabled=true
提交所有配置变更,使设置生效:
sudo cobbler sync
通过以上步骤,即可在Ubuntu服务器上完成Cobbler的安装与配置,实现Ubuntu系统的自动化PXE部署。