温馨提示×

如何通过Cobbler批量安装Ubuntu

小樊
50
2025-11-23 13:31:11
栏目: 智能运维

通过 Cobbler 批量安装 Ubuntu 的完整流程

一 环境准备与组件安装

  • 准备一台可长期运行的服务器(如 CentOS 7/8、Rocky 9Ubuntu 20.04+),与待装机在同一二层网络,规划好 PXE 网段、网关、DNS、IP 分配范围
  • 安装必要组件(以 RHEL/CentOS/Rocky 系为例):
    • yum 安装:cobbler cobbler-web dhcp tftp-server httpd pykickstart rsync xinetd
    • Ubuntu/Debian 系:cobbler cobbler-web isc-dhcp-server tftpd-hpa xinetd debmirror
  • 建议准备 Ubuntu Server ISO(如 20.04/22.04 LTS),后续用于导入镜像与自动应答文件。

二 配置 Cobbler 核心参数

  • 修改 /etc/cobbler/settings
    • 设置 servernext_server 为本机 IP(例如 10.0.0.5)。
    • 如由 Cobbler 托管 DHCP,将 manage_dhcp: 1;否则保持 0 并由外部 DHCP 提供服务。
    • 生成 root 默认密码并写入 default_password_crypted
      • 生成示例:openssl passwd -1 'YourPassword'
  • 启动/重启服务并加载网络引导文件:
    • systemd 系:systemctl enable --now cobblerd httpd tftp(xinetd 托管 tftp 时同时启用 xinetd)
    • 加载引导器:cobbler get-loaders
  • 检查并修复:cobbler check(务必清零告警后再继续)。

三 配置 DHCP 与 TFTP

  • DHCP(若由 Cobbler 托管,编辑 /etc/cobbler/dhcp.template;否则编辑 /etc/dhcp/dhcpd.conf):
    • 关键项:subnetrangeoption routersoption domain-name-serversfilename “pxelinux.0”next-server $next_server
    • 示例片段:
      • subnet 10.0.0.0 netmask 255.255.255.0 {
      •   range dynamic-bootp 10.0.0.100 10.0.0.200;
      •   option routers 10.0.0.2;
      •   option domain-name-servers 114.114.114.114;
      •   filename “/pxelinux.0”;
      •   next-server 10.0.0.5;
      • }
  • TFTP:
    • 启用服务:编辑 /etc/xinetd.d/tftp,将 disable = yes 改为 disable = no,然后重启 xinetd/tftp。

四 导入 Ubuntu 镜像并创建应答文件

  • 导入 ISO(两种常用方式,二选一或结合使用):
    • 直接导入 ISO 内容:cobbler import --path=/mnt/iso --name=ubuntu20.04 --arch=x86_64
    • 导入后关联预置应答文件(preseed/seed):cobbler import --name ubuntu20 --path /mnt/ --autoinstall ubuntu.seed
  • 准备 Ubuntu 预置文件(preseed/seed,示例路径 /var/lib/cobbler/kickstarts/ubuntu.seed/var/lib/cobbler/templates/ubuntu.seed):
    • 常用关键项(按需调整):
      • 语言与键盘:d-i debian-installer/locale string en_USd-i keyboard-configuration/layoutcode string us
      • 时区与 NTP:d-i time/zone string Asia/Shanghaid-i clock-setup/ntp boolean trued-i clock-setup/ntp-server string ntp1.aliyun.com
      • 安装源(使用 Cobbler 变量):d-i mirror/http/hostname string $http_serverd-i mirror/http/directory string $install_source_directory
      • 对于 12.10+ 使用 live installer 的镜像路径:d-i live-installer/net-image string http://$http_server/cobbler/links/$distro_name/install/filesystem.squashfs
      • 分区示例(全自动 LVM):
        • d-i partman-auto/method string lvm
        • d-i partman-lvm/device_remove_lvm boolean true
        • d-i partman-auto/purge_lvm boolean true
        • d-i partman-auto/choose_recipe select atomic
        • d-i partman-partitioning/confirm_write_new_label boolean true
        • d-i partman/confirm boolean true
        • d-i partman/confirm_nooverwrite boolean true
  • 将预置文件绑定到 Profile:
    • 查看导入结果:cobbler distro listcobbler profile list
    • 绑定/编辑:cobbler profile add --name ubuntu20.04 --distro ubuntu20.04-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ubuntu.seed
    • 或:cobbler profile edit --name ubuntu20.04-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ubuntu.seed
  • 同步配置:cobbler sync(每次修改后务必执行)。

五 批量部署与常见问题处理

  • 批量部署与主机管理:
    • 按 MAC 登记主机,实现一机一配置(推荐):
      • cobbler system add --name host01 --profile ubuntu20.04-x86_64 --mac AA:BB:CC:DD:EE:FF --netboot-enabled 1
      • 如需静态 IP:cobbler system edit --name host01 --interface eth0 --static 1 --ip-address 10.0.0.101 --netmask 255.255.255.0 --gateway 10.0.0.2 --dns-nameservers 114.114.114.114
    • 也可使用 profile 级默认配置进行“无差别”批量安装(适合同构环境)。
  • 客户端 PXE 启动后,在菜单选择相应 Profile 进入无人值守安装;安装完成后使用预设的 root 密码登录。
  • 常见问题速查:
    • cobblerd does not appear to be running/accessible:启动服务 systemctl start cobblerd httpd 后再试。
    • httpd Syntax error ... WSGIScriptAliasMatch:启用 mod_wsgi 模块(LoadModule wsgi_module …)。
    • cobbler check 告警未清零:按提示逐项修复,常见为 TFTP/SELinux/防火墙、未加载引导器、DHCP 模板不一致等,修复后 cobbler sync
    • 使用外部/AD 的 DHCP 时,PXE 获取地址慢或失败:在 PXE 默认菜单中为内核参数增加 dhcp_timeout=120,提升获取地址的容错。

0