Cobbler 自动化部署服务介绍与部署指南
Cobbler 自动化部署服务介绍与部署指南
一、Cobbler 简介
Cobbler 是一款用于 Linux 服务器自动化安装的工具,通过 PXE 网络启动实现物理机与虚拟机的快速安装、重装,同时集成了 DHCP、DNS、TFTP 等服务的管理功能。
核心优势
- 易用性:相比传统 Kickstart 更易配置,提供命令行、Web 界面及 API 多种管理方式
- 集成度高:内置 PXE、DHCP、TFTP、YUM 仓库等服务,无需单独部署
- 扩展性强:支持与 Puppet 等配置管理工具集成(暂不支持 SaltStack)
官网
https://cobbler.github.io/
二、Cobbler 核心组件与结构
1. 集成服务
- PXE 支持:网络启动基础
- DHCP 管理:自动分配 IP 地址
- DNS 管理:可选 bind 或 dnsmasq
- 电源管理:远程控制服务器开关机
- Kickstart 支持:自动应答安装配置
- YUM 仓库管理:镜像与软件源维护
- TFTP 服务:提供启动镜像
- Apache 服务:提供安装源与 Web 管理界面
2. 配置文件目录(/etc/cobbler
)
配置文件 | 作用 |
---|---|
/etc/cobbler/settings | 主配置文件(核心参数) |
/etc/cobbler/iso/ | ISO 模板配置 |
/etc/cobbler/pxe/ | PXE 模板配置 |
/etc/cobbler/dhcp.template | DHCP 服务配置模板 |
/etc/cobbler/dnsmasq.template | DNS 服务配置模板 |
/etc/cobbler/tftpd.template | TFTP 服务配置模板 |
/etc/cobbler/users.digest | Web 访问的用户名密码(加密存储) |
/etc/cobbler/modules.conf | 模块的配置文件 |
3. 数据目录
目录路径 | 作用 |
---|---|
/var/lib/cobbler/config/ | 存储 distros、profiles 等配置信息 |
/var/lib/cobbler/kickstart/ | 默认存放 Kickstart 自动应答文件 |
/var/lib/cobbler/loaders/ | 引导程序与镜像文件 |
/var/www/cobbler/ks_mirror/ | 导入的发行版系统数据 |
/var/www/cobbler/images/ | 网络启动用的 kernel 和 initrd 镜像 |
/var/www/cobbler/repo_mirror/ | yum仓库存储目录 |
4. 日志文件
日志路径 | 说明 |
---|---|
/var/log/cobbler/installing | 客户端安装日志 |
/var/log/cobbler/cobbler.log | Cobbler 服务运行日志 |
5. 常用命令
命令 | 功能 |
---|---|
cobbler check | 核对当前设置是否有问题 |
cobbler list | 列出所有 Cobbler 元素 |
cobbler report | 显示元素详细信息 |
cobbler sync | 同步配置到数据目录(必执行) |
cobbler reposync | 同步 YUM 仓库 |
cobbler distro | 查看导入的发行版系统信息 |
cobbler profile | 查看配置信息 |
cobbler system | 查看添加的系统信息 |
三、Cobbler 服务端部署(CentOS 7 IP:192.168.100.20)
1. 环境准备
[root@zhangyiwei-2 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo # 配置 YUM 源(阿里云镜像)% Total % Received % Xferd Average Speed Time Time Time CurrentDload Upload Total Spent Left Speed
100 2523 100 2523 0 0 15009 0 --:--:-- --:--:-- --:--:-- 15017[root@zhangyiwei-2 ~]# yum -y install epel-release # 安装 EPEL 源(提供 Cobbler 包)
已加载插件:fastestmirror, langpacks
Determining fastest mirrors****************省略****************
已安装:epel-release.noarch 0:7-11 完毕!
2. 安装Cobbler与依赖包
[root@zhangyiwei-2 ~]# yum -y install httpd dhcp* tftp tftp-server cobbler cobbler-web pykickstart rsync rsync-daemon
已加载插件:fastestmirror, langpacks********省略*******完毕!
3. 启动基础服务
[root@zhangyiwei-2 ~]# systemctl restart httpd && systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@zhangyiwei-2 ~]# systemctl restart rsyncd && systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
[root@zhangyiwei-2 ~]# systemctl restart tftp && systemctl enable tftp
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
[root@zhangyiwei-2 ~]# systemctl restart cobblerd && systemctl enable
Too few arguments.
4. 关闭防火墙与 SELinux
[root@zhangyiwei-2 ~]# systemctl stop firewalld && systemctl disable firewalld
[root@zhangyiwei-2 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@zhangyiwei-2 ~]# reboot # 重启使 SELinux 配置生效
5. 配置 Cobbler 主参数
# 设置服务器 IP(本机 IP)
[root@zhangyiwei-2 ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.100.20/' /etc/cobbler/settings# 设置 TFTP 服务器 IP(本机 IP)
[root@zhangyiwei-2 ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.100.20/' /etc/cobbler/settings# 生成 root 密码加密串(示例密码为 redhat)
[root@zhangyiwei-2 ~]# openssl passwd -1 -salt "$RANDOM" 'redhat'
$1$23475$RtjGDxor8DF65Z4P3AABI1 # 替换为实际生成的加密串# 配置默认密码(用于客户端 root 用户)
[root@zhangyiwei-2 ~]# vim /etc/cobbler/settingsdefault_password_crypted: "$1$23475$RtjGDxor8DF65Z4P3AABI1" # 填入加密串# 启用 DHCP 管理
[root@rhel7 ~]# sed -i "s/manage_dhcp: 0/manage_1: 1/" /etc/cobbler/settings
#( 或者输入 sed -i "s#manage_dhcp: false#manage_dhcp: true#"/etc/cobbler/settings 不确定manage_dhcp的值直接搜索 manage_dhcp 关键字并强制改为 1: )# 重启 Cobbler 服务
[root@zhangyiwei-2 ~]# systemctl restart cobblerd
# 同步配置
[root@zhangyiwei-2 ~]# cobbler sync
task started: 2025-08-20_193830_sync
task started (id=Sync, time=Wed Aug 20 19:38:30 2025)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /usr/share/syslinux/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /usr/share/syslinux/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout:
received on stderr:
running: service dhcpd restart
received on stdout:
received on stderr: Redirecting to /bin/systemctl restart dhcpd.service
Job for dhcpd.service failed because the control process exited with error code. See "systemctl status dhcpd.service" and "journalctl -xe" for details.Exception occured: <class 'cobbler.cexceptions.CX'>
Exception value: 'cobbler trigger failed: cobbler.modules.sync_post_restart_services'
Exception Info:File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 82, in runrc = self._run(self)File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 173, in runnerreturn self.remote.api.sync(self.options.get("verbose",False),logger=self.logger)File "/usr/lib/python2.7/site-packages/cobbler/api.py", line 749, in syncreturn sync.run()File "/usr/lib/python2.7/site-packages/cobbler/action_sync.py", line 144, in runutils.run_triggers(self.api, None, "/var/lib/cobbler/triggers/sync/post/*", logger=self.logger)File "/usr/lib/python2.7/site-packages/cobbler/utils.py", line 928, in run_triggersraise CX("cobbler trigger failed: %s" % m.__name__)!!! TASK FAILED !!!
6. 解决配置检查问题
# 执行检查命令
[root@zhangyiwei-2 ~]# cobbler check
The following are potential configuration items that you may want to fix:1: some network boot-loaders are missing from /var/lib/cobbler/loaders. If you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely. Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, and yaboot.
2: reposync is not installed, install yum-utils or dnf-plugins-core
3: yumdownloader is not installed, install yum-utils or dnf-plugins-core
4: debmirror package is not installed, it will be required to manage debian deployments and repositories
5: fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use themRestart cobblerd and then run 'cobbler sync' to apply changes.
[root@zhangyiwei-2 ~]# # 根据输出解决以下问题:# 问题 1:缺少 PXE 引导文件
[root@zhangyiwei-2 ~]# yum -y install syslinux*
[root@zhangyiwei-2 ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
[root@zhangyiwei-2 ~]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
[root@zhangyiwei-2 ~]# ls /var/lib/cobbler/loaders/
menu.c32 pxelinux.0# 问题 2、3:缺少 yum-utils
[root@zhangyiwei-2 ~]# yum -y install yum-utils#问题4和问题5可以忽略,因为是debian系统才需要解决,显示使用的是centos8Debian系统解决办法安装fence-agents
7. 配置 DHCP 服务
[root@zhangyiwei-2 ~]# vim /etc/cobbler/dhcp.template
# 修改子网配置(根据实际网络调整)
subnet 192.168.100.0 netmask 255.255.255.0 {option routers 192.168.100.254; # 网关option domain-name-servers 8.8.8.8; # DNSrange dynamic-bootp 192.168.100.100 192.168.100.110; # IP 池next-server $next_server; # 指向 TFTP 服务器
}
8. 同步配置
[root@zhangyiwei-2 ~]# cobbler sync # 同步所有配置到服务******省略*******
*** TASK COMPLETE ***
四、导入操作系统镜像
1. 挂载镜像
[root@zhangyiwei-2 ~]# mount /dev/cdrom /mnt/ # 挂载 CentOS 7 镜像
mount: /dev/sr0 写保护,将以只读方式挂载
2. 导入镜像
[root@zhangyiwei-2 ~]# cobbler import --path=/mnt/ --name=CentOS-7 arch=x86_64
task started: 2025-08-20_195017_import
task started (id=Media import, time=Wed Aug 20 19:50:17 2025)
Found a candidate signature: breed=suse, version=opensuse15.0
Found a candidate signature: breed=suse, version=opensuse15.1
Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
Adding distros from path /var/www/cobbler/ks_mirror/CentOS-7:
creating new distro: CentOS-7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS-7 -> /var/www/cobbler/links/CentOS-7-x86_64
creating new profile: CentOS-7-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/CentOS-7 for CentOS-7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS-7
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS-7
looking for /var/www/cobbler/ks_mirror/CentOS-7/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS-7/repodata
*** TASK COMPLETE ***--path=/mnt/ # 镜像挂载路径
--name=CentOS-7 # 自定义镜像名称
--arch=x86_64 # 架构(32位为 i386)
3. 验证导入结果
[root@zhangyiwei-2 ~]# cobbler list
distros:CentOS-7-x86_64 # 导入的镜像名称profiles:CentOS-7-x86_64systems:repos:images:mgmtclasses:packages:files:# 查看镜像详情
[root@zhangyiwei-2 ~]# cobbler distro report --name=CentOS-7-x86_64
Name : CentOS-7-x86_64
Architecture : x86_64
TFTP Boot Files : {}
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/ks_mirror/CentOS-7/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/ks_mirror/CentOS-7/images/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS-7-x86_64'}
Management Classes : []
OS Version : rhel6
Owners : ['admin']
Red Hat Management Key : <<inherit>>
Red Hat Management Server : <<inherit>>
Template Files : {}
此时就可以启动客户端进行网络安装:
五、总结
Cobbler 简化了大规模 Linux 服务器的部署流程,通过集成 PXE、DHCP 等服务实现自动化安装。核心步骤包括:
- 安装并配置 Cobbler 服务
- 解决配置检查中的依赖问题
- 导入操作系统镜像
- 同步配置并启动客户端进行网络安装
后续可通过 Web 界面(http://服务器IP/cobbler_web
)进一步管理镜像、配置文件和客户端。