1.部署服务机环境
关闭防火墙和selinux
插入centos6,7,8光盘
关闭VMware的DHCP
2.启用HTTP服务
[root@centos7 ~]# echo "- - -" > /sys/class/scsi_host/host0/scan ;echo "- - -" > /sys/class/scsi_host/host1/scan;echo "- - -" > /sys/class/scsi_host/host2/scan #读取插入的光盘
[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 2G 0 part [SWAP]
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 50G 0 part /data
sr0 11:0 1 3.7G 0 rom
sr1 11:1 1 7G 0 rom
sr2 11:2 1 4.4G 0 rom
[root@centos7 ~]# yum -y install httpd;systemctl enable --now httpd #安装httpd服务,并开启
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
[root@centos7 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-09-10 08:09:54 CST; 23min ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 1126 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─1126 /usr/sbin/httpd -DFOREGROUND
├─1203 /usr/sbin/httpd -DFOREGROUND
├─1204 /usr/sbin/httpd -DFOREGROUND
├─1205 /usr/sbin/httpd -DFOREGROUND
├─1210 /usr/sbin/httpd -DFOREGROUND
└─1212 /usr/sbin/httpd -DFOREGROUND
Sep 10 08:09:51 centos7.magedu.org systemd[1]: Starting The Apache HTTP Server...
Sep 10 08:09:54 centos7.magedu.org systemd[1]: Started The Apache HTTP Server.
[root@centos7 ~]# mkdir -pv /var/www/html/centos/{8,7,6}/os/x86_64/ #在httpd服务器上创建6,7,8相应的文件
[root@centos7 ~]# tree /var/www/html
/var/www/html
└── centos
├── 6
│ └── os
│ └── x86_64
├── 7
│ └── os
│ └── x86_64
└── 8
└── os
└── x86_64
10 directories, 0 files
#将对应的光盘挂载到httpd服务器文件上
[root@centos7 ~]# mount /dev/sr0 /var/www/html/centos/6/os/x86_64
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos7 ~]# mount /dev/sr2 /var/www/html/centos/7/os/x86_64
mount: /dev/sr2 is write-protected, mounting read-only
[root@centos7 ~]# mount /dev/sr1 /var/www/html/centos/8/os/x86_64
mount: /dev/sr1 is write-protected, mounting read-only
3.创建kickstart应答文件
创建centos8的kickstart应答文件
[root@centos ~]#vim /etc/yum.repos.d/***.repo
[development] #把原来"[]"内的内容改成development,其它不变
[root@centos7 ~]# yum -y install system-config-kickstart
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
[root@centos7 ~]# 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, langpacks
[root@centos7 ~]# mkdir /var/www/html/ksdir #创建应答文件夹
[root@centos7 ~]# cp ks8.cfg /var/www/html/ksdir/ #把生成好的应答文件拷贝到httpd服务器上
centos7准备kickstart文件
[root@centos7 ~]# vim /var/www/html/ksdir/ks7.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$f0OOktfs$ZFjz9pvGPbsruDl3W9GdG/
# 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.130/centos/7/os/x86_64/"
# 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="xfs" --size=100000
part /boot --fstype="xfs" --size=1000
part swap --fstype="swap" --size=2048
%post
mkdir -pv /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
cat > etc/yum.repos.d/base.repo <<EOF
[BaseOS]
name=base
baseurl=https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch/
enabled=1
gpgcheck=0
[epel]
name=epel
baseurl=https://mirrors.huaweicloud.com/epel/\$releasever/\$basearch/
https://mirrors.aliyun.com/epel/\$releasever/\$basearch/
enabled=1
gpgcheck=0
EOF
yum clean all
yum makecache
useradd hu
echo 123456 |passwd --stdin hu
mkdir /root/.ssh -m 700
cat > /root/.ssh/authorized_keys <<EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDL1KEP4C1YCiok1UeKv5oSQnGoNZH0HysOKI+HALmWWARcUhqiSjv0LrGRQGPPUVvfV/zuWBXdnq4MI1+OV3lre1Qf8uZylrF78BLHnxFbwYMK6kMlrUqC9PRyb5ILawysvqEJ1UDTjo4Qg9950JpLueFmlTvun/ZzMfD6+7Ikj22QM3CG2M/PlEWLz+Afz5+fKfUTV5LK9nOpsWh+XyYqujYoniZEH2dKVuz/rfSybRu2oZbAhRQEUXImmV27xuD1a7Ar8nFON+6cB6YIGHZEqRdoI3f3pjXtsS+1uV80O7UwK0QaQiMKdIb/Uy4vef0ya9G8FUTCI2DPilWO95wX root@Centos
EOF
chmod 600 /root/.ssh/authorized_keys
%end
%packages
@web-server
%end
centos6准备kickstart文件
[root@centos7 ~]# vim /var/www/html/ksdir/ks6.cfg
install
text
reboot
url --url=http://10.0.0.130/centos/6/os/x86_64/
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp --noipv6
rootpw --iscrypted $1$f0OOktfs$ZFjz9pvGPbsruDl3W9GdG/
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
@web-server
%end
%post
mkdir -pv /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
cat > etc/yum.repos.d/base.repo <<EOF
[BaseOS]
name=base
baseurl=https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch/
enabled=1
gpgcheck=0
[epel]
name=epel
baseurl=https://mirrors.huaweicloud.com/epel/\$releasever/\$basearch/
https://mirrors.aliyun.com/epel/\$releasever/\$basearch/
enabled=1
gpgcheck=0
EOF
yum clean all
yum makecache
useradd hu
echo 123456 |passwd --stdin hu
mkdir /root/.ssh -m 700
cat > /root/.ssh/authorized_keys <<EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDL1KEP4C1YCiok1UeKv5oSQnGoNZH0HysOKI+HALmWWARcUhqiSjv0LrGRQGPPUVvfV/zuWBXdnq4MI1+OV3lre1Qf8uZylrF78BLHnxFbwYMK6kMlrUqC9PRyb5ILawysvqEJ1UDTjo4Qg9950JpLueFmlTvun/ZzMfD6+7Ikj22QM3CG2M/PlEWLz+Afz5+fKfUTV5LK9nOpsWh+XyYqujYoniZEH2dKVuz/rfSybRu2oZbAhRQEUXImmV27xuD1a7Ar8nFON+6cB6YIGHZEqRdoI3f3pjXtsS+1uV80O7UwK0QaQiMKdIb/Uy4vef0ya9G8FUTCI2DPilWO95wX root@Centos
EOF
chmod 600 /root/.ssh/authorized_keys
%end
3.DHCP服务
[root@centos7 ~]# yum -y install dhcp
[root@centos7 ~]# systemctl enable --now dhcpd
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.
[root@centos7 ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
[root@centos7 ~]# cat /etc/dhcp/dhcpd.conf #DHCP配置文件格式
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers 180.76.76.76, 223.5.5.5;
default-lease-time 86400;
max-lease-time 172800;
# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.20 10.0.0.100;
range 10.0.0.150 10.0.0.200;
option routers 10.0.0.2;
next-server 10.0.0.130; #本机地址,TFTP服务器地址
filename "pxelinux.0"; #bootloader启动文件的名称
}
# This is a very basic subnet declaration.
#subnet 10.254.239.0 netmask 255.255.255.224 {
# range 10.254.239.10 10.254.239.20;
# option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
#}
# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.
#subnet 10.254.239.32 netmask 255.255.255.224 {
# range dynamic-bootp 10.254.239.40 10.254.239.60;
# option broadcast-address 10.254.239.31;
# option routers rtr-239-32-1.example.org;
#}
# A slightly different configuration for an internal subnet.
#subnet 10.5.5.0 netmask 255.255.255.224 {
# range 10.5.5.26 10.5.5.30;
# option domain-name-servers ns1.internal.example.org;
# option domain-name "internal.example.org";
# option routers 10.5.5.1;
# option broadcast-address 10.5.5.31;
# default-lease-time 600;
# max-lease-time 7200;
#}
# Hosts which require special configuration options can be listed in
# host statements. If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.
#host passacaglia {
# hardware ethernet 0:0:c0:5d:bd:95;
# filename "vmunix.passacaglia";
# server-name "toccata.fugue.com";
#}
# Fixed IP addresses can also be specified for hosts. These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP. Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
#host fantasia {
# hardware ethernet 08:00:07:26:c0:a5;
# fixed-address fantasia.fugue.com;
#}
# You can declare a class of clients and then do address allocation
# based on that. The example below shows a case where all clients
# in a certain class get addresses on the 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet.
#class "foo" {
# match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
#}
#shared-network 224-29 {
# subnet 10.17.224.0 netmask 255.255.255.0 {
# option routers rtr-224.example.org;
# }
# subnet 10.0.29.0 netmask 255.255.255.0 {
# option routers rtr-29.example.org;
# }
# pool {
# allow members of "foo";
# range 10.17.224.10 10.17.224.250;
# }
# pool {
# deny members of "foo";
# range 10.0.29.10 10.0.29.230;
# }
#}
[root@centos7 ~]# systemctl enable --now dhcpd #修改配置文件后成功启用DHCP
[root@centos7 ~]# systemctl restart dhcpd #修改配置文件后重启服务
#DHCP配置文件添加下面参数指定MAC地址分配IP
host test {
hardware ethernet $MAC;
fixed-address $IP;
}
4.TFTP服务
[root@centos7 ~]# yum -y install tftp-server
[root@centos7 ~]# systemctl enable --now tftp
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
[root@centos7 ~]# cd /var/lib/tftpboot/
[root@centos7 tftpboot]# yum provides */pxelinux.0
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* development: mirrors.163.com
* extras: mirrors.ustc.edu.cn
* updates: mirrors.163.com
development/7/x86_64/filelists_db | 7.1 MB 00:00:45
syslinux-4.05-15.el7.x86_64 : Simple kernel loader which boots from a FAT filesystem
Repo : development
Matched from:
Filename : /usr/share/syslinux/pxelinux.0
syslinux-tftpboot-4.05-15.el7.noarch : SYSLINUX modules in /var/lib/tftpboot, available for network booting
Repo : development
Matched from:
Filename : /var/lib/tftpboot/pxelinux.0
[root@centos7 ~]# yum -y install syslinux
[root@centos7 tftpboot]# rpm -ql syslinux|grep pxelinux.0
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0
[root@centos7 tftpboot]# cp /usr/share/syslinux/pxelinux.0 .
[root@centos7 tftpboot]# ls
pxelinux.0
[root@centos7 tftpboot]# pwd
/var/lib/tftpboot
[root@centos7 tftpboot]# cd /var/www/html/centos/8/os/x86_64/
AppStream/ BaseOS/ EFI/ images/ isolinux/
[root@centos7 tftpboot]# cd /var/www/html/centos/8/os/x86_64/isolinux/
[root@centos7 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@centos7 isolinux]# cp ldlinux.c32 libcom32.c32 libutil.c32 /var/lib/tftpboot
[root@centos7 isolinux]# cd /var/lib/tftpboot
[root@centos7 tftpboot]# mkdir pxelinux.cfg
[root@centos7 tftpboot]# ls /data/iso/isolinux/
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@centos7 tftpboot]# cp /data/iso/isolinux/isolinux.cfg pxelinux.cfg/default
[root@centos7 tftpboot]# cat pxelinux.cfg/default
default menu.c32
timeout 600
menu title CentOS Linux 6 7 8
label linux
menu label Auto Install CentOS Linux ^8
kernel centos8/vmlinuz
append initrd=centos8/initrd.img ks=http://10.0.0.130/ksdir/ks8.cfg
label linux
menu label Auto Install CentOS Linux ^7
kernel centos7/vmlinuz
append initrd=centos7/initrd.img ks=http://10.0.0.130/ksdir/ks7.cfg
label linux
menu label Auto Install CentOS Linux ^6
kernel centos6/vmlinuz
append initrd=centos6/initrd.img ks=http://10.0.0.130/ksdir/ks6.cfg
label rescue
menu label ^Rescue a CentOS8 Linux system
kernel centos8/vmlinuz
append initrd=centos8/initrd.img inst.repo=http://10.0.0.130/centos/8/os/x86_64/ rescue
label rescue
menu label ^Rescue a CentOS7 Linux system
kernel centos7/vmlinuz
append initrd=centos7/initrd.img inst.repo=http://10.0.0.130/centos/7/os/x86_64/ rescue
label rescue
menu label ^Rescue a CentOS6 Linux system
kernel centos6/vmlinuz
append initrd=centos6/initrd.img inst.repo=http://10.0.0.130/centos/6/os/x86_64/ rescue
label local
menu default
menu label Boot from ^local drive
localboot 0xffff
[root@centos7 tftpboot]# cp /var/www/html/centos/6/os/x86_64/isolinux/initrd.img centos6
[root@centos7 tftpboot]# cp /var/www/html/centos/6/os/x86_64/isolinux/vmlinuz centos6
[root@centos7 tftpboot]# cp /var/www/html/centos/7/os/x86_64/isolinux/vmlinuz centos7
[root@centos7 tftpboot]# cp /var/www/html/centos/7/os/x86_64/isolinux/initrd.img centos7
[root@centos7 tftpboot]# cp /var/www/html/centos/8/os/x86_64/isolinux/initrd.img centos8
[root@centos7 tftpboot]# cp /var/www/html/centos/8/os/x86_64/isolinux/vmlinuz centos8
[root@centos7 tftpboot]# tree
.
├── 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
到这里准备工作都结束了,开始安装
5.安装系统
启动系统按esc进入Boot Menu,选择4
3台虚拟机分别安装6,7,8
安装完成!