PXE high-efficiency batch network installation and unattended cooperation with Kickstart

One, PXE

(I. Overview

PXE (Pre-Boot Execution Environment) is a network boot technology developed by Inter company. It works in Client/Server mode, allowing clients to download boot images from remote servers via the network, and load installation files or the entire operating system

(2) Advantages of PXE

Large-scale: Assemble multiple servers at the same time. Automation: Install the system and configure various services. Remote realization: No CD, U disk and other installation media are required

(3) Conditions for building PXE services

The client's network card must support the PXE protocol (integrated BOOTROM chip), and the motherboard supports network boot. Generally, most servers support it. You only need to allow booting from Network or LAN in the BIOS settings. There is a DHCP server in the network to automatically assign addresses to clients and specify the location of the boot file. The server shall provide the download of the boot image file through the TFTP service (Simple File Transfer Protocol)

(4) Build a PXE remote installation server

The PXE remote installation server integrates CentOS7 installation source, TFTP service, DHCP service, and can send PXE boot program, Linux kernel, boot menu and other data to the client bare metal, as well as provide installation files.
Insert picture description here

1. Install and start the TFTP service

TFTP(Simple File Transfer Protocol) is a protocol for simple file transfer between client and server based on UDP protocol, suitable for small file transfer applications. TFTP service is managed by xinetd service by default, using UDP port 69
xinetdIt is a new generation of network daemon service program, also called super server, commonly used to manage a variety of lightweight Internet services

yum -y install tftp-server xinetd            //安装并启用 TFTP 服务
vim /etc/xinetd.d/tftp                       //修改TFTP服务的配置文件
protocol            = udp		             //TFTP默认使用UDP协议	  
wait                = no		             //no表示客户机可以多台一起连接,yes表示客户机只能一台一台连接
server_args         = -s /var/lib/tftpboot	     //指定TFTP根目录(引导文件的存储路径)
disable             = no		             //no表示开启TFTP服务 
systemctl start tftp                         //开启ftp服务
systemctl enable tftp                        //开启ftp服务开机自启
systemctl start xinetd                       //开启xinetd服务
systemctl enable xinetd                      //开启xinetd服务开机自启

Insert picture description here
Insert picture description here
Insert picture description here

2. Install and enable DHCP service

DHCP (Dynamic Host Configuration Protocol, dynamic host configuration protocol) is a network protocol for local area network, using UDP protocol to work

yum -y install dhcp                          //安装dhcp软件包
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.        //将dhcp配置模板复制到dhcp配置文件中
cp:是否覆盖"/etc/dhcp/dhcpd.conf"?                                       //yes 
vim /etc/dhcp/dhcpd.conf    					//修改DHCP服务的配置文件
ddns-update-style none;					        //禁用 DNS 动态更新
next-server 192.168.71.20; 					//指定 TFTP 服务器的地址
filename "pxelinux.0";						//指定要下载的 PXE 引导程序的文件
 
 subnet 192.168.71.0 netmask 255.255.255.0 {
    
    	                //声明要分配的网段地址
 range 192.168.71.50 192.168.71.150;			        //设置地址池
 option routers 192.168.71.20;                                //默认网关地址指向TFTP服务器的IP地址
} 

systemctl start dhcpd                                           //开启dhcp服务 
systemctl enable dhcpd                                          //开启dhcp服务开机自启 

Insert picture description here
Insert picture description here
Insert picture description here

3. Prepare the Linux kernel and initialize the image file

mount /dev/sr0 /mnt
cd /mnt/images/pxeboot      
cp vmlinuz /var/lib/tftpboot/    //复制 Linux系统的内核文件 到TFTP根目录下
cp initrd.img /var/lib/tftpboot/       //复制 初始化镜像文件(linux引导加载模块)到TFTP根目录下

Insert picture description here

4. Prepare the PXE boot program

yum -y install syslinux         //PXE引导程序由软件包 syslinux 提供
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot   //复制 PXE引导程序 到TFTP根

Insert picture description here
Insert picture description here

5. Install FTP service, prepare CentOS 7 installation source

yum -y install vsftpd               //安装vsftpd服务
mkdir /var/ftp/centos7              //在ftp根目录下创建目录centos7
cp -rf /mnt/* /var/ftp/centos7/     //将镜像文件强制复制到centos7目录中,可加&让它自己后台运行
或者 mount /dev/sr0 /var/ftp/centos7  //或者直接将光盘文件挂载在目录下使用
systemctl start vsftpd              //开启vsftpd服务
systemctl enable vsftpd             //开启vsftpd服务开机自启

Insert picture description here
Insert picture description here
Insert picture description here

6. Configure the boot menu file

The default boot menu file is in the pxelinux.cfg subdirectory of the TFTP root directory, and the file name is default

mkdir /var/lib/tftpboot/pxelinux.cfg		  
vim /var/lib/tftpboot/pxelinux.cfg/default	

default auto 		//指定默认入口名称
prompt 1 	        //设置是否等待用户选择,“1”表示等待用户控

label auto		//图形安装(默认)引导入口,label 用来定义启动项
kernel vmlinuz		//kernel 和 append用来定义引导参数
append initrd=initrd.img method=ftp://192.168.71.20/centos7 

label linux text	//文本安装引导入口
kernel vmlinuz
append text initrd=initrd.img method=ftp://192.168.71.20/centos7

label linux rescue	//救援模式引导入口
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://192.168.71.20/centos7

systemctl stop firewalld.service        //关闭系统防火墙
setenforce 0                            //关闭系统安全机制

Insert picture description here
Insert picture description here
Insert picture description here

Note: Use the virtual machine created by VMware to test, the virtual machine memory needs to be at least 2GB, otherwise an error may be reported when the installation is started
Turn on the virtual machine, press Enter directly after the prompt string "boot:" (or execute the "auto" command), the installation file will be automatically downloaded through the network, and enter the default graphical installation entry; if you execute the "linux text" command , Enter the text installation entrance; if you execute the "linux rescue" command, enter the rescue mode.
Insert picture description here
Insert picture description here

2. Realize Kickstart unattended installation (using desktop environment)

1. Prepare to install the answer file

 yum install -y system-config-kickstart       //安装system-config-kickstart 工具

2. Open the "Kickstart Configuration Program" window

通过桌面菜单“应用程序”-->“系统工具”-->“Kickstart” 打开
或
执行 “system-config-kickstart” 命令打开

3. Configure kickstart options

3.1 Basic configuration
The default language is set to "Chinese (Simplified)" and the
time zone is set to "Asia/Shanghai".
Set the root password. In the
advanced configuration, check "Restart after installation"

Insert picture description here

==3.2 Installation method==
Choose FTP
FTP server
: ftp://192.168.80.10 FTP directory: centos7

Insert picture description here

==3.3. Boot loader option==
"Installation type": install a new boot loader
"install option": install the boot loader in the master boot record (MBR)

Insert picture description here
3.4. Partition information
Master Boot Record: Clear Master Boot Record
Partition: Delete all existing partitions
Disk Label: Initialize Disk Label
Layout: Add Partition
Mount Point: /boot, File System Type: xfs, Fixed Size: 500M
File System Type: swap, Fixed Size: 4096M
mount point: /, file system type: xfs, use all unused space on the disk
Insert picture description here
Insert picture description here

Insert picture description here
3.5. Network configuration:
Add network device "ens33"
network type is set to "DHCP"

Insert picture description here
3.6. Firewall configuration:
Disable SELinux, disable firewall

Insert picture description here
3.7. Post-installation script:
Check "Use interpreter": /bin/bash

rm -rf /etc/yum.repos.d/*
echo '[local]
name=local
baseurl=ftp://192.168.80.10/centos7
enabled=1
gpgcheck=0' > /etc/yum.repos.d/local.repo

Insert picture description here
==3.8. Save auto answer file==

Select the "File" -> "Save" command in the "Kickstart Configuration Program" window and select the specified save location. The file name is ks.cfg and
is saved in /root/ks.cfg by default (other directories can be selected)
Insert picture description here

4. Configure the software packages that need to be installed

You can copy the package installation script of /root/anaconda-ks.cfg to the ks.cfg file according
to your needs , just copy the %packages to the %end part.

If you require minimal installation, you can copy the following:

vim ks.cfg
%packages
@^minimal
%end

Insert picture description here

Insert picture description here

5. Copy /root/ks.cfg to the /var/ftp directory

The boot boot reads the content in /var/ftp, not /root. /root is only the temporarily saved counterpart, so copy it directly and add the content copied in /root/anaconda-ks.cfg

cp /root/ks.cfg /var/ftp/ks.cfg

vim /var/ftp/ks.cfg

Insert picture description here
Insert picture description here

6. Edit the boot menu file default and add ks boot parameters

vim /var/lib/tftpboot/pxelinux.cfg/default
default auto 							
prompt 0 	//设置是否等待用户选择,“0”表示不等待用户控制

label auto								
kernel vmlinuz    //kernel 和 append用来定义引导参数
append initrd=initrd.img method=ftp://192.168.71.20/centos7 ks=ftp://192.168.71.20/ks.cfg  //添加 ks 引导参数以指定 ks.cfg 应答文件的 URL 路径

Insert picture description here

When the client computer boots in PXE mode every time, it will automatically download the ks.cfg response configuration file, and then install the CentOS 7 system according to the settings in it, without manual selection

7. Create a new virtual machine to verify the results

Each option will be automatically selected and at the end just manually accept the verification terms.
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_53567573/article/details/114120867