关闭防火墙和SELINUX,DHCP服务器静态IP
网络要求:关闭Vmware软件中的DHCP服务,基于NAT模式
注意:使用1G以下的内存的主机安装CentOS 7,8会提示空间不足,建议2G以上
[root@centos8 ~]#yum -y install dhcp-server tftp-server httpd syslinux-nonlinux
[root@centos8 ~]#systemctl enable --now httpd tftp
[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,233.5.5.5;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
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";
}
#并将后面的非#开头的行注释掉,方法在末行模式下,:.,$s@\(^[^#]\)@#\1@
保存退出
[root@centos8 ~]#systemctl enable --now dhcpd
[root@centos8 ~]#mkdir -pv /var/www/html/centos/{6,7,8}/os/x86_64/
[root@centos8 ~]#mount -r /dev/sr0 /var/www/html/centos/6/os/x86_64/
[root@centos8 ~]#mount -r /dev/sr1 /var/www/html/centos/7/os/x86_64/
[root@centos8 ~]#mount -r /dev/sr2 /var/www/html/centos/8/os/x86_64/
#在浏览器上验证搭建的yum仓库是否能访问
[root@centos8 ~]#mkdir /var/www/html/ks
[root@centos8 ~]#vim /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 --hostname centos6.kobe.com
rootpw --iscrypted $6$ZqApgQaeO0mXFWe.$IBfhxqiDlWcrgIKkjexjBltP8R2UXdM/PkvQ4GvnXl25Zzcoh4ZrrhFv9.dEZrm6oSjEDSJ7KwonWEh54JsiL0
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 kobe
echo centos | passwd --stdin kobe &> /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 < /etc/yum.repos.d/base.repo < /etc/yum.repos.d/base.repo <
[root@centos8 ~]#mkdir /var/lib/tftpboot/centos{6,7,8}
#准备CentOS6,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/{initrd.img,vmlinuz} /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
#最终目录结构如下
[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
[root@centos8 ~]#vim /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.8/ks/centos8.cfg
label linux7
menu label 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 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
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
kernel centos8/vmlinuz
append initrd=centos8/initrd.img inst.repo=http://10.0.0.8/centos/8/os/x86_64/ rescue
label local
menu default
menu label Boot from ^local drive
localboot 0xffff
新准备一台主机,选择网卡引导,可看到启动菜单,并实现自动安装
注意:VMware workstation对于不同的CentOS版本,生产的虚拟机的硬件不兼容
这里以安装centos 8为例: