Article directory
- PXE realizes unmanned batch deployment server
PXE realizes unmanned batch deployment server
1. PXE overview
1.1 What is PXE
- PEX (Pre-Boot Execution Environment), is a boot method, not an installation method.
- Working mode based on Client/Server
- PXE is in the ROM of the network card. When the computer boots, the BIOS transfers the PXE Client into the memory for execution, and the PXE Client downloads the files placed at the remote end to run locally through the network.
1.2 What is KickStart
-
KickStart is an unattended installation method. KickStart works by recording various parameters (language, time zone, password, partition, keyboard, etc.) that need to be filled in during a typical installation process, and generating a ks.cfg document. (The name can be modified, the default is ks.cfg)
-
In the subsequent installation process, when there is a situation where parameters are required to be filled in, the installation program will first look for the file generated by KickStart. When the appropriate parameters are found, the found parameters will be used. When no suitable parameters are found, it will be stuck, requiring manual intervention.
-
If the KickStart file covers all the parameters that need to be filled in during the installation process, you only need to tell the installer where to get the ks.cfg file. After the installation is complete, the installer will restart the system according to the restart options set in ks.cfg and end the installation.
1.3 Necessary conditions for installation
-
The BIOS supports PXE, which needs to be enabled in the BIOS
-
NIC network card support
Second, the working principle of PXE
2.1 Working principle
-
Topology
-
How PXE works
1.首先 PXE Client 向 DHCP 服务器发起请求分配IP(网卡需要向DHCP请求地址,获取信息) 2. DHCP 除了给你分配地址外,还会给你分配 boot-loader name(引导程序的名字) 以及Tftp 服务器IP地址 3.网卡使用Tftp 的客户端,向tftp服务器发起请求,把引导程序(pxelinux.0)加载到内存中来 4.然后 BIOS会执行这个引导程序。 5.引导程序会 boot-loader会从tftp去查找它的配置文件(default) 6.根据配置文件来引导
2.2 The experimental environment
-
lab environment
CPU name network mode IP address Server Only host
vmware needs to turn off DHP10.0.0.100 Client host only DHCP assignment
2.3 Contents required to perform PXE+KiskStart installation
-
DHCP server is used to assign IP to clients
-
The TFTP server is used to store PXE related files: system boot files
-
FTP|NFS|HTTP server is used to store system installation files
-
The ks.cfg configuration file generated by KickStart
-
A host that will be installed with a PXE-enabled network card
3. Installation steps
3.1 Configure YUM source
-
YUM source configuration
[root@Server~]# cd /etc/yum.repos.d/ [root@Server/etc/yum.repos.d]# ls rivers.repo [root@Server/etc/yum.repos.d]# mv rivers.repo rivers.repo.bak [root@Server/etc/yum.repos.d]# vim dvd.repo [development] name=Centos7.6 baseurl=file:///mnt enabled=1 gpgcheck=0 [root@Server~]# mount /dev/cdrom /mnt/ mount: /dev/sr0 is write-protected, mounting read-only [root@Server~]# [root@Server~]# yum clean all Loaded plugins: fastestmirror Cleaning repos: development Other repos take up 137 M of disk space (use --verbose for details) [root@Server~]#
3.2 Turn off firewall and selinux
-
Turn off firewall, selinux
[root@Server~]# systemctl disable firewalld --now [root@Server~]#setenforce 0 # selinux 开机才生效,setenforce 0 临时关闭
3.3 安装DHCP 、tftp(tftp-server、xinetd)
3.3.1 Install dhcp, tftp-server, xinetd
-
Install dhcp, tftp-server
[root@Server~]# yum -y install dhcp tftp-server xinetd Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package dhcp.x86_64 12:4.2.5-68.el7.centos.1 will be installed ……
3.3.2 Configuring DHCP Service
-
Configure DHCP file
# 1.进入 dhcp目录 [root@Server~]# cd /etc/dhcp/ [root@Server/etc/dhcp]# ls dhclient.d dhcpd6.conf scripts dhclient-exit-hooks.d dhcpd.conf # 2.查看默认配置文件,是空的,但是/usr/share/doc/dhcp*/目录下有配置模板,我们可以拷贝 [root@Server/etc/dhcp]# cat dhcpd.conf # # DHCP Server Configuration file. # see /usr/share/doc/dhcp*/dhcpd.conf.example # see dhcpd.conf(5) man page # [root@Server/etc/dhcp]# # 3.拷贝dhcpd 配置模板文件 [root@Server/etc/dhcp]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y # 4. 修改dhcp 文件,(这里可以不用拷贝配置文件,直接复制下面一段。subnet--filename) # A slightly different configuration for an internal subnet. subnet 10.0.0.0 netmask 255.255.255.0 { range 10.0.0.120 10.0.0.200; option domain-name-servers 10.0.0.5, 10.0.0.6; option domain-name "example.com"; option routers 10.0.0.254; option broadcast-address 10.0.0.255; default-lease-time 600; max-lease-time 7200; next-server 10.0.0.100; filename "pxelinux.0"; } subnet 10.0.0.0 netmask 255.255.255.0 #宣告网段 range 10.0.0.120 10.0.0.200; #分配地址范围 option domain-name-servers: #dns配置,正常公司会有2个DNS我这里随意配的 option routers 10.0.0.254; # 设置网关的 option broadcast-address 10.0.0.255; # 设置广播地址 default-lease-time 600; # 默认租约时间,它的单位为秒 max-lease-time 7200; #最大租约时间,它的单位为秒 next-server 10.0.0.100; # tftp-server IP地址 filename "/pxelinux.0"; # 网络启动程序,(网络引导) # 5. 启动dhcp 服务器, [root@Server/etc/dhcp]# systemctl enable dhcpd Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service. [root@Server/etc/dhcp]# systemctl start dhcpd [root@Server/etc/dhcp]# [root@Server/etc/dhcp]# netstat -lantup|grep :67 udp 0 0 0.0.0.0:67 0.0.0.0:* 8503/dhcpd [root@Server/etc/dhcp]# [root@Server/etc/dhcp]# cd [root@Server~]# @补充:如果全局配置了,子配置没配置,那么将读取全局设置 如果全局配置了,子的也配置了,那么将以自配置为准。
3.3.3 Configure tftp service
-
enable tftp service
# 1.修改tftp配置文件 [root@Server~]# vim /etc/xinetd.d/tftp 将 disable = no 改为 yes #重启 xinetd [root@Server~]# systemctl restart xinetd.service [root@Server~]# netstat -lntup|grep :69 udp 0 0 0.0.0.0:69 0.0.0.0:* 9071/xinetd [root@Server~]#
3.3.4 Install syslinux and copy the pxelinux.0 file
-
Where to configure tftp-server
# 1.查找 pxelinux.0文件是那个包提供的 [root@Server~]# yum provides "*/pxelinux.0" Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile 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 # 2.安装syslinux包,然候拷贝pxelinux.0文件到 tftp-server目录 [root@Server~]# yum -y install syslinux [root@Server~]# rpm -ql syslinux|grep pxe /usr/share/doc/syslinux-4.05/pxelinux.txt /usr/share/syslinux/gpxecmd.c32 /usr/share/syslinux/gpxelinux.0 /usr/share/syslinux/gpxelinuxk.0 /usr/share/syslinux/pxechain.com /usr/share/syslinux/pxelinux.0 [root@Server~]# # 3. 拷贝pxelinux.0 文件到 tftp-server 目录 [root@Server~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ [root@Server/var/lib/tftpboot]# ls pxelinux.0 # 4.创建一个目录,用来放启动配置文件 default的 [root@Server/var/lib/tftpboot]# mkdir pxelinux.cfg [root@Server/var/lib/tftpboot]# ls pxelinux.cfg pxelinux.0 [root@Server/var/lib/tftpboot]# cd pxelinux.cfg [root@Server/var/lib/tftpboot/pxe.cfg]# pwd /var/lib/tftpboot/pxelinux.cfg # 5.将 /mnt/isolinux/目录下面的所有文件都考到 /var/lib/tftpboot下面 [root@Server/var/lib/tftpboot]# cd -- [root@Server~]# cd /mnt/isolinux/ [root@Server/mnt/isolinux]# cp -a isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default [root@Server/mnt/isolinux]#cp * /var/lib/tftpboot/
-
verify
1.客户端启动系统,选择从网卡启动
2.就会从DHCP服务器(10.0.0.81)中获取IP地址,同时还获取了 tftp-server IP(10.0.0.81)地址和网络引导程序(pxelinux.0)
3.通过网卡读取到tftp-server(/var/lib/tftpboot目录)上的pxelinux.0,读取到内存中
4.在内存中执行引导程序
5.读取引导程序的配置文件(/var/lib/tftpboot/pxe.cfg/default)
3.4 Write kickstart.cfg configuration file
3.4.1 Install system-config-kickstart
-
install system-config-kickstart
[root@Server/etc/yum.repos.d]# cd -- # 1. 安装system-config-kickstart [root@Server~]# yum -y install system-config-kickstart 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile …… #2. 启动界面,配置ks.cfg [root@Server~]# system-config-kickstart 详解界面如下:
3.4.2 system-config-kickstart interface configuration
-
Basic configuration (default language, keyboard, time zone, password, reboot after installation)
-
Installation method (fresh installation, HTTP installation method)
-
Install a new boot loader
-
Partition information
-
Network Configuration
-
Firewall configuration
-
Display configuration (whether to install a graphical interface)
-
Package installation options
-
post-install script
-
keep
3.5 Configure HTTP mirror source
3.5.1 Install http
-
install httpd
# 1. 安装httpd [root@Server ~]# yum -y install httpd 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile …… # 2.设置开启自动、启动服务 [root@Server ~]# systemctl enable httpd [root@Server ~]# systemctl start httpd #3. 创建 目录 [root@Server ~]# cd /var/www/html [root@Server/var/www/html]# mkdir ks.cfg [root@Server/var/www/html]# mkdir pub # 4.修改yum 源,将本地改为http [root@Server/var/www/html]# cd [root@Server~]# cat /etc/yum.repos.d/dvd.repo [development] name=rhce7 baseurl=http://10.0.0.100/pub enabled=1 gpgcheck=0 [root@Server~]#
3.5.2 Hang the iso image file on the setting to start automatically at boot
-
set iso to start automatically
# 1. 在末尾添加以下一条信息。 [root@Server~]# vim /etc/fstab /dev/cdrom /var/www/html/pub iso9660 defaults,loop 0 0 [root@Server~]# tail -1 /etc/fstab /dev/cdrom /var/www/html/pub iso9660 defaults,loop 0 0 [root@Server~]# # 2.挂载镜像 [root@Server~]# mount -a # 3.用火狐浏览器访问下,如果可以访问,则说明http 镜像源没有问题 [root@Server~]# firefox http://10.0.0.100/pub & @ 7版本上,模式可以识别loop,defaults,loop 后面的loop可以省略
3.6 Configure boot menu default
3.6.1 Move ks6.cfg to /var/www/html/ks
-
move ks6.cfg
# 1.将我们保存在root目录中的cfg移动到 /var/www/html/ks.cfg/ [root@Server~]# mv ks6.cfg /var/www/html/ks.cfg/ [root@Server/var/www/html/ks.cfg]# ls ks6.cfg [root@Server/var/www/html/ks.cfg]#
3.6.2 Configure boot menu
-
Writing defautl files
[root@Server~]# cd /var/lib/tftpboot/pxelinux.cfg/ [root@Server/var/lib/tftpboot/pxelinux.cfg]# ls default # 1.编写default文件,此时在原本的label linux 添加以下内容, # 并删除label check里面的 menu defalut(默认启动方式,设置了,就不需要选择,默认启动选项) [root@Server/var/lib/tftpboot/pxelinux.cfg]# vim default label rhce7 menu label ^Install rhce7 menu default kernel vmlinuz append initrd=initrd.img ks=http://10.0.0.100/ks.cfg/ks6.cfg # 2.可以修改下默认的时间,默认是 600(单位是600秒的十分之一,就是60s) # 这里我设置60,就是6s timeout 60 ------------------- 参数介绍 efault vesamenu.c32 # 这是必须项,或者使用menu.c32 timeout 60 # 超时等待时间,60秒内不操作将自动选择默认的菜单来加载 display boot.msg # 这是为选项提供一些说明的文件 # Clear the screen when exiting the menu, instead of leaving the menu displayed. # For vesamenu, this means the graphical background is still displayed without # the menu itself for as long as the screen remains in graphics mode. menu clear menu background splash.png # 背景图片 menu title CentOS 7 # 大标题 menu vshift 8 …… label linux menu label ^Install CentOS 7 # 菜单文字 kernel vmlinuz # 内核文件路径,注意相对路径是从tftp的根路径/tftpboot开始的 append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet # 内核启动选项,其中包括initrd的路径,同样要改为"ks=http://10.0.0.100/ks.cfg/ks6.cfg" menu default # menu default表示开机时光标一开始默认停留在此label上 # 一般pxe环境下此路径直接指向系统安装文件的路径,具体做法见下文示例 # utilities submenu # 子菜单项的设置方法 menu begin ^Troubleshooting menu title Troubleshooting
3.6.3 Set the client to network startup (raid, etc.), and start it
4. Summary
The so-called unattended is an automatic answer. When the human-computer interaction is required to provide answers to certain options during the installation process (such as how to partition), the automatic answer file can automatically provide answers according to the corresponding items. However, unattended is not completely unattended. At least it is necessary to set the bios to boot from the network card, and it is also necessary to set the boot from the network card after the system is installed. In addition, other basically can achieve unattended installation.
During deployment, it is recommended to use Kickstart+DHCP+HTTP(FTP)+TFTP to install dhcp, tftp-server, xinetd, httpd, system-config-kickstart and other software.
In a real environment, we usually find a server with several hard disks. After the raid is completed, the entire hard disk has a waiting time of 10T. If we use kickstart to automatically install and partition it; generally, the server hard disk exceeds 2T. How to use kickstart to install and configure? ? Here you cannot use the MBR method to partition, you need to use the GPT format to boot and partition. You need to add the following commands at the end of ks.cfg to achieve the requirements:
%pre
parted -s /dev/sdb mklabel gpt
%end