PXE-batch automatic installation

PXE batch deployment has the following three advantages:

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

PXE 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. To build a PXE network system, the following prerequisites must be met.

  • The client's network card supports the PXE protocol (integrated BOOTROM chip), and the motherboard supports network boot.
  • There is a DHCP server in the network to automatically assign addresses to clients and specify the location of the boot file.
  • The server provides the download of the boot image file through TFTP (Trivial File Transfer Protocol).

Basic deployment process

  1. Prepare CentOS7 installation source
  2. Install and enable TFTP and FTP services
  3. Provide Linux kernel, PXE boot program, etc.
  4. Install and enable DHCP service
  5. Configure boot menu

Planning:
a Linux system to build a service------------- 20.0.0.15

A Linux system for PXE test-------------DHCP acquisition

Software version: Centos 7.6

The following are the complete steps to start the installation:

Build the service first

vi /etc/sysconfig/network-scripts/ifcfg-ens33 
BOOTPROTO=static
.......
ONBOOT=yes
IPADDR=20.0.0.15
NETMASK=255.255.255.0
GATEWAY=20.0.0.2
DNS1=8.8.8.8
DNS2=114.114.114.114 

 systemctl restart network				##重启网卡
  vi /etc/selinux/config					##关闭核心防火墙
  ......
  SELINUX=disabled
  ......
  systemctl stop firewalld				##关闭防火墙
  systemctl disable firewalld			##开机自动关闭防火墙  
  最小化

Installation needs to compile and install yum
yum list ---------Check whether there is yum installation

1. Prepare CentOS7 installation source

[root@localhost ~]# mkdir -p /var/ftp/centos7
[root@localhost ~]# mount /dev/cdrom /mnt
[root@localhost ~]# cp -rf /mnt/* /var/ftp/centos7

[root@localhost ~]# yum -y install vsftpd
[root@localhost ~]# systemctl start vsftpd
[root@localhost ~]# systemctl enable vsftpd

2. Install and enable TFTP and FTP services

[root@localhost ~]# yum -y install tftp-server
[root@localhost ~]# vi /etc/xinetd.d/tftp
service tftp
{
......
protocol = udp                             ###TFTP 采用 UDP 传输协议
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot             ###指定 TFTP 根目录
disable = no
......
}
[root@localhost ~]# systemctl start tftp
[root@localhost ~]# systemctl enable tftp

3. Provide Linux kernel, PXE boot program, etc.

[root@localhost ~]#   cd /mnt/images/pxeboot/          ####切换到挂载目录/mntimages/pxeboot/   
[root@localhost pxeboot]# cp vmlinuz initrd.img /var/lib/tftpboot/  ###两个文件并将其复制到 tftp 服务的根目录下[root@localhost ~]# yum -y install syslinux
[root@localhost pxeboot]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

4. Install and enable DHCP service

[root@localhost ~]# yum -y install dhcp
[root@localhost ~]# vi /etc/dhcp/dhcpd.conf
......
subnet 20.0.0.0 netmask 255.255.255.0 {
option routers 20.0.0.15;
option subnet-mask 255.255.255.0;
option domain-name "bdqn.com";
option domain-name-servers 20.0.0.254,202.106.0.20;
default-lease-time 21600;
max-lease-time 43200;
range 20.0.0.100 20.0.0.200;
next-server 20.0.0.15;				#####指定 TFTP 服务器的地址
filename "pxelinux.0";				####指定 PXE 引导程序的文件名
}

 [root@localhost ~]# systemctl start dhcpd
 [root@localhost ~]# systemctl enable dhcpd
 Created symlink from
 /etc/systemd/system/multi-user.target.wants/dhcpd.service to
 /usr/lib/systemd/system/dhcpd.service.

5. Configure the boot menu

[root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@localhost ~]# vi /var/lib/tftpboot/pxelinux.cfg/default
default auto
prompt 1
label auto
	kernel vmlinuz	
	append initrd=initrd.img method=ftp://20.0.0.15/centos7
label linux text
	kernel vmlinuz
	append text initrd=initrd.img method=ftp://20.0.0.15/centos7
label linux rescue
	kernel vmlinuz
	append rescue initrd=initrd.img method=ftp://20.0.0.15/centos7

Three boot entries are defined in the above configuration record, namely graphical installation (default), text installation, and rescue mode. Among them, prompt is used to set whether to wait for user selection; label is used to define and separate startup items; kernel and append are used to define boot parameters. The number and content of the guide entrances are defined by themselves. For example, only one entrance is required for unattended installation.

Implement Kickstart unattended installation

[root@localhost ~]# yum -y install  system-config-kickstart

########Basic configuration##########
Basic configuration:

  • Default language: Chinese (PR of China)-Chinese (Simplified)
  • Keyboard: US English
  • Time zone: Asia/Shanghai
  • Root password: Abc123
  • Default password: Abc123
  • Check √: Encrypt the root password

Advanced configuration:

  • Target architecture: X86, AMD64, or IntelEm64T
  • Check √: restart after installation
  • Uncheck: install in text mode (default is graphical mode)

########Installation method##########
Installation method:

  • Check √: perform a clean installation
    Installation method:
  • Check √: FTP
  • FTP server: ftp://20.0.0.254
  • FTP directory: centos

########Boot Loader Options######
Installation Type:

  • Check √: install new boot loader

########Partition Information##########
In the "Partition Information" interface, you need to plan the hard disk partition scheme correctly. For example, you can divide a 500MB /boot partition, 4GB /home partition, 2GB swap partition, and divide the remaining space into the root partition
/boot -----xfs-----is-----500
/ home-----xfs-----Yes-----4096
swap-----swap-----Yes-----2048
/-----xfs----- Yes ----- all remaining memory

###Other information###
If there is no special requirement, just keep the default settings in the "Verify" interface and "Display Configuration" interface.

####After installing the script####
Check √: Use the interpreter: /bin/bash
Type your %post script below:

  rm -rf /etc/yum.repos.d/*
  echo -e'[base]\nname=CentOS7.6\nbaseurl=ftp://20.0.0.15/centos7\nenabled=1\ngpgcheck=1\ngpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7'>/etc/yum.repos.d/centos7.repo

####Save auto answer file####
[root@localhost ~]# vi /ks.cfg

Cut to the bottom and add:

%packages
@^minimal
%end

####Realize batch automatic installation####

Once you have the answer file for automatic installation, just place it in the FTP directory of the PXE installation server and modify the boot menu appropriately to realize batch automatic installation based on the network.

1. Enable the automatic answer file In the PXE remote installation server, copy the answer file created in the previous section to the /var/ftp/centos7 directory, so that the client can use ftp://20.0.0.254/centos7/ks.cfg Access; then edit the boot menu file default and add the ks boot parameter to specify the URL path of the ks.cfg answer file.

[root@localhost ~]# cp /root/ks.cfg /var/ftp/ks.cfg
[root@localhost ~]# vi /var/lib/tftpboot/pxelinux.cfg/default
default auto
prompt 0
label auto        
	kernel vmlinuz
        append initrd=initrd.img method=ftp://20.0.0.15/centos7 ks=ftp://20.0.0.15/ks.cfg

Guess you like

Origin blog.csdn.net/weixin_48190875/article/details/107822484