利用 PXE 实现自动化系统部署
作者:互联网
一、PXE介绍
1.PXE:Preboot Excution Environment,预启动执行环境,是由Intel公司研发,基于Client/Server的网 络模式,支持远程主机通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,可以引导 和安装Windows,linux等多种操作系统
2.利用PXE实现自动化安装流程
3.PXE工作原理
1. Client向PXE Server上的DHCP发送IP地址请求消息,DHCP检测Client是否合法(主要是检测Client 的网卡MAC地址),如果合法则返回Client的IP地址,同时将启动文件pxelinux.0的所在TFTP服务 器地址信息一并传送给Client 2. Client向TFTP服务器发送获取pxelinux.0请求消息,TFTP服务器接收到消息之后,向Client发送 pxelinux.0大小信息,试探Client是否满意,当TFTP收到Client发回的同意大小信息之后,正式向 Client发送pxelinux.0 3. Client执行接收到的pxelinux.0文件,并利用此文件启动 4. Client向TFTP 服务器发送请求针对本机的配置信息文件(在TFTP 服务器的pxelinux.cfg目录下), TFTP服务器将启动菜单配置文件发回Client,继而Client根据启动菜单配置文件执行后续操作 5. Client根据启动菜单配置文件里的信息,向TFTP发送Linux内核和initrd文件请求信息,TFTP接收到 消息之后将内核和initrd文件发送给Client 6. Client向TFTP发送根文件请求信息,TFTP接收到消息之后返回Linux根文件系统 7. Client启动Linux内核,加载相关的内核参数 8. Client通过内核参数下载kickstart文件,并根据kickstart文件里的安装信息,下载安装源文件进行 自动化安装
范例:在centos8上实现PXE自动化安装(此范例是基于tftp和dhcpd服务配好的情况下做的)
1.安装前准备
关闭防火墙和SELINUX,DHCP服务器静态IP 网络要求:关闭Vmware软件中的DHCP服务,基于NAT模式
注意:使用 1G 以下内存的主机安装CentOS 7,8 会提示空间不足,建议2G以上
2.安装
安装syslinux-nonlinux包
[root@centos8 ~]# yum -y install syslinux-nonlinux
查看包的内容
[root@centos8 ~]# rpm -ql syslinux-nonlinux /usr/share/syslinux/altmbr.bin /usr/share/syslinux/altmbr_c.bin /usr/share/syslinux/altmbr_f.bin /usr/share/syslinux/cat.c32 /usr/share/syslinux/chain.c32 /usr/share/syslinux/cmd.c32 /usr/share/syslinux/cmenu.c32 /usr/share/syslinux/config.c32 /usr/share/syslinux/cptime.c32 /usr/share/syslinux/cpu.c32 /usr/share/syslinux/cpuid.c32 /usr/share/syslinux/cpuidtest.c32 /usr/share/syslinux/debug.c32 /usr/share/syslinux/dhcp.c32 /usr/share/syslinux/dir.c32 /usr/share/syslinux/disk.c32 /usr/share/syslinux/dmi.c32 /usr/share/syslinux/dmitest.c32 /usr/share/syslinux/elf.c32 /usr/share/syslinux/ethersel.c32 /usr/share/syslinux/gfxboot.c32 /usr/share/syslinux/gptmbr.bin /usr/share/syslinux/gptmbr_c.bin /usr/share/syslinux/gptmbr_f.bin /usr/share/syslinux/gpxecmd.c32 /usr/share/syslinux/hdt.c32 /usr/share/syslinux/hexdump.c32 /usr/share/syslinux/host.c32 /usr/share/syslinux/ifcpu.c32 /usr/share/syslinux/ifcpu64.c32 /usr/share/syslinux/ifmemdsk.c32 /usr/share/syslinux/ifplop.c32 /usr/share/syslinux/isohdpfx.bin /usr/share/syslinux/isohdpfx_c.bin /usr/share/syslinux/isohdpfx_f.bin /usr/share/syslinux/isohdppx.bin /usr/share/syslinux/isohdppx_c.bin /usr/share/syslinux/isohdppx_f.bin /usr/share/syslinux/isolinux-debug.bin /usr/share/syslinux/isolinux.bin /usr/share/syslinux/kbdmap.c32 /usr/share/syslinux/kontron_wdt.c32 /usr/share/syslinux/ldlinux.c32 /usr/share/syslinux/lfs.c32 /usr/share/syslinux/libcom32.c32 /usr/share/syslinux/libgpl.c32 /usr/share/syslinux/liblua.c32 /usr/share/syslinux/libmenu.c32 /usr/share/syslinux/libutil.c32 /usr/share/syslinux/linux.c32 /usr/share/syslinux/lpxelinux.0 /usr/share/syslinux/ls.c32 /usr/share/syslinux/lua.c32 /usr/share/syslinux/mboot.c32 /usr/share/syslinux/mbr.bin /usr/share/syslinux/mbr_c.bin /usr/share/syslinux/mbr_f.bin /usr/share/syslinux/memdisk /usr/share/syslinux/meminfo.c32 /usr/share/syslinux/menu.c32 /usr/share/syslinux/pci.c32 /usr/share/syslinux/pcitest.c32 /usr/share/syslinux/pmload.c32 /usr/share/syslinux/poweroff.c32 /usr/share/syslinux/prdhcp.c32 /usr/share/syslinux/pwd.c32 /usr/share/syslinux/pxechn.c32 /usr/share/syslinux/pxelinux.0 /usr/share/syslinux/reboot.c32 /usr/share/syslinux/rosh.c32 /usr/share/syslinux/sanboot.c32 /usr/share/syslinux/sdi.c32 /usr/share/syslinux/sysdump.c32 /usr/share/syslinux/syslinux.c32 /usr/share/syslinux/syslinux.com /usr/share/syslinux/syslinux.exe /usr/share/syslinux/vesa.c32 /usr/share/syslinux/vesainfo.c32 /usr/share/syslinux/vesamenu.c32 /usr/share/syslinux/vpdtest.c32 /usr/share/syslinux/whichsys.c32 /usr/share/syslinux/zzjson.c32
将/usr/share/syslinux/pxelinux.0和/usr/share/syslinux/menu.c32这两个文件拷贝到/var/lib/tftpboot/目录下
[root@centos8 tftpboot]# cp /usr/share/syslinux/pxelinux.0 /usr/share/syslinux/menu.c32 .
创建centos7和8的目录
[root@centos8 tftpboot]# mkdir centos{7,8}
将centos8光盘里的vmlinuz和initrd.img拷到8目录下
[root@centos8 tftpboot]# cp /misc/cd/isolinux/{vmlinuz,initrd.img} centos8/
将centos7光盘里的vmlinuz和initrd.img拷到7目录下
[root@centos8 tftpboot]# cp /var/www/html/centos/7/os/x86_64/isolinux/{vmlinuz,initrd.img} centos7/
将centos8光盘里的ldlinux.c32,libcom32.c32,libutil.c32三个文件cp到该目录中这是centos8独有的
[root@centos8 tftpboot]# cp /misc/cd/isolinux/{ldlinux.c32,libutil.c32,libcom32.c32} .
现在就缺菜单了,我们需要建一个单独的叫pxelinux.cfg文件夹
[root@centos8 tftpboot]# mkdir pxelinux.cfg
将光盘里的菜单文件/misc/cd/isolinux/isolinux.cfg作为模板拷到pxelinux.cfg目录下
[root@centos8 tftpboot]# cp /misc/cd/isolinux/isolinux.cfg pxelinux.cfg/default
编辑此文件
vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32 timeout 600 menu title Install CentOS Linux label linux8 menu label Auto Install CentOS Linux ^8 kernel centos8/vmlinuz append initrd=centos8/initrd.img ks=http://192.168.93.129/ks/centos8.cfg label linux7 menu label Auto Install CentOS Linux ^7 kernel centos7/vmlinuz append initrd=centos7/initrd.img ks=http://192.168.93.129/ks/centos7.cfg label manual menu label ^Manual Install CentOS Linux 8.0 kernel centos8/vmlinuz append initrd=centos8/initrd.img inst.repo=http://192.168.93.129/centos/8/os/x86_64/ label rescue menu label ^Rescue a CentOS Linux system 8 kernel centos8/vmlinuz append initrd=centos8/initrd.img inst.repo=http://192.168.93.129/centos/8/os/x86_64/ rescue label local menu default menu label Boot from ^local drive localboot 0xffff
我们检查一下
[root@centos8 tftpboot]# tree /var/lib/tftpboot/
三个文件夹10个文件
我们查看其端口:
[root@centos8 tftpboot]# ss -ntul
现在我们就可以装系统了
重启等图形界面进度条没完之前按esc键
成了!
记录于2022-3-15-12:15
标签:syslinux,部署,share,Client,usr,自动化,centos8,PXE,c32 来源: https://www.cnblogs.com/weilanxuesre/p/16054057.html