實(shí)驗(yàn)一:使用 kickstart 半自動化安裝CentOS7系統(tǒng)
1.安裝system-config-kickstart工具
[root@centos7 ~]#yum -y install system-config-kickstart
2.利用system-config-kickstart生成ks文件
[root@centos7 ~]#export DISPLAY=10.0.0.1:0.0
[root@centos7 ~]#system-config-kickstart
3.生成配置文件內(nèi)容
[root@centos7 ~]#vim /root/anaconda-ks.cfg
#platf orm=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --plaintext centos
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
firstboot --enable
# SELinux configuration
selinux --disabled
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=eth0
network --hostname=centos7.pex.org
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai --nontp
# 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 --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
autopart --type=lvm
%post
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=https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
https://mirrors.huaweicloud.com/centos/$releasever/os/$basearch/
gpgcheck=0
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/\$releasever/\$basearch/
https://mirrors.huaweicloud.com/epel/$releasever/$basearch/
gpgcheck=0
[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/
https://mirrors.huaweicloud.com/centos/\$releasever/extras/\$basearch/
gpgcheck=0
enabled=1
EOF
mkdir /root/.ssh -m 700
cat > /root/.ssh/authorized_keys <<EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDkfPVKy1JLTNiH72bqxxiYsb1WUX1jKsD1AwdjbWJPTy318cKJfsYFj7OOrhfSJAX3kyFXg9r+iQjzUYMgTsLKpmIf9xFEQ/+oQj68h1q1uNmMp4gqXxC3ONPUK3+ywWYCGGR0B+i3q8/Fc24A+sc0ccbONL4fiUmQHd82vHfk5yiDlTiA04aHq4GU71NQZ1MhL0n8YvNpsarj2QdlvI3TUrtCBOquSsqoErPKCOkMb8WkS63HZmg5fb98WRoJk9tRINtQRLO6EEqSMFwW77CgcfLrZJsEPT06pIVtJ0FnMfYehdLPjSGRURQ1cb2vhILQJnTSpY6PKFOQV9pfgCwN root@centos8.xbd.com
EOF
chmod 600 /root/.ssh/authorized_keys
useradd ding
echo 123456 | passwd --stdin ding
%end
4.在centos8建立http的yum倉庫,和ks文件
#掛載centos7的光盤文件到http目錄下
[root@centos8 ~]#mount /dev/sr1 /var/www/html/centos/7/os/x86_64/
#把centos7的ks文件放到http目錄下
[root@centos7 ~]scp ks7.cfg 10.0.0.8:/var/www/html/ksdir
#啟動httpd服務(wù)
[root@centos8 ~]#systemctl start httpd
5.centos7使用ks文件安裝系統(tǒng)
#進(jìn)入開機(jī)界面,按esc鍵進(jìn)入boot界面
#指定ks文件路徑和ip
boot> linux ks=http://10.0.0.8/ksdir/ks7.cfg ip=dhcp
實(shí)驗(yàn)八:實(shí)現(xiàn)pxe安裝雙系統(tǒng)centos6羊异、centos7
1.安裝相關(guān)軟件包并啟動
[root@centos8 ~]#dnf -y install dhcp-server tftp-server httpd syslinux-nonlinux
[root@centos8 ~]#systemctl enable --now httpd tftp dhcpd
2.配置DHCP服務(wù)
[root@centos8 ~]#cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf
[root@centos8 ~]#cat /etc/dhcp/dhcpd.conf
option domain-name "xbd.com";
option domain-name-servers 180.76.76.76, 223.5.5.5;
default-lease-time 86400;
max-lease-time 172800;
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.50 10.0.0.100;
range 10.0.0.150 10.0.0.200;
option routers 10.0.0.2;
next-server 10.0.0.8;
filename "pxelinux.0";
}
[root@centos8 ~]#systemctl start dhcpd
3.準(zhǔn)備yum 源和相關(guān)目錄
[root@centos8 ~]#mkdir -pv /var/www/html/centos/{6,7,8}/os/x86_64/
[root@centos8 ~]#mount /dev/sr0 /var/www/html/centos/6/os/x86_64/
[root@centos8 ~]#mount /dev/sr1 /var/www/html/centos/7/os/x86_64/
[root@centos8 ~]#mount /dev/sr2 /var/www/html/centos/8/os/x86_64/
4.準(zhǔn)備kickstart文件
[root@centos8 ~]#mkdir /var/www/html/ksdir/
[root@centos8 ~]#vim /var/www/html/ksdir/ks6.cfg
[root@centos8 ~]#vim /var/www/html/ksdir/ks7.cfg
[root@centos8 ~]#vim /var/www/html/ksdir/ks8.cfg
5.準(zhǔn)備PXE啟動相關(guān)文件
[root@centos8 ~]#mkdir /var/lib/tftpboot/centos{6,7,8}
#準(zhǔn)備CentOS6疟暖,7迂猴,8各自的內(nèi)核相關(guān)文件
[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/
#以下三個文件是CentOS8安裝所必須文件,CentOS6双戳,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
#最終目錄結(jié)構(gòu)如下
[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
6.準(zhǔn)備啟動菜單文件
[root@centos8 ~]#vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 60
menu title CentOS Linux 8.0.1905
label linux8
menu label Auto install CentOS Linux ^8.0
kernel centos8/vmlinuz
append initrd=centos8/initrd.img quiet ks=http://10.0.0.8/ksdir/ks8.cfg
label linux7
menu label Auto install CentOS Linux ^7.6
kernel centos7/vmlinuz
append initrd=centos7/initrd.img quiet ks=http://10.0.0.8/ksdir/ks7.cfg
label linux^6
menu label Auto install CentOS Linux ^6.10
kernel centos6/vmlinuz
append initrd=centos6/initrd.img quiet ks=http://10.0.0.8/ksdir/ks6.cfg
label rescue8
menu label Rescue a CentOS Linux system
kernel centos8/vmlinuz
append initrd=centos/initrd.img inst.repo=http://10.0.0.8/centos/8/os/x86_64/ rescue quiet
label local
menu default
menu label Boot from ^local drive
localboot 0xffff
7.測試客戶端基于PXE實(shí)現(xiàn)自動安裝
新準(zhǔn)備一臺主機(jī)殖演,設(shè)置網(wǎng)卡引導(dǎo)猾漫,可看到看啟動菜單,并實(shí)現(xiàn)自動安裝