第七周作业
1.使用kickstart半自动化安装centos操作系统
(1)准备yum源和相关文件
yum -y install httpd
systemctl enable --now httpd
mkdir /var/www/html/centos/7/os/x86_64 -pv
mount /dev/sr0 /var/www/html/centos/7/os/x86_64
(2)安装kickstart工具并生成ks7.cfg文件
yum -y install system-config-kickstart
export DISPLAY=10.0.0.1:0.0
system-config-kickstart #执行命令前打开passive工具
ks-validator ks7.cfg #检查语法格式
vim /etc/yum.repos.d/base.repo
#[base]改为[develoment]
(3)补充ks7.cfg文件
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --plaintext mage@123
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=md5
# Use graphical install
text
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=eth0
# Halt after installation
reboot
# System timezone
timezone Africa/Abidjan --isUtc
# Use network installation
url --url="http://10.0.0.132/centos/7/os/x86_64"
# System bootloader configuration
bootloader --location=mbr
ignoredisk --only-use=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --fstype="xfs" --size=100000
part /boot --fstype="xfs" --size=1024
part swap --fstype="swap" --size=2048
%post
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]
name=CentOS-\$releasever Base
baseurl=https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch/
enabled=1
gpgcheck=0
[epel]
name=CentOS-\$releasever Epel
baseurl=https://mirrors.aliyun.com/epel/\$releasever/\$basearch/
https://mirrors.huaweicloud.com/epel/\$releasever/\$basearch/
enabled=1
gpgcheck=0
[extras]
name=CentOS-\$releasever Extras
baseurl=https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/
https://mirrors.huaweicloud.com/centos/\$releasever/extras/\$basearch/
enabled=1
gpgcheck=0
EOF
mkdir /root/.ssh
cat > /root/.ssh/authorized_keys <<EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDQgWrsbf/+cw6HZxOu8ZSaAZgc5Kh0ahjwfcsfMNW/I5WajepUnFLzZuxJgx9+1V3m6vlgj9WHiy36J8itmoYOENIEvwL2l79zpjwwb8NdRuxgSDg1UKxl6aDMtDx7fNTAMnT7Tdzp/2Kpsn+PCzHnrmOJbHKOb/y9LYtTKepiNM5mNSbDZU5pQ+4Poq/P++6xSR4WwFJnWDLl+jNQfR4lA2XuJ1x7N2apSWZ7zdKIKrxyG+XrVNQ0EvxwPERfv35Q2iCdDgMdR3NTRCFS7odorCmOuXWTcucXJHUuIEBF6fOiNzqJjMw/yg98SHywxQ+JH0Uhgp15zCbZTHpl1l8t root@CentOS8-2
EOF
useradd zhang
echo mage@123 |passwd --stdin zhang
%end
%packages
@web-server
%end
(4)通过httpd服务访问ks7.cfg文件
mkdir /var/www/html/ksdir
cp ks7.cfg /var/www/html/ksdir/
(5)新建centos7-ks虚拟机并挂载光盘
- 在centos8上实现PXE自动化安装Centos6,7,8
(1)安装相关软件包并启动
yum -y install httpd tftp-server dhcp-server syslinux-nonlinux
systemctl enable --now httpd tftp
(2)配置DHCP服务
vim /etc/dhcp/dhcpd.conf #其他行注释,:,$s@\(^[^#]\)@#\1@
dhcpd -t -cf/etc/dhcp/dhcpd.conf #检查是否存在语法错误
systemctl enable --now dhcpd
(3)准备yum源和相关目录
mkdir -pv /var/www/html/centos/{6,7,8}/os/x86_64/
mount -r /dev/sr0 /var/www/html/centos/6/os/x86_64/
mount -r /dev/sr1 /var/www/html/centos/7/os/x86_64/
mount -r /dev/sr2 /var/www/html/centos/8/os/x86_64/
(4)准备kickstart文件
[root@CentOS8-1 ~]#mkdir /var/www/html/ks
[root@CentOS8-1 ~]#cat /var/www/html/ks/centos6.cfg
install
text
reboot
url --url=http://10.0.0.135/centos/6/os/x86_64/
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp --noipv6 --hostname centos6.zhang.com
rootpw --iscrypted $6$Duj3su4K7cBDJe0T$7Hc8yXJyuQqRX4CeOHjahJe9XCWDsbTrgVAgiaowHHtrW6bjSskxY9lGiNL6nY/HEtxOuDQO8UOvlq/TrGRil0
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=102400
part /data --fstype=ext4 --size=51200
part swap --size=2048
%packages
@core
@server-policy
@workstation-policy
autofs
vim-enhanced
%end
%post
useradd zhang
echo mage@123 | passwd --stdin zhang &> /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=CentOS-\$releasever Base
baseurl=https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch/
enabled=1
gpgcheck=0
[epel]
name=CentOS-\$releasever Epel
baseurl=https://mirrors.aliyun.com/epel/\$releasever/\$basearch/
https://mirrors.huaweicloud.com/epel/\$releasever/\$basearch/
enabled=1
gpgcheck=0
[extras]
name=CentOS-\$releasever Extras
baseurl=https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/
https://mirrors.huaweicloud.com/centos/\$releasever/extras/\$basearch/
enabled=1
gpgcheck=0
EOF
%end
[root@CentOS8-1 ~]#cat /var/www/html/ks/centos7.cfg
install
xconfig --startxonboot
keyboard --vckeymap=us --xlayouts='us'
rootpw --iscrypted $6$eTdlrRmdSzjQr8fy$KYuBGJlxw.ylvEr5JxwaD8esiopGVVUXWoaBmweSrdmjivQrikHk927OpeqeE9hoAmXN.m9ZG48Z.4FHLdelB/
url --url="http://10.0.0.135/centos/7/os/x86_64"
lang en_US
auth --useshadow --passalgo=sha512
text
firstboot --enable
selinux --disabled
skipx
services --disabled="chronyd"
ignoredisk --only-use=sda
firewall --disabled
network --bootproto=dhcp --device=eth0
network --hostname=centos7.zhang.com
reboot
timezone Asia/Shanghai --nontp
bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda
zerombr
#autopart --type=lvm
clearpart --all --initlabel
part swap --fstype="swap" --ondisk=sda --size=2048
part / --fstype="xfs" --ondisk=sda --size=102400
part /boot --fstype="xfs" --ondisk=sda --size=1024
part /data --fstype="xfs" --ondisk=sda --size=51200
%post
useradd kobe
echo mage@123 | passwd --stdin zhang
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=CentOS-\$releasever Base
baseurl=https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch/
enabled=1
gpgcheck=0
[epel]
name=CentOS-\$releasever Epel
baseurl=https://mirrors.aliyun.com/epel/\$releasever/\$basearch/
https://mirrors.huaweicloud.com/epel/\$releasever/\$basearch/
enabled=1
gpgcheck=0
[extras]
name=CentOS-\$releasever Extras
baseurl=https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/
https://mirrors.huaweicloud.com/centos/\$releasever/extras/\$basearch/
enabled=1
gpgcheck=0
EOF
%end
%packages
@core
%end
[root@CentOS8-1 ~]#cat /var/www/html/ks/centos6.cfg
ignoredisk --only-use=sda
zerombr
text
reboot
clearpart --all --initlabel
selinux --disabled
firewall --disabled
url --url=http://10.0.0.135/centos/8/os/x86_64/
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
network --bootproto=dhcp --device=eth0 --ipv6=auto --activate
bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda
network --hostname=centos8.zhang.com
rootpw --iscrypted $6$9htDQBQerzPBGNAh$9X5bZk6FbOGLArpumKOOrIOm3T4Oic.2v36rqNny28W1DxQTC8wNHGpQ8AAuL3TiPcyFbLP164wqmZb1mMcT1.
firstboot --enable
skipx
services --disabled="chronyd"
timezone Asia/Shanghai --isUtc --nontp
user --name=zhang --password=$6$9b0sKYtYhQhcarc6$hqwO9wI277zKrt6P1bJZPRiDKzfZph0PGjqjorx.LFooHolzQTzuDShCLa229342Tn5c1/yokcnBmbDmKbDQ.1 --iscrypted --gecos="zhang"
#autopart --type=lvm
#part / --fstype xfs --size 1 --grow --ondisk sda 可以实现根自动使用所有剩余空间
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
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=CentOS-\$releasever Base
#baseurl=file:///misc/cd/BaseOS
baseurl=https://mirrors.aliyun.com/centos/\$releasever/BaseOS/\$basearch/os/
https://mirrors.huaweicloud.com/centos/\$releasever/BaseOS/\$basearch/os/
enabled=1
gpgcheck=0
[AppStream]
name=CentOS-\$releasever Appstream
#baseurl=file:///misc/cd/AppStream
baseurl=https://mirrors.aliyun.com/centos/\$releasever/AppStream/\$basearch/os/
https://mirrors.huaweicloud.com/centos/\$releasever/AppStream/\$basearch/os/
enabled=1
gpgcheck=0
[epel]
name=CentOS-\$releasever Epel
baseurl=https://mirrors.aliyun.com/epel/\$releasever/Everything/\$basearch/
https://mirrors.huaweicloud.com/epel/\$releasever/Everything/\$basearch/
enabled=1
gpgcheck=0
[extras]
name=CentOS-\$releasever Extras
baseurl=https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/os/
https://mirrors.huaweicloud.com/centos/\$releasever/extras/\$basearch/os/
enabled=1
gpgcheck=0
EOF
%end
(5)准备PXE启动相关文件
[root@CentOS8-1 centos6]#cd /var/www/html/centos/8/os/x86_64/isolinux/
[root@CentOS8-1 isolinux]#ls
boot.cat grub.conf isolinux.bin ldlinux.c32 libutil.c32 splash.png vesamenu.c32
boot.msg initrd.img isolinux.cfg libcom32.c32 memtest TRANS.TBL vmlinuz
[root@CentOS8-1 ~]#cp /var/www/html/centos/6/os/x86_64/isolinux/{initrd.img,vmlinuz} /var/lib/tftpboot/centos6/
[root@CentOS8-1 ~]#cp /var/www/html/centos/7/os/x86_64/isolinux/{initrd.img,vmlinuz} /var/lib/tftpboot/centos7/
[root@CentOS8-1 ~]#cp /var/www/html/centos/8/os/x86_64/isolinux/{initrd.img,vmlinuz} /var/lib/tftpboot/
[root@CentOS8-1 ~]#cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/
(6)准备启动菜单文件
[root@CentOS8-1 ~]#mkdir /var/lib/tftpboot/pxelinux.cfg
[root@CentOS8-1 ~]#cat /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 600
menu title Install CentOS Linux
label linux8
menu label Install CentOS Linux ^8
kernel centos8/vmlinuz
append initrd=centos8/initrd.img ks=http://10.0.0.135/ks/centos8.cfg
label linux7
menu label Install CentOS Linux ^7
kernel centos7/vmlinuz
append initrd=centos7/initrd.img ks=http://10.0.0.135/ks/centos7.cfg
label linux6
menu label Install CentOS Linux ^6
kernel centos6/vmlinuz
append initrd=centos6/initrd.img ks=http://10.0.0.135/ks/centos6.cfg
label manual
menu label ^Manual Install CentOS Linux 8
kernel centos8/vmlinuz
append initrd=centos8/initrd.img inst.repo=http://10.0.0.135/centos/8/os/x86_64/
label rescue
menu label ^Rescue a CentOS Linux system
kernel centos8/vmlinuz
append initrd=centos8/initrd.img inst.repo=http://10.0.0.135/centos/8/os/x86_64/ rescue
label local
menu default
menu label Boot from ^local drive
localboot 0xffff
(7)核对所需文件
[root@CentOS8-1 ~]#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
[root@CentOS8-1 ~]#tree /var/www/html/ks
/var/www/html/ks
├── centos6.cfg
├── centos7.cfg
└── centos8.cfg
0 directories, 3 files
(8)测试客户端基于PXE实现自动化安装