使用 Cobbler 远程管理 Ubuntu 系统的实践指南
一 架构与准备
- 组件与角色:部署一台 Cobbler 服务器(提供 DHCP/TFTP/HTTP 与镜像分发),客户端通过 PXE 引导,使用 preseed(Debian 系)/kickstart(RHEL 系) 完成无人值守安装;远程管理通过 Web 界面 与 API 执行。
- 网络与地址:规划 PXE/管理网段、网关、DNS;在 Cobbler 配置中设置 server(本机地址)与 next_server(TFTP 地址,通常与 server 一致)。
- 安全与访问:启用 HTTPS 访问 Web;为 Web 创建 Digest 账号;必要时为客户端导入 SSH 公钥 以便后续远程运维。
- 基础服务:确保 HTTP/HTTPS、TFTP、DHCP 在防火墙放行;导入 Ubuntu ISO 后可生成对应的 Distro/Profile,供远程装机与复用。
二 安装与初始化配置
- 安装软件包(Ubuntu 示例):
- sudo apt update
- sudo apt install cobbler cobbler-web tftpd-hpa xinetd isc-dhcp-server apache2
- 关键配置(/etc/cobbler/settings):
- server: 192.168.1.10(Cobbler 服务器地址)
- next_server: 192.168.1.10(TFTP 地址)
- manage_dhcp: 1(由 Cobbler 管理 DHCP)
- default_password_crypted: 使用命令生成,例如:openssl passwd -1 ‘YourPassword’
- 引导文件与 TFTP:
- 确保 /var/lib/cobbler/loaders 具备 pxelinux.0/menu.c32 等引导文件;若缺失,可安装 syslinux 并拷贝,或执行 cobbler get-loaders(若可用)。
- 启用 TFTP:编辑 /etc/default/tftpd-hpa 或 /etc/xinetd.d/tftp,设置 TFTP_DIRECTORY=/var/lib/tftpboot,并将 disable=no。
- DHCP 模板(/etc/cobbler/dhcp.template 或 /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.10;
- }
- 初始化与同步:
- sudo systemctl enable --now cobblerd apache2 isc-dhcp-server tftpd-hpa
- sudo cobbler check(逐项修复告警)
- sudo cobbler sync(使 DHCP/TFTP 配置生效)
三 导入 Ubuntu 镜像与创建 Profile
- 挂载并导入 ISO(示例):
- sudo mount -o loop /tmp/ubuntu-20.04.iso /mnt
- sudo cobbler import --path /mnt --name ubuntu-20.04 --arch amd64
- 准备 preseed(Ubuntu 使用 preseed,路径:/var/lib/cobbler/kickstarts/ubuntu-20.04.seed):
- 示例关键项(可按需扩展):
- d-i debian-installer/locale string en_US
- d-i keyboard-configuration/layoutcode string us
- d-i netcfg/choose_interface select auto
- d-i netcfg/get_nameservers string 8.8.8.8 8.8.4.4
- d-i netcfg/get_ipaddress string 192.168.1.101
- d-i netcfg/get_netmask string 255.255.255.0
- d-i netcfg/get_gateway string 192.168.1.1
- d-i netcfg/confirm_static boolean true
- 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 passwd/root-login boolean true
- d-i passwd/root-password-crypted password $1$…(与 default_password_crypted 一致或单独设置)
- d-i pkgsel/include string openssh-server vim
- d-i pkgsel/upgrade select none
- d-i finish-install/reboot_in_progress note
- 创建 Profile 并关联 preseed:
- sudo cobbler profile add --name ubuntu-20.04-amd64 --distro ubuntu-20.04-x86_64 --kickstart /var/lib/cobbler/kickstarts/ubuntu-20.04.seed
- 使配置生效:
四 远程装机与重装
- 基于 MAC 登记主机(System 对象,便于固化 IP/主机名/Profile):
- sudo cobbler system add --name node01 --hostname node01 --mac 52:54:00:12:34:56
–ip-address 192.168.1.101 --subnet 255.255.255.0 --gateway 192.168.1.1
–name-servers 8.8.8.8 8.8.4.4 --profile ubuntu-20.04-amd64
- sudo cobbler sync
- 客户端 PXE 启动后,将自动按 System/Profile 完成安装;如需变更,只需编辑 System 或 Profile 并再次同步。
- 无 PXE 或临时重装:在客户端安装 koan,指定 Cobbler 服务器与要安装的 Profile/System,触发网络重装并自动按 System 参数设置网络:
- koan --server 192.168.1.10 --list=profiles
- koan -r --server 192.168.1.10 --profile ubuntu-20.04-amd64
- 或指定 System:koan -r --server 192.168.1.10 --system node01
- 重启客户端后将自动进入安装流程。
五 远程管理与安全加固
- Web 远程管理:
- 访问 https://<Cobbler_IP>/cobbler_web;默认账号 cobbler/cobbler,建议首次登录后立即修改。
- 修改/添加 Web 账号:htdigest /etc/cobbler/users.digest “Cobbler” username
- 若访问报 Forbidden 或需认证,确认使用 HTTPS 且账号已加入 users.digest 对应 realm。
- API 远程管理(自动化/集成):
- Cobbler 提供 API 接口,可通过脚本或外部系统远程执行镜像导入、Profile/System 管理、装机触发等操作;建议配合 TLS/证书 与 访问控制 使用。
- 防火墙与端口:
- 放行 TCP 80/443(HTTP/HTTPS)、UDP 67/68(DHCP)、UDP/TCP 69(TFTP),确保客户端可达。
- 加固建议:
- 使用 强密码/证书、限制管理网段访问、定期更新 Cobbler 与依赖组件、分离装机网与管理网、审计关键操作。