20.第15章 運維自動化之系統部署


一.kickstart文件制作過程

[root@centos7 isolinux]# system-config-kickstart
-bash: system-config-kickstart: command not found
[root@centos7 isolinux]# yum -y install system-config-kickstart

[root@centos7 isolinux]# system-config-kickstart
Could not open display because no X server is running.
Try running 'system-config-kickstart --help' for a list of options.

#打開Xmanager – Passive文件
[root@centos7 isolinux]# export DISPLAY=10.0.0.1:0.0
[root@centos7 isolinux]# system-config-kickstart
/usr/share/system-config-kickstart/kickstartGui.py:104: GtkWarning: GtkSpinButton: setting an adjustment with non-zero page size is deprecated
  xml = gtk.glade.XML ("/usr/share/system-config-kickstart/system-config-kickstart.glade", domain="system-config-kickstart")
Loaded plugins: fastestmirror

[root@centos7 ~]# yum -y install httpd;systemctl enable --now httpd
[root@centos7 ~]# mkdir -pv /var/www/html/centos/{6,7,8}
mkdir: created directory ‘/var/www/html/centos’
mkdir: created directory ‘/var/www/html/centos/6’
mkdir: created directory ‘/var/www/html/centos/7’
mkdir: created directory ‘/var/www/html/centos/8’

[root@centos7 ~]# mount /dev/sr0 /var/www/html/centos/7
mount: /dev/sr0 is write-protected, mounting read-only

http://10.0.0.7/centos/7/


net.ifnames=0,系統安裝后網卡是eth0、eth1網卡名


網絡設置


驗證方法


SElinux和防火牆


顯示


軟件包安裝,這里不能選

[root@centos7 isolinux]# cd /etc/yum.repos.d/
[root@centos7 yum.repos.d]# vim base.repo 
#把[base]改成[development]  
:wq

[root@centos7 yum.repos.d]# system-config-kickstart


現在就可以選擇軟件包了


安裝前腳本

root@centos7 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Eg2jx10UZw1uyQcTcNaKaitaryyynwLRh1l32KZyxY4 root@centos7.9
The key's randomart image is:
+---[RSA 2048]----+
|      o+ .=oX=   |
|    .oo=*. B +o  |
| . +..+Bo  .=..  |
|. + o.E.. ....   |
| . . o. S.       |
|.      .o        |
| .    .. .       |
|  o .+...        |
|  .=+ooo.        |
+----[SHA256]-----+

[root@centos7 ~]# cd .ssh
[root@centos7 .ssh]# ls
id_rsa  id_rsa.pub
[root@centos7 .ssh]# ssh-copy-id 127.0.0.1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:zb/8mo/ptS0h8eHVY1FDRuvh6aQj1opzpsD7khnYjSo.
ECDSA key fingerprint is MD5:f1:ee:83:81:26:e8:ed:a5:39:d5:fd:41:bc:a8:23:38.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@127.0.0.1's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '127.0.0.1'"
and check to make sure that only the key(s) you wanted were added.
[root@centos7 .ssh]# ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts

[root@centos7 .ssh]# cat authorized_keys 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDnsdSfIrGqy9pyJmiuRPRZYF834zr2TcSneCfcysCqiiNet19z4CS6ynbTY5RX7qD7dBOJhNUjTT7xB8xel6CTUfTL6Dw+gqpbVBNggU7sxyvePTsRVSU95uHcClO/Nq0EXV3T+0KAEZ0KVYWJHfzLihn5YML4xXwcLGAAFHt/lHUBX7IjUmwHMHk+fxD0g6+HkWhHB84HOPPSs3ZANiMdvU6SZHZM1kMt+53BXrdKFZiP/PZUIvDcRV2Ilk5uuYzJMyeuAXcFuUJZKQupMdwi6c4jyryy8NMavMJFMm0uAF3bhNzYvdXwZ5ENGEpTU8ZqtGMl6Z02cRi5RIWfUlFn root@centos7.9
[root@centos7 .ssh]# pwd
/root/.ssh
[root@centos7 .ssh]# cd
[root@centos7 ~]# ll -hd .ssh
drwx------ 2 root root 80 Dec 30 14:36 .ssh


安裝后腳本

[root@centos7 ~]# cat ks7.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --plaintext 123456
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled


# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://10.0.0.7/centos/7"
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --fstype="ext4" --size=102400
part /boot --fstype="ext4" --size=1024
part /data --fstype="ext4" --size=51200
part swap --fstype="swap" --size=2048

%post
mkdir -m 700 /root/.ssh
cat > /root/.ssh/authorized_keys <<EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDnsdSfIrGqy9pyJmiuRPRZYF834zr2TcSneCfcysCqiiNet19z4CS6ynbTY5RX7qD7dBOJhNUjTT7xB8xel6CTUfTL6Dw+gqpbVBNggU7sxyvePTsRVSU95uHcClO/Nq0EXV3T+0KAEZ0KVYWJHfzLihn5YML4xXwcLGAAFHt/lHUBX7IjUmwHMHk+fxD0g6+HkWhHB84HOPPSs3ZANiMdvU6SZHZM1kMt+53BXrdKFZiP/PZUIvDcRV2Ilk5uuYzJMyeuAXcFuUJZKQupMdwi6c4jyryy8NMavMJFMm0uAF3bhNzYvdXwZ5ENGEpTU8ZqtGMl6Z02cRi5RIWfUlFn root@centos7.9
EOF
chmod 600 /root/.ssh/authorized_keys
%end

%packages
vim
wget
curl
%end

[root@centos7 ~]# ksvalidator ks7.cfg
#檢查語法格式

二.在CentOS 8上實現PXE自動化安裝CentOS 6,7,8

1.安裝前准備

關閉防火牆和SELinux,服務器設置靜態IP地址

網絡要求:關閉vmware軟件中的DHCP服務,基於NAT模式

注意:使用1G以下內存的主機安裝centos7,8會提示空間不足,建議2G以上內存

2.安裝相關軟件包並啟動

[root@centos8 ~]# dnf -y install dhcp-server tftp-server httpd syslinux-nonlinux
[root@centos8 ~]# systemctl enable --now httpd tftp dhcpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket → /usr/lib/systemd/system/tftp.socket.
Created symlink /etc/systemd/system/multi-user.target.wants/dhcpd.service → /usr/lib/systemd/system/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.
#dhcp服務不能啟動,因為沒有設置dhcp配置文件

3.配置DHCP服務

[root@centos8 ~]# cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf 
cp: overwrite '/etc/dhcp/dhcpd.conf'? y
[root@centos8 ~]# vim /etc/dhcp/dhcpd.conf
option domain-name "example.org";         #設置域名,這里可以不設置                                             
option domain-name-servers 180.76.76.76, 223.6.6.6;		#設置DNS
default-lease-time 86400;		#設置DHCP租期
max-lease-time 100000;			#設置最大DHCP租期
subnet 10.0.0.0 netmask 255.255.255.0 {    #DHCP獲取網絡段
  range 10.0.0.100 10.0.0.200;	#DHCP獲取地址范圍
  option routers 10.0.0.2;		#網關
  next-server 10.0.0.8;			#tftp 服務地址
  filename "pxelinux.0";		#pxe獲取文件名
}
:wq
[root@centos8 ~]# systemctl enable --now dhcpd

4.准備yum源和相關目錄

[root@centos8 ~]# mkdir -pv /var/www/html/centos/{6,7,8}/os/x86_64
mkdir: created directory '/var/www/html/centos'
mkdir: created directory '/var/www/html/centos/6'
mkdir: created directory '/var/www/html/centos/6/os'
mkdir: created directory '/var/www/html/centos/6/os/x86_64'
mkdir: created directory '/var/www/html/centos/7'
mkdir: created directory '/var/www/html/centos/7/os'
mkdir: created directory '/var/www/html/centos/7/os/x86_64'
mkdir: created directory '/var/www/html/centos/8'
mkdir: created directory '/var/www/html/centos/8/os'
mkdir: created directory '/var/www/html/centos/8/os/x86_64'
[root@centos8 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sr0     11:0    1  3.7G  0 rom  
sr1     11:1    1  9.5G  0 rom  
sr2     11:2    1  8.6G  0 rom  
[root@centos8 ~]# mount /dev/sr0 /var/www/html/centos/6/os/x86_64/
mount: /var/www/html/centos/6/os/x86_64: WARNING: device write-protected, mounted read-only.
[root@centos8 ~]# mount /dev/sr1 /var/www/html/centos/7/os/x86_64/
mount: /var/www/html/centos/7/os/x86_64: WARNING: device write-protected, mounted read-only.
[root@centos8 ~]# mount /dev/sr2 /var/www/html/centos/8/os/x86_64/
mount: /var/www/html/centos/8/os/x86_64: WARNING: device write-protected, mounted read-only.

http://10.0.0.8/centos/6/os/x86_64/

5.准備kickstart文件

[root@centos8 ~]# mkdir /var/www/html/ks
[root@centos8 ~]# rz
#把事先准備好的kickstart文件傳到系統
[root@centos8 ~]# ls
anaconda-ks.cfg  centos6.cfg  centos7.cfg  centos8.cfg
[root@centos8 ~]# mv centos* /var/www/html/ks/
[root@centos8 ~]# ls /var/www/html/ks/
centos6.cfg  centos7.cfg  centos8.cfg

[root@centos8 ~]# cat /var/www/html/ks/centos6.cfg 
install
text
reboot
url --url=http://10.0.0.8/centos/6/os/x86_64/
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp  --noipv6
rootpw --plaintext 123456
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
useradd neteagle 
echo 123456 | passwd --stdin neteagle &> /dev/null
mkdir  /etc/yum.repos.d/backup
mv /etc/yum.repos.d/* /etc/yum.repos.d/backup
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=base
baseurl=file:///misc/cd
gpgcheck=0
EOF
%end



[root@centos8 ~]# cat /var/www/html/ks/centos7.cfg 
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --plaintext 123456
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled


# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=static --device=eth0 --ip=10.0.0.123 --netmask=255.255.255.0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://10.0.0.8/centos/7/os/x86_64"
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr
# Partition clearing information
clearpart --all
# Disk partitioning information
part / --fstype="xfs" --size=100000

%post
useradd neteagle
echo 123456 |passwd --stdin neteagle
mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
EOF
%end

%packages
vim
wget
lrzsz
tree
curl
%end


[root@centos8 ~]# cat /var/www/html/ks/centos8.cfg 
ignoredisk --only-use=sda
zerombr
text
reboot
clearpart --all --initlabel
selinux --disabled
firewall --disabled
url --url=http://10.0.0.8/centos/8/os/x86_64/
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
network  --bootproto=dhcp --device=ens160 --ipv6=auto --activate
network  --hostname=centos8.magedu.com
rootpw --plaintext 123456
firstboot --enable
skipx
services --disabled="chronyd"
timezone Asia/Shanghai --isUtc --nontp
user --name=wang --password=6oUfb/02CWfLb5l8f$sgEZeR7c7DpqfpmFDH6huSmDbW1XQNR4qKl2EPns.gOXqlnAIgv9pTogtFVaDtEpMOC.SWXKYqxfVtd9MCwxb1 --iscrypted --gecos="wang"
part / --fstype="xfs" --ondisk=sda --size=102400
part /data --fstype="xfs" --ondisk=sda --size=51200
part swap --fstype="swap" --ondisk=sda --size=2048
part /boot --fstype="ext4" --ondisk=sda --size=1024
%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
useradd neteagle
echo 123456 | passwd --stdin neteagle &> /dev/null
%end

6.准備PXE啟動相關文件

[root@centos8 ~]# mkdir /var/lib/tftpboot/centos{6,7,8}

#准備centos 6,7,8各自的內核相關文件
[root@centos8 ~]# cp /var/www/html/centos/6/os/x86_64/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos6/
[root@centos8 ~]# cp /var/www/html/centos/7/os/x86_64/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos7/
[root@centos8 ~]# cp /var/www/html/centos/8/os/x86_64/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos8/
[root@centos8 ~]# cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/

#以下三個文件是CentOS 8安裝所必須文件,CentOS 6,7則不需要
[root@centos8 ~]# cp /var/www/html/centos/8/os/x86_64/isolinux/{ldlinux.c32,libcom32.c32,libutil.c32} /var/lib/tftpboot/

#生成安裝菜單文件
[root@centos8 ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@centos8 ~]# cp /var/www/html/centos/8/os/x86_64/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

#最終目錄結構如下
[root@centos8 ~]# tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── centos6
│   ├── initrd.img
│   └── vmlinuz
├── centos7
│   ├── initrd.img
│   └── vmlinuz
├── centos8
│   ├── initrd.img
│   └── vmlinuz
├── ldlinux.c32
├── libcom32.c32
├── libutil.c32
├── menu.c32
├── pxelinux.0
└── pxelinux.cfg
    └── default

4 directories, 12 files

7.准備啟動菜單文件

[root@centos8 ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 600

menu title CentOS Linux

label linux8
  menu label Auto Install CentOS Linux ^8
  kernel centos8/vmlinuz
  append initrd=centos8/initrd.img ks=http://10.0.0.8/ks/centos8.cfg

label linux7
  menu label Auto Install CentOS Linux ^7
  kernel centos7/vmlinuz
  append initrd=centos7/initrd.img ks=http://10.0.0.8/ks/centos7.cfg

label linux6
  menu label Auto Install CentOS Linux ^6
  kernel centos6/vmlinuz
  append initrd=centos6/initrd.img ks=http://10.0.0.8/ks/centos6.cfg

label manual
  menu label ^Manual Install CentOS Linux 8.3
  kernel centos8/vmlinuz
  append initrd=centos8/initrd.img inst.repo=http://10.0.0.8/centos/8/os/x86_64/

label rescue
  menu label ^Rescue a CentOS Linux system 8
  kernel centos8/vmlinuz
  append initrd=centos8/initrd.img inst.repo=http://10.0.0.8/centos/8/os/x86_64/ rescue

label local
  menu label Boot from ^local drive
  localboot 0xffff
menu end
:wq!  #需要強制保存

8.測試客戶機基於PXE實現自動化安裝

新准備一台虛擬機,設置網卡引導,可看到啟動菜單,並實現自動安裝

自動安裝CentOS8


正在安裝


安裝完成,並啟動


正常登錄

自動安裝CentOS7

自動安裝CentOS6

三.CentOS 7基於Cobbler實現CentOS 6,7,8系統的自動化安裝

1.環境准備

兩台主機:

一台主機:CentOS 7充當cobbler,http,dhcp,tftp服務器,並關閉防火牆和SELinux

一台主機:充當測試機,用於實現自動化安裝Linux系統

網絡要求:關閉vmware軟件中的NAT模式中的DHCP服務,兩個主機網卡基於NAT模式

2.安裝相關包並啟動服務

[root@centos7 ~]# yum -y install cobbler dhcp
[root@centos7 ~]# systemctl enable --now cobblerd httpd tftp dhcpd
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.
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/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.
#DHCP沒有配置文件,稍后再配置

3.修改cobbler相關的配置

[root@centos7 ~]# 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密碼為cobber
[root@centos7 ~]# openssl passwd -1 '123456'
$1$IDH4FUHg$aiO7y.lEscZmd7lkDUwPW1

#根據以上提示,只需要做1,2,8這三項即可,修改下面四行
[root@centos7 ~]# vim /etc/cobbler/settings 
server: 10.0.0.7	#IP地址修改為你當前主機的IP地址
next_server: 10.0.0.7   #IP地址修改為你當前主機的IP地址
manage_dhcp: 1  	#設置1,表示通過cobbler生成dhcpd.conf配置文件
default_password_crypted: "$1$IDH4FUHg$aiO7y.lEscZmd7lkDUwPW1"    #密碼設置成你剛生成的新密碼
:wq
[root@centos7 ~]# systemctl restart cobblerd

4.實現dhcp服務

[root@centos7 ~]# vim /etc/cobbler/dhcp.template
subnet 10.0.0.0 netmask 255.255.255.0 {
     option routers             10.0.0.2;
     option domain-name-servers 180.76.76.76,223.6.6.6;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        10.0.0.100 10.0.0.254;
:wq

[root@centos7 ~]# cobbler sync
task started: 2020-12-30_223028_sync
task started (id=Sync, time=Wed Dec 30 22:30:28 2020)
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

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@centos7 ~]# systemctl status dhcpd
● dhcpd.service - DHCPv4 Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2020-12-30 22:30:29 CST; 25s ago
     Docs: man:dhcpd(8)
           man:dhcpd.conf(5)
 Main PID: 1275 (dhcpd)
   Status: "Dispatching packets..."
   CGroup: /system.slice/dhcpd.service
           └─1275 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid

Dec 30 22:30:29 centos7.9 dhcpd[1275]: Copyright 2004-2013 Internet Systems Consortium.
Dec 30 22:30:29 centos7.9 dhcpd[1275]: All rights reserved.
Dec 30 22:30:29 centos7.9 dhcpd[1275]: For info, please visit https://www.isc.org/software/dhcp/
Dec 30 22:30:29 centos7.9 dhcpd[1275]: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not spec...g file
Dec 30 22:30:29 centos7.9 dhcpd[1275]: Wrote 0 class decls to leases file.
Dec 30 22:30:29 centos7.9 dhcpd[1275]: Wrote 0 leases to leases file.
Dec 30 22:30:29 centos7.9 dhcpd[1275]: Listening on LPF/eth0/00:0c:29:6a:7e:b8/10.0.0.0/24
Dec 30 22:30:29 centos7.9 dhcpd[1275]: Sending on   LPF/eth0/00:0c:29:6a:7e:b8/10.0.0.0/24
Dec 30 22:30:29 centos7.9 dhcpd[1275]: Sending on   Socket/fallback/fallback-net
Dec 30 22:30:29 centos7.9 systemd[1]: Started DHCPv4 Server Daemon.
Hint: Some lines were ellipsized, use -l to show in full.

5.下載啟動的相關文件

[root@centos7 ~]# cobbler get-loaders
task started: 2020-12-30_223833_get_loaders
task started (id=Download Bootloader Content, time=Wed Dec 30 22:38:33 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 ***

遇到cobbler get-loaders不能下載啟動文件,估計是網絡問題造成的
用cobbler離線安裝的getLoader離線包,問題解決,下載地址:https://pan.baidu.com/s/1Mi5lyX-5DpTVtSRaXsGGgQ 提取碼:zl3c

[root@centos7 ~]# ls /var/lib/cobbler/loaders/
COPYING.elilo     COPYING.yaboot  grub-x86_64.efi  menu.c32    README
COPYING.syslinux  elilo-ia64.efi  grub-x86.efi     pxelinux.0  yaboot

[root@centos7 ~]# tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── boot
├── etc
├── grub
├── images
├── images2
├── memdisk
├── menu.c32
├── ppc
├── pxelinux.cfg
│   └── default
└── s390x

8 directories, 0 files

[root@centos7 ~]# cobbler sync
task started: 2020-12-30_224401_sync
task started (id=Sync, time=Wed Dec 30 22:44:01 2020)
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
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
copying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
copying: /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
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@centos7 ~]# tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── boot
│   └── grub
│       └── menu.lst
├── etc
├── grub
│   ├── efidefault
│   ├── grub-x86_64.efi
│   ├── grub-x86.efi
│   └── images -> ../images
├── images
├── images2
├── memdisk
├── menu.c32
├── ppc
├── pxelinux.0
├── pxelinux.cfg
│   └── default
├── s390x
│   └── profile_list
└── yaboot

10 directories, 10 files

6.修改菜單的標題信息

[root@centos7 ~]# vim /etc/cobbler/pxe/pxedefault.template 
MENU TITLE Cobbler | http://www.neteagles.cn/   
:wq
[root@centos7 ~]# cobbler sync
task started: 2020-12-30_224620_sync
task started (id=Sync, time=Wed Dec 30 22:46:20 2020)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
copying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
copying: /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
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@centos7 ~]# cat /var/lib/tftpboot/pxelinux.cfg/default 
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://www.neteagles.cn/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local

LABEL local
        MENU LABEL (local)
        MENU DEFAULT
        LOCALBOOT -1



MENU end

7.導入CentOS系統的安裝文件,生成相應的YUM源

[root@centos7 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sr0     11:0    1  9.5G  0 rom  
sr1     11:1    1  8.6G  0 rom  
sr2     11:2    1  3.7G  0 rom  

[root@centos7 ~]# mkdir /mnt/centos{6,7,8}

[root@centos7 ~]# mount /dev/sr0 /mnt/centos7
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos7 ~]# mount /dev/sr1 /mnt/centos8
mount: /dev/sr1 is write-protected, mounting read-only
[root@centos7 ~]# mount /dev/sr2 /mnt/centos6
mount: /dev/sr2 is write-protected, mounting read-only

[root@centos7 ~]# cobbler import --name=centos-8.3-x86_64 --path=/mnt/centos8 --arch=x86_64
task started: 2020-12-31_135841_import
task started (id=Media import, time=Thu Dec 31 13:58:41 2020)
Found a candidate signature: breed=redhat, version=rhel8
No signature matched in /var/www/cobbler/ks_mirror/centos-8.3-x86_64
!!! TASK FAILED !!!	#出現No signature matched報錯

#修改下面的配置文件
[root@centos7 ~]# vim /var/lib/cobbler/distro_signatures.json
"rhel8": {
        "signatures": [
          "BaseOS"
        ],
        "version_file": "(redhat|sl|slf|centos-linux|oraclelinux|vzlinux)-release-(?!notes)([\\w]*-)*8(Server)*[\\.-]+(.*)\\.rpm",   #把這行centos改成centos-linux          
:wq

[root@centos7 ~]# systemctl restart cobblerd

[root@centos7 ~]# cobbler import --name=centos-8.3-x86_64 --path=/mnt/centos8 --arch=x86_64
task started: 2020-12-31_140121_import
task started (id=Media import, time=Thu Dec 31 14:01:21 2020)
Found a candidate signature: breed=redhat, version=rhel8
Found a matching signature: breed=redhat, version=rhel8
Adding distros from path /var/www/cobbler/ks_mirror/centos-8.3-x86_64:
creating new distro: centos-8.3-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos-8.3-x86_64 -> /var/www/cobbler/links/centos-8.3-x86_64
creating new profile: centos-8.3-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-8.3-x86_64 for centos-8.3-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos-8.3-x86_64/AppStream
need to process repo/comps: /var/www/cobbler/ks_mirror/centos-8.3-x86_64/AppStream
looking for /var/www/cobbler/ks_mirror/centos-8.3-x86_64/AppStream/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos-8.3-x86_64/AppStream/repodata
processing repo at : /var/www/cobbler/ks_mirror/centos-8.3-x86_64/BaseOS
need to process repo/comps: /var/www/cobbler/ks_mirror/centos-8.3-x86_64/BaseOS
looking for /var/www/cobbler/ks_mirror/centos-8.3-x86_64/BaseOS/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos-8.3-x86_64/BaseOS/repodata
*** TASK COMPLETE ***
#現在導入鏡像成功


[root@centos7 ~]# cobbler import --name=centos-7.9-x86_64 --path=/mnt/centos7 --arch=x86_64
task started: 2020-12-31_140211_import
task started (id=Media import, time=Thu Dec 31 14:02:11 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/centos-7.9-x86_64:
creating new distro: centos-7.9-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos-7.9-x86_64 -> /var/www/cobbler/links/centos-7.9-x86_64
creating new profile: centos-7.9-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.9-x86_64 for centos-7.9-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos-7.9-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/centos-7.9-x86_64
looking for /var/www/cobbler/ks_mirror/centos-7.9-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos-7.9-x86_64/repodata
*** TASK COMPLETE ***

[root@centos7 ~]# cobbler import --name=centos-6.10-x86_64 --path=/mnt/centos6 --arch=x86_64
task started: 2020-12-31_140501_import
task started (id=Media import, time=Thu Dec 31 14:05:01 2020)
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-6.10-x86_64:
creating new distro: centos-6.10-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos-6.10-x86_64 -> /var/www/cobbler/links/centos-6.10-x86_64
creating new profile: centos-6.10-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-6.10-x86_64 for centos-6.10-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos-6.10-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/centos-6.10-x86_64
looking for /var/www/cobbler/ks_mirror/centos-6.10-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos-6.10-x86_64/repodata
*** TASK COMPLETE ***

[root@centos7 ~]# du -sh /var/www/cobbler/ks_mirror/*
3.8G	/var/www/cobbler/ks_mirror/centos-6.10-x86_64
9.6G	/var/www/cobbler/ks_mirror/centos-7.9-x86_64
8.8G	/var/www/cobbler/ks_mirror/centos-8.3-x86_64
16K	/var/www/cobbler/ks_mirror/config

[root@centos7 ~]# cobbler distro list
   centos-6.10-x86_64
   centos-7.9-x86_64
   centos-8.3-x86_64

[root@centos7 ~]# cobbler profile list
   centos-6.10-x86_64
   centos-7.9-x86_64
   centos-8.3-x86_64
   
#默認生成的是最小化安裝

#cobbler在導入鏡像時報以下錯誤:
task started: 2018-06-06_125116_import
task started (id=Media import, time=Wed Jun  6 12:51:16 2018)
Exception occured: <class 'cobbler.cexceptions.CX'>
Exception value: 'Command failed'
Exception Info:
  File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 82, in run
    rc = self._run(self)
   File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 226, in runner
    self.logger
   File "/usr/lib/python2.7/site-packages/cobbler/api.py", line 876, in import_tree
    utils.run_this(rsync_cmd, (spacer, mirror_url, path), self.logger)
   File "/usr/lib/python2.7/site-packages/cobbler/utils.py", line 899, in run_this
    die(logger,"Command failed")
   File "/usr/lib/python2.7/site-packages/cobbler/utils.py", line 114, in die
    raise CX(msg)

!!! TASK FAILED !!!

#查看日志文件,發現報以下錯誤:
Fri Jun  1 11:28:57 2018 - DEBUG | received on stderr: rsync: read errors mapping "/mnt/EFI/TRANS.TBL": Input/output error (5)
rsync: read errors mapping "/mnt/EFI/BOOT/BOOTX64.EFI": Input/output error (5)
rsync: read errors mapping "/mnt/EFI/BOOT/MokManager.efi": Input/output error (5)

#問題原因
#防火牆、selinux等確認是否關閉(我這里是已經關閉了的)
#確認鏡像文件是否損壞,我這里就是鏡像文件出了問題,換了一個新的鏡像就導入OK了。

8.准備kickstart文件,並關聯至指定的YUM源

[root@centos7 ~]# rz
#把kickstart文件傳到Linux里
[root@centos7 ~]# ls
anaconda-ks.cfg  centos6.cfg  centos7.cfg  centos8.cfg
[root@centos7 ~]# mv centos* /var/lib/cobbler/kickstarts/
[root@centos7 ~]# ls
anaconda-ks.cfg
[root@centos7 ~]# ll /var/lib/cobbler/kickstarts/
total 76
-rw-r--r-- 1 root root  866 Dec 30 20:55 centos6.cfg
-rw-r--r-- 1 root root 1384 Dec 30 20:55 centos7.cfg
-rw-r--r-- 1 root root 1229 Dec 30 20:56 centos8.cfg
-rw-r--r-- 1 root root  115 Aug 30  2019 default.ks
-rw-r--r-- 1 root root   22 Aug 30  2019 esxi4-ks.cfg
-rw-r--r-- 1 root root   22 Aug 30  2019 esxi5-ks.cfg
drwxr-xr-x 2 root root   56 Dec 31 13:44 install_profiles
-rw-r--r-- 1 root root 1424 Aug 30  2019 legacy.ks
-rw-r--r-- 1 root root  292 Aug 30  2019 pxerescue.ks
-rw-r--r-- 1 root root 2825 Aug 30  2019 sample_autoyast.xml
-rw-r--r-- 1 root root 1856 Aug 30  2019 sample_end.ks
-rw-r--r-- 1 root root    0 Aug 30  2019 sample_esx4.ks
-rw-r--r-- 1 root root  324 Aug 30  2019 sample_esxi4.ks
-rw-r--r-- 1 root root  386 Aug 30  2019 sample_esxi5.ks
-rw-r--r-- 1 root root  386 Aug 30  2019 sample_esxi6.ks
-rw-r--r-- 1 root root 1913 Aug 30  2019 sample.ks
-rw-r--r-- 1 root root 3419 Aug 30  2019 sample_old.seed
-rw-r--r-- 1 root root 6694 Aug 30  2019 sample.seed
-rw-r--r-- 1 root root 6706 Jun 18  2019 sample.seed.28

[root@centos7 ~]# vim /var/lib/cobbler/kickstarts/centos7.cfg 
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --plaintext 123456
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled


# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=static --device=eth0 --ip=10.0.0.123 --netmask=255.255.255.0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url=$tree			#注意此行必須指定
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr
# Partition clearing information
clearpart --all
# Disk partitioning information
part / --fstype="xfs" --size=100000

%post
useradd neteagle
echo 123456 |passwd --stdin neteagle
mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
EOF
%end

%packages
vim
wget
lrzsz
tree
curl
%end
:wq


[root@centos7 ~]# vim /var/lib/cobbler/kickstarts/centos8.cfg 
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=ens160 --ipv6=auto --activate
network  --hostname=centos8.magedu.com
rootpw --plaintext 123456
firstboot --enable
skipx
services --disabled="chronyd"
timezone Asia/Shanghai --isUtc --nontp
user --name=wang --password=6oUfb/02CWfLb5l8f$sgEZeR7c7DpqfpmFDH6huSmDbW1XQNR4qKl2EPns.gOXqlnAIgv9pTogtFVaDtEpMOC.SWXKYqxfVtd9MCwxb1 --iscrypted --gecos="wang"
part / --fstype="xfs" --ondisk=sda --size=102400
part /data --fstype="xfs" --ondisk=sda --size=51200
part swap --fstype="swap" --ondisk=sda --size=2048
part /boot --fstype="ext4" --ondisk=sda --size=1024
%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
useradd neteagle
echo 123456 | passwd --stdin neteagle &> /dev/null
%end
:wq

[root@centos7 ~]# cat /var/lib/cobbler/kickstarts/centos6.cfg 
install
text
reboot
url --url=$tree		#注意此行必須指定
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp  --noipv6
rootpw --plaintext 123456
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
useradd neteagle 
echo 123456 | passwd --stdin neteagle &> /dev/null
mkdir  /etc/yum.repos.d/backup
mv /etc/yum.repos.d/* /etc/yum.repos.d/backup
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=base
baseurl=file:///misc/cd
gpgcheck=0
EOF
%end
:wq

#將kickstart文件,關聯指定的YUM源和生成菜單列表
[root@centos7 ~]#  cobbler profile add --name=CentOS-7.9_mini --distro=CentOS-7.9-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg
[root@centos7 ~]# cobbler profile add --name=CentOS-8.3_mini --distro=CentOS-8.3-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos8.cfg
[root@centos7 ~]# cobbler profile add --name=CentOS-6.10_mini --distro=CentOS-6.10-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos6.cfg

#刪除默認生成的菜單
[root@centos7 ~]# cobbler profile remove --name=centos-7.9-x86_64
[root@centos7 ~]# cobbler profile remove --name=centos-8.3-x86_64
[root@centos7 ~]# cobbler profile remove --name=centos-6.10-x86_64

[root@centos7 ~]# cobbler profile list
   CentOS-6.10_mini
   CentOS-7.9_mini
   CentOS-8.3_mini

9.測試客戶端基於Cobbler實現自動安裝

CentOS 7 自動安裝

Centos 8自動安裝

Centos 6自動安裝

10.實現cobbler的web管理

[root@centos7 ~]# yum -y install cobbler-web
Complete!
[root@centos7 ~]# systemctl restart httpd

https://10.0.0.7/cobbler_web


默認用戶名和密碼:cobbler

11.創建cobbler的自定義的web用戶

[root@centos7 ~]# cat /etc/cobbler/users.digest 
cobbler:Cobbler:a2d6bae81669d707b72c0bd9806e01f3

[root@centos7 ~]# htdigest -c /etc/cobbler/users.digest Cobbler admin
Adding password for admin in realm Cobbler.
New password: 
Re-type new password: 

[root@centos7 ~]# cat /etc/cobbler/users.digest 
admin:Cobbler:38a2b8b1b63ae825e30c892e13a200f5
3


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM