实验环境
- 操作系统: Centos 7.7
- 安装软件 & 启动服务
[root@localhost ~]# yum install -y dhcp cobbler
[root@localhost ~]# systemctl enable --now cobblerd httpd tftp
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
- 查看服务启动状态
[root@localhost ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6401/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 6572/master
tcp 0 0 127.0.0.1:25151 0.0.0.0:* LISTEN 6868/python2
tcp6 0 0 :::80 :::* LISTEN 6870/httpd
tcp6 0 0 :::22 :::* LISTEN 6401/sshd
tcp6 0 0 ::1:25 :::* LISTEN 6572/master
- Cobbler 检查配置
[root@localhost ~]# cobbler check
The following are potential configuration items that you may want to fix:
1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work. This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : Some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, 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, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
5 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
7 : ksvalidator was not found, install pykickstart
8 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
9 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
Restart cobblerd and then run 'cobbler sync' to apply changes.
- 根据提示修改配置文件
# 修改前的默认配置
[root@localhost ~]# cat /etc/cobbler/settings | egrep -v "^#|^$" |egrep "^server|next_server|manage_dhcp"
manage_dhcp: 0
next_server: 127.0.0.1
server: 127.0.0.1
# 使用sed替换内容
[root@localhost ~]# sed -i 's/next_server: 127.0.0.1/next_server: 10.0.0.10/g' /etc/cobbler/settings
[root@localhost ~]# sed -i 's/server: 127.0.0.1/server: 10.0.0.10/g' /etc/cobbler/settings
[root@localhost ~]# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/g' /etc/cobbler/settings
# 查看替换内容
[root@localhost ~]# cat /etc/cobbler/settings | egrep -v "^#|^$" |egrep "^server|next_server|manage_dhcp"
manage_dhcp: 1
next_server: 10.0.0.10
server: 10.0.0.10
# 下载 loaders 文件
[root@localhost ~]# cobbler get-loaders
task started: 2020-02-11_231404_get_loaders
task started (id=Download Bootloader Content, time=Tue Feb 11 23:14:04 2020)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***
- 修改DHCP配置模板
[root@localhost ~]# vim /etc/cobbler/dhcp.template
# 修改前
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.5;
option domain-name-servers 192.168.1.1;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.1.100 192.168.1.254;
# 修改后
subnet 10.0.0.0 netmask 255.255.255.0 {
option routers 10.0.0.5;
option domain-name-servers 180.78.78.78;
option subnet-mask 255.255.255.0;
range dynamic-bootp 10.0.0.30 10.0.0.250;
- Cobbler 同步配置
[root@localhost ~]# cobbler sync
task started: 2020-02-11_232322_sync
task started (id=Sync, time=Tue Feb 11 23:23:22 2020)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
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 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 ***
- 重启cobblerd & check配置
[root@localhost ~]# systemctl restart cobblerd.service
[root@localhost ~]# cobbler check
The following are potential configuration items that you may want to fix:
1 : enable and start rsyncd.service with systemctl
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
3 : ksvalidator was not found, install pykickstart
4 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
5 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
Restart cobblerd and then run 'cobbler sync' to apply changes.
# 以上非必要项, 如有需要自行修改, 否则往下执行
- 挂载ISO镜像
挂载ISO.png
- 查看 && 挂载到 /mnt
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 300M 0 part /boot
├─sda2 8:2 0 37.7G 0 part /home
├─sda3 8:3 0 20G 0 part /
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 2G 0 part [SWAP]
sr0 11:0 1 942M 0 rom
[root@localhost ~]# mount /dev/sr0 /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# du -sh /mnt
1000M /mnt
[root@localhost ~]# ll /mnt
total 110
-rw-rw-r-- 1 root root 14 Sep 10 03:06 CentOS_BuildTag
drwxr-xr-x 3 root root 2048 Sep 6 19:48 EFI
-rw-rw-r-- 1 root root 227 Aug 30 2017 EULA
-rw-rw-r-- 1 root root 18009 Dec 10 2015 GPL
drwxr-xr-x 3 root root 2048 Sep 10 02:07 images
drwxr-xr-x 2 root root 2048 Sep 10 02:07 isolinux
drwxr-xr-x 2 root root 2048 Sep 6 19:48 LiveOS
drwxrwxr-x 2 root root 73728 Sep 12 02:58 Packages
drwxrwxr-x 2 root root 4096 Sep 12 03:01 repodata
-rw-rw-r-- 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r-- 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r-- 1 root root 2883 Sep 12 03:02 TRANS.TBL
- import 导入
[root@localhost ~]# cobbler import --name=centos7 --path=/mnt --arch=x86_64
task started: 2020-02-11_234319_import
task started (id=Media import, time=Tue Feb 11 23:43:19 2020)
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
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@localhost ~]# du -sh /var/www/cobbler/ks_mirror/centos7-x86_64
1001M /var/www/cobbler/ks_mirror/centos7-x86_64
- 导入第二个iso && 解决光盘识别
[root@localhost ~]# echo '- - -' > /sys/class/scsi_host/host
host0/ host1/ host2/
[root@localhost ~]# echo '- - -' > /sys/class/scsi_host/host0/scan
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 300M 0 part /boot
├─sda2 8:2 0 37.7G 0 part /home
├─sda3 8:3 0 20G 0 part /
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 2G 0 part [SWAP]
sr0 11:0 1 942M 0 rom /mnt
sr1 11:1 1 7G 0 rom
- 查看发行版本
[root@localhost ~]# du -sh /var/www/cobbler/ks_mirror/*
1001M /var/www/cobbler/ks_mirror/centos7-x86_64
8.0K /var/www/cobbler/ks_mirror/config
[root@localhost ~]# cobbler distro list
centos7-x86_64
- 查看应答文件菜单
[root@localhost ~]# cobbler profile list
centos7-x86_64
[root@localhost ~]# cobbler profile report
Name : centos7-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : centos7-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks
Kickstart Metadata : {}
Management Classes : []
Management Parameters : <<inherit>>
Name Servers : []
Name Servers Search Path : []
Owners : ['admin']
Parent Profile :
Internal proxy :
Red Hat Management Key : <<inherit>>
Red Hat Management Server : <<inherit>>
Repos : []
Server Override : <<inherit>>
Template Files : {}
Virt Auto Boot : 1
Virt Bridge : xenbr0
Virt CPUs : 1
Virt Disk Driver Type : raw
Virt File Size(GB) : 5
Virt Path :
Virt RAM (MB) : 512
Virt Type : kvm
- DHCP服务
[root@localhost ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6401/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 6572/master
tcp 0 0 127.0.0.1:25151 0.0.0.0:* LISTEN 17091/python2
tcp6 0 0 :::80 :::* LISTEN 6870/httpd
tcp6 0 0 :::22 :::* LISTEN 6401/sshd
tcp6 0 0 ::1:25 :::* LISTEN 6572/master
udp 0 0 0.0.0.0:67 0.0.0.0:* 17473/dhcpd
[root@localhost ~]# cobbler sync
[root@localhost ~]# systemctl status dhcpd
● dhcpd.service - DHCPv4 Server Daemon
Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2020-02-12 00:07:42 CST; 19s ago
Docs: man:dhcpd(8)
man:dhcpd.conf(5)
Main PID: 17473 (dhcpd)
Status: "Dispatching packets..."
CGroup: /system.slice/dhcpd.service
└─17473 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid
Feb 12 00:07:42 localhost dhcpd[17473]: Copyright 2004-2013 Internet Systems Consortium.
Feb 12 00:07:42 localhost dhcpd[17473]: All rights reserved.
Feb 12 00:07:42 localhost dhcpd[17473]: For info, please visit https://www.isc.org/software/dhcp/
Feb 12 00:07:42 localhost dhcpd[17473]: Not searching LDAP since ldap-server, ldap-port and ldap-b...file
Feb 12 00:07:42 localhost dhcpd[17473]: Wrote 0 class decls to leases file.
Feb 12 00:07:42 localhost dhcpd[17473]: Wrote 0 leases to leases file.
Feb 12 00:07:42 localhost dhcpd[17473]: Listening on LPF/eth0/00:0c:29:43:bf:db/10.0.0.0/24
Feb 12 00:07:42 localhost dhcpd[17473]: Sending on LPF/eth0/00:0c:29:43:bf:db/10.0.0.0/24
Feb 12 00:07:42 localhost dhcpd[17473]: Sending on Socket/fallback/fallback-net
Feb 12 00:07:42 localhost systemd[1]: Started DHCPv4 Server Daemon.
Hint: Some lines were ellipsized, use -l to show in full.
- 自定义应答文件
[root@localhost ~]# ls
anaconda-ks.cfg centos6.cfg centos7.cfg centos8.cfg
[root@localhost ~]# cp centos* /var/lib/cobbler/kickstarts/
[root@localhost kickstarts]# ls
centos6.cfg esxi4-ks.cfg pxerescue.ks sample_esxi4.ks sample_old.seed
centos7.cfg esxi5-ks.cfg sample_autoyast.xml sample_esxi5.ks sample.seed
centos8.cfg install_profiles sample_end.ks sample_esxi6.ks sample.seed.28
default.ks legacy.ks sample_esx4.ks sample.ks
# 修改应答文件
[root@localhost kickstarts]# vim Centos8.cfg
url --url=http://10.0.0.8/centos/8/os/x86_64/ --> url --url=$tree
# 关联应答文件
[root@localhost kickstarts]# cobbler distro list
centos7-x86_64
[root@localhost kickstarts]# cobbler profile list
centos7-x86_64
# 生成新的菜单
[root@localhost kickstarts]# cobbler profile add --name=Centos_v7.7_Minimal --distro=centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg
Centos 8.cfg
cat > /var/lib/cobbler/kickstarts/Centos8.cfg <<EOF
ignoredisk --only-use=sda
zerombr
text
reboot
clearpart --all --initlabel
selinux --disabled
firewall --disabled
url --url=$tree
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
network --bootproto=dhcp --device=eth0 --ipv6=auto --activate
network --hostname=localhost
rootpw --iscrypted $6$j9YhzDUnQVnxaAk8$qv7rkMcPAEbV5yvwsP666DXWYadd3jYjkA9fpxAo9qYotjGGBUclCGoP1TRvgHBpqgc5n0RypMsPTQnVDcpO01
firstboot --enable
skipx
services --disabled="chronyd"
timezone Asia/Shanghai --isUtc --nontp
part / --fstype="ext4" --ondisk=sda --size=10240
part /data --fstype="ext4" --ondisk=sda --size=5120
part swap --fstype="swap" --ondisk=sda --size=2048
part /boot --fstype="ext4" --ondisk=sda --size=300
%packages
@^minimal-environment
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
%post
%end
EOF
Centos 7.cfg
cat > /var/lib/cobbler/kickstarts/Centos7.cfg <<EOF
auth --enableshadow --passalgo=sha512
url --url=$tree
text
reboot
firstboot --disable
ignoredisk --only-use=sda
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
network --bootproto=dhcp --device=eth0 --onboot=on --ipv6=auto --activate
network --hostname=localhost
rootpw --iscrypted $6$3wD9l3CM7QgAOz68$ypkW2rtZSDxQJItbiGN7.BzEqG/e6MhPN7WoH28Tvli3Q8.EvD2YtlMS9WKaYI/AdYbTuVGVUEkYGvODDayRy1
services --disabled="chronyd"
timezone Asia/Shanghai --isUtc --nontp
bootloader --location=mbr --boot-drive=sda
zerombr
clearpart --none --initlabel
part / --fstype="ext4" --ondisk=sda --size=20480
part /boot --fstype="ext4" --ondisk=sda --size=300
part /data --fstype="ext4" --ondisk=sda --size=38610
part swap --fstype="swap" --ondisk=sda --size=2048
%packages
@^minimal
@core
%end
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
EOF
Centos 6.cfg
cat > /var/lib/cobbler/kickstarts/Centos6.cfg <<EOF
install
text
reboot
url --url=$tree
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp --noipv6
rootpw --iscrypted $6$j9YhzDUnQVnxaAk8$qv7rkMcPAEbV5yvwsP666DXWYadd3jYjkA9fpxAo9qYotjGGBUclCGoP1TRvgHBpqgc5n0RypMsPTQnVDcpO01
firewall --disabled
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
zerombr
clearpart --all --initlabel
part /boot --fstype=ext4 --size=1024
part / --fstype=ext4 --size=50000
part /data --fstype=ext4 --size=30000
part swap --size=2048
%packages
@core
@server-policy
@workstation-policy
autofs
vim-enhanced
%end
%post
%end
EOF