- A+
Cobbler
是一个系统启动服务(boot server)
,可以通过网络启动(PXE)
的方式用来快速安装、重装物理服务器和虚拟机,支持安装不同的Linux
发行版和Windows
系统,下文将通过先部署一台Cobbler服务,然后在一台空虚拟机上安装centos7.6操作系统,演示其使用方法。
1.环境准备
准备2台虚拟机,1台安装Cobbler
服务,及DHCP
、HTTPD
、TFTP
服务,另一台作为裸机,不安装操作系统。
服务名 | IP地址 | 安装软件 |
---|---|---|
Cobbler服务端 | 10.129.10.224 | Cobbler、DHCP、HTTPD、TFTP |
裸机 |
2.部署Cobbler服务
2.1关闭防火墙和SElinux
- [root@cobbler ~]# systemctl stop firewalld
- [root@cobbler ~]# systemctl disable firewalld
- Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
- Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
- [root@cobbler ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
- [root@cobbler ~]# setenforce 0
- [root@cobbler ~]#
2.2安装cobbler及相关软件
先安装EPEL
源
- [root@cobbler ~]# yum -y install epel-release
- 已加载插件:fastestmirror, langpacks
- Loading mirror speeds from cached hostfile
- * base: mirrors.huaweicloud.com
- * extras: mirrors.huaweicloud.com
- * updates: mirrors.ustc.edu.cn
- 正在解决依赖关系
- --> 正在检查事务
- ---> 软件包 epel-release.noarch.0.7-11 将被 安装
- --> 解决依赖关系完成
- ……
然后再安装(这里安装过程有点问题,分别安装Cobbler和cobbler-web
:
- [root@cobbler ~]# yum -y install httpd dhcp tftp python-ctypes cobbler xinetd cobbler-web pykickstart net-tools
- 已加载插件:fastestmirror, langpacks
- Determining fastest mirrors
- * base: mirrors.huaweicloud.com
- * extras: mirrors.huaweicloud.com
- * updates: mirrors.ustc.edu.cn
- base | 3.6 kB 00:00:00
- extras | 2.9 kB 00:00:00
- updates | 2.9 kB 00:00:00
- (1/4): base/7/x86_64/group_gz | 153 kB 00:00:00
- (2/4): extras/7/x86_64/primary_db | 250 kB 00:00:00
- (3/4): base/7/x86_64/primary_db | 6.1 MB 00:00:01
- (4/4): updates/7/x86_64/primary_db | 23 MB 00:00:05
- 没有可用软件包 cobbler。
- 没有可用软件包 cobbler-web。
- 正在解决依赖关系
- --> 正在检查事务
- ---> 软件包 dhcp.x86_64.12.4.2.5-83.el7.centos.1 将被 安装
- --> 正在处理依赖关系 dhcp-libs(x86-64) = 12:4.2.5-83.el7.centos.1,它被软件包 12:dhcp-4.2.5-83.el7.centos.1.x86_64 需要
- ……
- 已安装:
- dhcp.x86_64 12:4.2.5-83.el7.centos.1 httpd.x86_64 0:2.4.6-99.el7.centos.1 tftp.x86_64 0:5.2-22.el7 xinetd.x86_64 2:2.3.15-14.el7
- 作为依赖被安装:
- bind-export-libs.x86_64 32:9.11.4-26.P2.el7_9.14 httpd-tools.x86_64 0:2.4.6-99.el7.centos.1 mailcap.noarch 0:2.1.41-2.el7
- 更新完毕:
- net-tools.x86_64 0:2.0-0.25.20131004git.el7 pykickstart.noarch 0:1.99.66.22-1.el7 python.x86_64 0:2.7.5-93.el7_9
- 作为依赖被升级:
- dhclient.x86_64 12:4.2.5-83.el7.centos.1 dhcp-common.x86_64 12:4.2.5-83.el7.centos.1 dhcp-libs.x86_64 12:4.2.5-83.el7.centos.1 python-libs.x86_64 0:2.7.5-93.el7_9
- 完毕!
- [root@cobbler ~]#
2.3启动服务
- [root@cobbler ~]# systemctl enable --now httpd
- [root@cobbler ~]# systemctl enable --now cobblerd
- Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
- [root@cobbler ~]#
2.4修改sever的IP地址
编辑Cobbler
配置文件/etc/cobbler/settings
,这里IP地址为10.129.10.224
:
- [root@cobbler ~]# vim /etc/cobbler/settings


并将manage_dhcp: 1
2.5开启tftp
服务
在配置文件中,将disable = yes
行修改为disable = no
- [root@cobbler ~]# cat /etc/xinetd.d/tftp
- # default: off
- # description: The tftp server serves files using the trivial file transfer \
- # protocol. The tftp protocol is often used to boot diskless \
- # workstations, download configuration files to network-aware printers, \
- # and to start the installation process for some operating systems.
- service tftp
- {
- socket_type = dgram
- protocol = udp
- wait = yes
- user = root
- server = /usr/sbin/in.tftpd
- server_args = -s /var/lib/tftpboot
- disable = no
- per_source = 11
- cps = 100 2
- flags = IPv4
- }
- [root@cobbler ~]#

然后重新加载服务:
- [root@cobbler ~]# systemctl restart xinetd
- [root@cobbler ~]#
2.6配置DHCP服务
编辑DHCP
服务配置文件/etc/dhcp/dhcpd.conf
:
- subnet 10.129.10.0 netmask 255.255.255.0 {
- option routers 10.129.10.224;
- option domain-name-servers 10.129.10.254;
- option subnet-mask 255.255.255.0;
- range dynamic-bootp 10.129.10.10 10.129.10.20;
- default-lease-time 21600;
- max-lease-time 43200;
- next-server $next_server;
- class "pxeclients" {
- match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
- if option pxe-system-type = 00:02 {
- filename "ia64/elilo.efi";
- } else if option pxe-system-type = 00:06 {
- filename "grub/grub-x86.efi";
- } else if option pxe-system-type = 00:07 {
- filename "grub/grub-x86_64.efi";
- } else if option pxe-system-type = 00:09 {
- filename "grub/grub-x86_64.efi";
- } else {
- filename "pxelinux.0";
- }
- }
- }
2.7重启服务并同步
- [root@cobbler ~]# systemctl restart cobblerd
- [root@cobbler ~]# cobbler sync
- task started: 2023-10-12_134810_sync
- task started (id=Sync, time=Thu Oct 12 13:48:10 2023)
- running pre-sync triggers
- cleaning trees
- removing: /var/lib/tftpboot/pxelinux.cfg/default
- removing: /var/lib/tftpboot/grub/images
- removing: /var/lib/tftpboot/grub/efidefault
- removing: /var/lib/tftpboot/s390x/profile_list
- copying bootloaders
- 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
- running shell triggers from /var/lib/cobbler/triggers/sync/post/*
- running python triggers from /var/lib/cobbler/triggers/change/*
- running python trigger cobbler.modules.manage_genders
- running python trigger cobbler.modules.scm_track
- running shell triggers from /var/lib/cobbler/triggers/change/*
- *** TASK COMPLETE ***
- [root@cobbler ~]#
2.8检查DHCP
- [root@cobbler ~]# netstat -lnup|grep dhcp
- udp 0 0 0.0.0.0:67 0.0.0.0:* 10334/dhcpd
- [root@cobbler ~]#
2.9导入镜像
在Cobbler
服务器上导入镜像文件:
- [root@cobbler /]# mount -t iso9660 /dev/cdrom /mnt/
- mount: /dev/sr0 写保护,将以只读方式挂载
- [root@cobbler /]#
- [root@cobbler /]# cobbler import --name="centos7-x86_64" --path=/mnt/
- task started: 2023-10-12_140348_import
- task started (id=Media import, time=Thu Oct 12 14:03:48 2023)
- 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/centos7-x86_64:
- creating new distro: centos7-x86_64
- trying symlink: /var/www/cobbler/ks_mirror/centos7-x86_64 -> /var/www/cobbler/links/centos7-x86_64
- creating new profile: centos7-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/centos7-x86_64 for centos7-x86_64
- processing repo at : /var/www/cobbler/ks_mirror/centos7-x86_64
- need to process repo/comps: /var/www/cobbler/ks_mirror/centos7-x86_64
- looking for /var/www/cobbler/ks_mirror/centos7-x86_64/repodata/*comps*.xml
- Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos7-x86_64/repodata
- *** TASK COMPLETE ***
- [root@cobbler /]#
- [root@cobbler /]# cobbler list
- distros:
- centos7-x86_64
- profiles:
- centos7-x86_64
- systems:
- repos:
- images:
- mgmtclasses:
- packages:
- files:
- [root@cobbler /]#
3.自动安装系统
新建虚拟机环境,网络模式设置和cobbler
服务器一致,然后点开机按钮,进行自动安装:

