Linux系统管理与编程16:PXE自动化安装部署centos7.9操作系统
兰生幽谷,不为莫服而不芳;
君子行义,不为莫知而止休。
0.准备
1)防火墙和SELinux
systemctl stop firewalld systemctl disable firewalld setenforce 0 sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config |
(很不好的习惯,但省事)
3)yum源
1.按照必要工具:dhcp、tftp-server、http、syslinux(提供pxe引导所需的配置文件)
yum install -y dhcp tftp-server httpd tftp |
2.配置dhcp
cd /etc/dhcp vi dhcpd.conf |
配置文件:
subnet 192.168.100.0 netmask 255.255.255.0{ range 192.168.100.30 192.168.100.60; default-lease-time 3600; filename "pxelinux.0"; next-server 192.168.100.111; } |
以宿主物理机做平台,测试一下:
图16- 1
3.配置tftp
vi /etc/xinetd.d/tftp (disable处改为no)
图16- 2
重新启动tftp
systemctl restart tftp.socket
4.配置apache
1)保证安装光驱插入,且处于已连接状态
图16- 3
启动httpd:出错了!
查看一下,端口怎么被占用的,处理后重新启动
[root@shell ~]# netstat -tulnp | grep :80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1051/nginx: master tcp6 0 0 :::80 :::* LISTEN 1051/nginx: master [root@shell ~]# systemctl stop nginx [root@shell ~]# systemctl disable nginx Removed symlink /etc/systemd/system/multi-user.target.wants/nginx.service. [root@shell ~]# systemctl start httpd [root@shell ~]# systemctl enable httpd Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. |
在apache默认目录下创建Centos目录,并将光盘挂上去
mkdir -p var/www/html/Centos [root@shell html]# mount -t iso9660 /dev/sr0 /var/www/html/Centos |
以台式机为平台,测试一下
图16- 5
拷贝pxe自动部署所需的配置文件
[root@shell tftpboot]# cp /usr/share/syslinux/pxelinux.0 ./ [root@shell tftpboot]# cp /usr/share/syslinux/menu.c32 ./ [root@shell ~]# mount -t iso9660 /dev/sr0 /var/www/html/Centos [root@shell tftpboot]# cp /var/www/html/Centos/isolinux/vmlinuz ./ [root@shell tftpboot]# cp /var/www/html/Centos/isolinux/initrd.img ./ [root@shell tftpboot]# ls initrd.img menu.c32 pxelinux.0 vmlinuz [root@shell tftpboot]# mkdir pxelinux.cfg && cd pxelinux.cfg [root@shell pxelinux.cfg]# cat default default menu.c32 timeout 300 prompt 0 label 1 menu label ^1)Install CentOS7.9.2207 menu default kernel vmlinuz append initrd=initrd.img method=http://192.168.100.111/Centos ks=http://192.168.100.111/ks.cfg |
准备部署系统的配置文件cs.cfg
[root@shell pxelinux.cfg]# cd /var/www/html [root@shell html]# cp ~/anaconda-ks.cfg ./ [root@shell html]# mv anaconda-ks.cfg ks.cfg [root@shell html]# chmod +r ks.cfg [root@shell html]# vi ks.cfg |
红色部分是根据自己的实际情况,需要改动的:
…… # cdrom url --url http://192.168.100.111/Centos7 # Use graphical install #graphical text …… # Root password rootpw wu …… clearpart --all --initlabel …… poweroff |
说明:为了省事,root口令是明文,且很短。用户登录后自行改动。
5.重启httpd tftp.socket dhcpd三个服务
至此,服务器端部署完毕。
6.新建需要部署Centos系统的虚拟机
1)vmware workstation:文件--》新建虚拟机
图16- 6
图16- 7
图16- 8
据网上说,内存一定要2GB以上,否则会死机。
图16- 9
图16- 10
改一下网卡,处于DHCP管控的IP网卡之下
图16- 11
启动新建的虚拟机:
图16- 12
出错了!
图16- 13
得把cs.cfg的echo行删掉
图16- 14
部署完毕。
登录测试,做好网卡配置
看看网卡
图16- 15
改变该虚拟机的网卡
图16- 16
看看配置文件
图16- 17
是kickstart自动生成的配置文件,好像和自己手动安装的不一样。我们做下面的改动工作
…… ONBOOT=no …… NAME=ens33 …… #UUID…… …… |
重启一下网络
nmcli c reload ens33 nmcli c up ens33 |
图16- 18
剩下的就是搭建yum源等工作了。