Linux PXE batch network installation and Kickstart unattended installation

1. PXE batch network installation

PXE (pre-boot execution environment, running before the operating system) is a network boot technology developed by Intel. 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 .

Two, the three advantages of PXE

  • Scale: install multiple servers at the same time;
  • Automation: install the system, configure various services;
  • Remote realization: no CD, U disk and other installation media are required.

3. Prerequisites for building PXE

Client:

  • The client's network card must support the PXE protocol (integrated BOOTROM chip), and the motherboard supports network boot. Some need to allow booting from Network or LAN in the BIOS settings.

Server:

  • There is a posture DHCP server on the network while the client automatically assigns addresses and specifies the location of the boot file.
  • The server must be used to download the system kernel and boot image files through the TFTP service (Trivial File Transfer Protocol).

Service explanation

  • The PXE remote installation server integrates CentoS 7 installation source, TFTP service, DHCP service, FTP service, and can send PXE boot program, Linmux kernel, boot menu and other data to the client bare metal, as well as provide installation files.
  • TFTP (Trivial File Transfer Protocol) is a UDP-based protocol for simple file transfer between client and server, suitable for small file transfer applications. TFTP service is managed by xinetd service by default, using UDP port 69
  • xinetd is a new generation of network daemon service program, also called super server, commonly used to manage a variety of lightweight Internet services.

Fourth, configure PXE installed server

1. Install and enable TFTP service

yum -y install tftp-server xinetd

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

systemctl start tftp
systemctl enable tftp
systemctl start xinetd
systemctl enable xinetd

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

2. Install and enable DHCP service

yum -y install dhcp
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

#修改DHCP服务的配置文件
vim /etc/dhcp/dhcpd.conf
ddns-update-style none;		   #禁用 DNS 动态更新
next-server 192.172.168.10;	   #指定 TFTP 服务器的地址
filename "pxelinux.0";		   #指定要下载的 PXE 引导程序的文件

subnet 192.168.172.0 netmask 255.255.255.0 {
    
        #声明要分配的网段地址
  range 192.168.172.100 192.168.172.200;	    #设置地址池
  option routers 192.168.172.10;				    #默认网关地址指向TFTP服务器的IP地址
}

systemctl start dhcpd
systemctl enable dhcpd

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
mkdir /var/ftp/centos7
cp -rf /mnt/* /var/ftp/centos7/

systemctl start vsftpd
systemctl enable vsftpd

Insert picture description here
Insert picture description here

6. Configure the boot menu file

默认的启动菜单文件在TFTP根目录的 pxelinux.cfg子目录下,文件名为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.172.10/centos7

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

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

Insert picture description here

7. Turn off the firewall

systemctl stop firewalld.service 
setenforce 0

Insert picture description here

8. Verification

Use a virtual machine created by VMware for testing. The memory of the virtual machine must 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 via the network and enter the default graphical installation portal;
  • If you execute the "linux text" command, enter the text installation entry
  • If you execute the "linux rescue" command, enter the rescue mode
    Insert picture description here

Insert picture description here
The configuration is completed and the installation is successful. In order to solve the problem that PXE needs to be manually set after installation, we will use it here.Kickstart unattended installation

Five, Kickstart unattended installation

1. Install the system-config-kickstart tool

yum install -y system-config-kickstart       

Insert picture description here

2. Open the "Kickstart Configuration Program" window

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

Insert picture description here

3. Configure kickstart options

basic configuration

默认语言设为“中文(简体)”
时区设为“Asia/Shanghai”
设置root密码
高级配置中勾选“安装后重启”。

Insert picture description here

installation method

FTP
FTP服务器:ftp://192.168.172.10
FTP目录:centos7

Insert picture description here

Bootloader options

“安装类型”:安装新引导装载程序
“安装选项”:在主引导记录(MBR)中安装引导装载程序

Insert picture description here

Partition information

主引导记录:清除主引导记录
分区:删除所有现存分区
磁盘标签:初始化磁盘标签
布局:添加分区
挂载点:/boot,文件系统类型:xfs,固定大小:500M
文件系统类型:swap,固定大小:4096M
挂载点:/home,文件系统类型:xfs,固定大小:4096M
挂载点:/,文件系统类型:xfs,使用磁盘上全部未使用空间

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

Network Configuration

添加网络设备“ens33”
网络类型设为“DHCP

Insert picture description here

Firewall configuration

禁用 SELinux、禁用防火墙

Insert picture description here

Post-install script

勾选“使用解释程序”:/bin/bash
mkdir /etc/yum.repos.d/repo.bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo.bak
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

4. Save the auto answer file

选择“Kickstart 配置程序”窗口的“文件”-->“保存”命令,选择指定保存位置,文件名为ks.cfg
默认保存在/root/ks.cfg

Insert picture description here
Insert picture description here

5. Configure the software packages that need to be installed

可以根据需要将/root/anaconda-ks.cfg 的软件包安装脚本复制到 ks.cfg文件中,只需要复制%packages 到%end 部分即可。
如要求最小化安装,可复制下面内容:
vim ks.cfg
%packages
@^minimal
%end

cp /root/ks.cfg /var/ftp/ks.cfg
将/root/anaconda-ks.cfg 的软件包安装脚本复制到/var/ftp/ks.cfg以实现桌面安装

Insert picture description here
Insert picture description here
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.80.10/centos7 ks=ftp://192.168.80.10/ks.cfg  #添加 ks 引导参数以指定 ks.cfg 应答文件的 URL 路径

Insert picture description here

7. Verify unattended installation

We use the virtual machine created in the previous experiment to install.
Insert picture description here
You can see that they are all set up by themselves.
Insert picture description here
Insert picture description here
Insert picture description here
Log in to the root user and check whether the yum source script we set is executed successfully. The
Insert picture description here
experiment is complete.

Guess you like

Origin blog.csdn.net/IHBOS/article/details/114106305