温馨提示×

怎样用debian cobbler装机

小樊
48
2026-09-27 23:19:35
栏目: 智能运维

下面给你一个**在 Debian 上用 Cobbler 批量装机(PXE 自动安装)**的实战流程,适合从零开始。以 Debian 11/12 + Cobbler 3.x 为例。


一、环境准备

1. 系统要求

  • 一台 Debian 作为 Cobbler Server(建议静态 IP)
  • 客户端支持 PXE 启动
  • 同网段或经 DHCP 中继

2. 安装基础软件

sudo apt update
sudo apt install -y cobbler cobbler-web tftp tftp-hpa xinetd \
  isc-dhcp-server apache2 debmirror

有些 Debian 版本 cobbler 在 backports 中,可自行启用。


二、Cobbler 基础配置

1. 修改 Cobbler 设置

编辑 /etc/cobbler/settings.yaml(或 .yaml 新版):

server: 192.168.1.10
next_server: 192.168.1.10
manage_dhcp: 1
manage_tftp: 1
pxe_just_once: 1

server 和 next_server 改成你的 Cobbler IP

2. 配置 DHCP

编辑 /etc/cobbler/dhcp.template:

subnet 192.168.1.0 netmask 255.255.255.0 {
     option routers             192.168.1.1;
     option domain-name-servers 8.8.8.8;
     range 192.168.1.100 192.168.1.200;
}

然后:

cobbler sync

三、导入 Debian 镜像

1. 挂载 ISO

mount -o loop debian-12-amd64-DVD-1.iso /mnt

2. 导入到 Cobbler

cobbler import --path=/mnt --name=debian12 --arch=x86_64

查看:

cobbler distro list

四、创建自动安装文件(preseed)

1. 示例 preseed

/var/lib/cobbler/kickstarts/debian12.seed

d-i debian-installer/locale string en_US
d-i keyboard-configuration xkb-keymap select us
d-i netcfg/get_hostname string debian
d-i mirror/country string manual
d-i mirror/http/hostname string ftp.de.debian.org
d-i mirror/http/directory string /debian
d-i partman-auto/method string lvm
d-i partman-auto/choose_recipe select atomic
d-i passwd/root-password password rootpw
d-i passwd/root-password-again password rootpw
d-i finish-install/reboot_in_progress note

五、创建 Profile 和 System

1. 关联 profile

cobbler profile add \
  --name=debian12-auto \
  --distro=debian12-x86_64 \
  --kickstart=/var/lib/cobbler/kickstarts/debian12.seed

2. (可选)绑定具体机器

cobbler system add \
  --name=node01 \
  --profile=debian12-auto \
  --mac=00:11:22:33:44:55

六、启动服务

systemctl enable --now cobblerd
systemctl enable --now apache2
systemctl enable --now tftpd-hpa
cobbler sync

七、客户端装机

  1. 客户端 BIOS 设置 PXE Boot
  2. 开机 → 进入 Cobbler 菜单
  3. 选择 debian12-auto
  4. 自动完成安装

八、常见问题

1. 客户端拿不到 IP

  • DHCP 没起
  • Cobbler IP 和 next_server 不一致

2. 卡在 TFTP

cobbler sync
systemctl restart tftpd-hpa

3. 安装中途问问题

preseed 不完整,需补全模块


九、进阶建议

  • 用 cobbler web 管理
  • 结合 ansible 做装后初始化
  • 多系统(CentOS / Ubuntu)共存

如果你愿意,我可以:

  • 给你 完整 preseed 模板
  • 帮你 适配 UEFI / BIOS
  • 或写 一键部署脚本

你现在是 BIOS 还是 UEFI?装机规模大概多少台?

0 踩