Cobbler 是一个用于自动化 Linux 系统安装和配置的工具,可以简化大规模 Linux 安装过程。以下是在 Ubuntu 上使用 Cobbler 实现自动化部署的步骤:
首先,在 Ubuntu 服务器上安装 Cobbler 及其相关组件:
sudo apt update
sudo apt install cobbler cobbler-web dhcp3-server tftpd-hpa xinetd
配置 DHCP 服务器:
编辑 /etc/dhcp/dhcpd.conf
文件,添加以下内容(根据你的网络环境进行修改):
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.200;
option routers 192.168.1.1;
option domain-name-servers 8.8.8.8, 8.8.4.4;
filename "pxelinux.0";
next-server 192.168.1.2;
}
将 192.168.1.0
替换为你的子网,将 192.168.1.1
替换为你的网关,将 192.168.1.2
替换为 Cobbler 服务器的 IP 地址。
编辑 /etc/default/isc-dhcp-server
文件,指定 DHCP 服务器监听的接口:
INTERFACESv4="eth0"
将 eth0
替换为你的网络接口名称。最后,重启 DHCP 服务器:
sudo systemctl restart isc-dhcp-server
配置 TFTP 服务器:
编辑 /etc/xinetd.d/tftp
文件,设置 server_args
参数:
server_args = -s /var/lib/tftpboot
然后,重启 xinetd 服务:
sudo systemctl restart xinetd
配置 Cobbler:
运行以下命令启动 Cobbler 服务并设置开机启动:
sudo systemctl start cobblerd
sudo systemctl enable cobblerd
运行 Cobbler 的配置命令:
sudo cobbler get-loaders
sudo cobbler check
导入 Ubuntu 镜像:
使用 debmirror
工具导入 Ubuntu 镜像。例如,要导入 Ubuntu 20.04 LTS 镜像,运行以下命令(确保将 /path/to/your/mirror
替换为实际路径):
sudo debmirror -a amd64 --method http --dist focal --section main,restricted,universe,multiverse --host archive.ubuntu.com /path/to/your/mirror
添加 Ubuntu 镜像到 Cobbler:
将导入的 Ubuntu 镜像添加到 Cobbler 中:
sudo cobbler import --path /path/to/your/mirror --name ubuntu-20.04
创建 Cobbler Profile:
创建一个新的 Cobbler Profile,用于定义系统安装设置。运行以下命令,将 /path/to/your/preseed.cfg
替换为实际路径:
sudo cobbler profile add --name ubuntu-20.04-profile --distro ubuntu-20.04 --kickstart /path/to/your/preseed.cfg
添加系统到 Cobbler:
创建一个新的 Cobbler 系统,用于定义要安装的目标系统。运行以下命令,将 your-system-name
替换为实际系统名称:
sudo cobbler system add --name your-system-name --profile ubuntu-20.04-profile --interface auto --mac AA:BB:CC:DD:EE:FF
注意:这里的 MAC 地址应该替换为实际的 MAC 地址。
同步 Cobbler 配置:
将 Cobbler 配置同步到 TFTP 服务器:
sudo cobbler sync
现在,当目标系统通过 PXE 启动时,Cobbler 将自动安装 Ubuntu 20.04 LTS。你可以通过 DHCP 服务器分配 IP 地址和其他网络设置,以及使用 preseed.cfg 文件自定义安装过程。