温馨提示×

ubuntu cobbler配置步骤有哪些

小樊
36
2026-01-01 20:53:24
栏目: 智能运维

Ubuntu 上部署 Cobbler 的标准流程

一 环境准备与安装

  • 更新索引并安装组件(Ubuntu 使用 APT):
    • 建议安装:cobbler cobbler-web tftp-hpa xinetd isc-dhcp-server apache2 debmirror
    • 命令:sudo apt-get update && sudo apt-get install -y cobbler cobbler-web tftp-hpa xinetd isc-dhcp-server apache2 debmirror
  • 说明:
    • TFTP 用于分发 PXE 引导文件,DHCP 提供 IP 与引导文件名,Apache 提供镜像与 kickstart,debmirror 用于管理 Ubuntu/Debian 仓库镜像,cobbler-web 提供 Web 管理界面。

二 核心配置

  • 修改主配置 /etc/cobbler/settings(将地址替换为你的服务器 IP,例如 10.0.0.2):
    • server: 10.0.0.2
    • next_server: 10.0.0.2
    • 可选:manage_dhcp: 1(由 Cobbler 管理 DHCP,便于后续 cobbler sync 同步配置)
    • 设置 root 默认密码(示例生成 MD5-crypt 密文):
      • 生成:openssl passwd -1 'YourPassword'
      • 写入:default_password_crypted: "$1$...."
  • 启动引导加载器:
    • 执行:sudo cobbler get-loaders(下载 pxelinux.0、menu.c32 等网络引导文件)
  • 配置 DHCP(两种做法,二选一)
    • 由 Cobbler 管理(推荐):编辑 /etc/cobbler/dhcp.template
      • 示例:
        • 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.1;
        • option domain-name-servers 223.5.5.5, 8.8.8.8;
        • filename "pxelinux.0";
        • next-server $next_server;
        • }
    • 由外部 ISC DHCP 管理:编辑 /etc/dhcp/dhcpd.conf,并设置监听接口 /etc/default/isc-dhcp-server(如 INTERFACESv4="eth0"
  • 配置 TFTP:编辑 /etc/xinetd.d/tftp,将 disable = yes 改为 disable = no
  • 配置 Apache 与 WSGI(Ubuntu 常见为启用 cobbler 配置与模块):
    • 启用站点:sudo a2enconf cobbler
    • 启用模块:sudo a2enmod proxy proxy_http
    • 重启 Apache:sudo systemctl restart apache2
  • 可选:允许运行时动态设置(部分版本需要)
    • sudo sed -ri '/allow_dynamic_settings:/c\allow_dynamic_settings: 1' /etc/cobbler/settings
  • 使配置生效:sudo cobbler sync

三 导入镜像与创建系统

  • 导入 Ubuntu 镜像(两种方式)
    • 使用 ISO 挂载导入(适合离线 ISO):
      • 挂载:sudo mount -o loop /path/to/ubuntu-20.04.iso /mnt/iso
      • 导入:sudo cobbler import --path=/mnt/iso --name=ubuntu-20.04 --arch=amd64
    • 使用 debmirror 镜像目录导入(适合网络镜像源):
      • 同步:sudo debmirror -a amd64 --method http --dist focal --section main,restricted,universe,multiverse --host archive.ubuntu.com /path/to/mirror
      • 导入:sudo cobbler import --path=/path/to/mirror --name=ubuntu-20.04
  • 准备应答文件(preseed.cfg,示例关键项)
    • 示例:
      • d-i debian-installer/locale string en_US.UTF-8
      • d-i keyboard-configuration/layoutcode string us
      • d-i netcfg/choose_interface select auto
      • d-i partman-auto/disk string /dev/sda
      • d-i partman-auto/method string regular
      • d-i partman-auto/choose_recipe select boot-root
      • d-i partman-partitioning/confirm_write_new_label boolean true
      • d-i partman/confirm boolean true
      • d-i partman/confirm_nooverwrite boolean true
      • d-i finish-install/reboot_in_progress note
  • 创建 Profile 与 System
    • 创建 Profile:sudo cobbler profile add --name=ubuntu-20.04-profile --distro=ubuntu-20.04-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ubuntu-20.04.seed
    • 注册主机(按 MAC):sudo cobbler system add --name=node01 --profile=ubuntu-20.04-profile --interface=eth0 --mac=AA:BB:CC:DD:EE:FF
  • 同步并验证:sudo cobbler sync,随后在客户端设置 PXE 启动 测试。

四 验证与常见问题

  • 服务状态与连通性
    • 状态:sudo systemctl status cobblerd apache2 isc-dhcp-server xinetd
    • 连通:curl -I http://127.0.0.1/cobbler(应返回 200
    • 配置检查:sudo cobbler check(按提示逐项修复)
  • 常见修复
    • 引导文件缺失:sudo cobbler get-loaders
    • debmirror 配置(Ubuntu/Debian 必需):复制示例配置并注释 /etc/debmirror.conf 中的 @dists@arches
    • TFTP 未启用:确认 /etc/xinetd.d/tftpdisable=no 并已重启 xinetd
    • DHCP 接口:若外部 DHCP,确认 /etc/default/isc-dhcp-serverINTERFACESv4 设置正确
    • UEFI 支持:确保 syslinux 6.x 可用并已放置 elilo.efi 等 UEFI 引导文件(Cobbler 2.9+ 对 UEFI 有更好支持)。

0