PXE high-efficiency batch network installation and kickstart unattended technology

Advantages of PXE batch deployment

  • 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(Preboot eXcution Environment)

  • Pre-boot execution environment, run before the operating system

Server

  • Run the DHCP service to allocate addresses and locate the boot program
  • Run TFTP service, provide boot program download

Client

  • Network card supports PXE protocol
  • Motherboard supports network boot

Basic deployment process

  1. Prepare CentOS 7 installation source (YUM warehouse)
  2. Install and enable TFTP service
  3. Provide Linux kernel, PXE boot program, etc.
  4. Install and enable DHCP service
  5. Configure boot menu

Prepare CentOS 7 installation source

  • CentOS 7 installation source supports HTTP, FTP, NFS and other protocol releases
[root@localhost ~]# yum -y install vsftpd
[root@localhost ~]# mkdir /var/ftp/centos7
[root@localhost ~]# cp -rf /media/cdrom/*  /var/ftp/centos7/
[root@localhost ~]# systemctl start vsftpd

Install and enable TFTP service

  • Install the tftp-server software package and enable the tftp service
  • The configuration file is located at /etc/xinetd.d/tftp
[root@localhost ~]# yum -y install tftp-server
[root@localhost ~]# vi /etc/xinetd.d/tftp
 server_args      =-s /var/lib/tftpboot
 disable          =no //修改配置值
[root@localhost ~]# systemctl start tftp
[root@localhost ~]# systemctl enable tftp

Prepare Linux kernel and PXE boot program

  • The Linux kernel and initialization image files are vmlinuz and initrd.img respectively
  • The boot program is pxelinux.0, provided by the software package syslinux
[root@localhost ~]# cd /media/cdrom/images/pxeboot //位于系统镜像文件夹 inages/pxeboot下
[root@localhost pxeboot]# cp vmlinuz initrd.img /var/lib/tftpboot
[root@localhost ~]# yum -y install syslinux
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot  //拷贝到tftp的根目录

PXE settings for DHCP service

[root@localhost ~]# yum -y install dhcp
[root@localhost ~]# vi /etc/dhcp/dhcp.conf
subnet 192.168.4.0 netmask 255.255.255.0 {
    
    
  ......
  option routers 192.168.4.254;
  option domain-name-server 192.168.4.254, 202.106.0.20;
  range 192.168.4.254; //next-server:指定TFTP服务器地址
  filename “pxelinux.0//filename:指定要下载的引导程序文件
}
[root@localhost ~]# systemctl start dhcpd
[root@localhost ~]# systemctl enable dhcpd

Configure the boot menu file

[root@localhost ~]# vi /var/lib/tftpboot/pxelinux.cfg/default  //确保pexlinux.cfg目录已存在
default auto
prompt 1
label auto
  kernel vmlinuz
  append initrd=initrd.img method=ftp://192.168.4.254 /centos7
label linux text //文本模式安装
  kernel vmlinuz
  append text initrd=initrd.img method=ftp://192.168.4.254 /centos7
label linux rescue  //进入救援模式
  kernel vmlinuz
  append rescue initrd=initrd.img method=ftp://192.168.4.254 /centos7

Verify PXE network installation

  • Adjust the BIOS settings to boot from the network
  • Obtain an IP address automatically and specify the CentOS 7 installation source
  • The rest of the process is the same as the local installation
    Insert picture description here

Kickstart unattended technology

  • Create an answer file and define various installation settings in advance
  • Eliminate the need for interactive setup process, thus achieving fully automated installation

The source of the answer file

  • Edit the existing answer file in the CentOS 7 system-
     /root/anaconda-ks.cfg
  • Use the system-config-kickstart tool to create a new answer file
     -the system-config-kickstart package needs to be installed

The content of the answer file

......
url--url=“ftp://192.168.4.254/centos7"
......
%post--interpreter=/bin/bash
rm -f /etc/yum.repos.d/*
echo -e
'[base]Inname=CentOS7.3Inbaseurl=ftp://192.168.4.254/centos7\nenabled=1ngpgcheck=1Ingpgkey=file:/lletc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7'>/etc/yum.repos.d/centos7.repo
%end
%packages
@^minimal
%end

PXE combined with kickstart

[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://192.168.4.254/centos7
ks=ftp://192.168/4/254/ks/cfg //应答文件的URL地址

Verify automatic installation

  • Boot the client in PXE mode
  • The system will automatically complete the installation and configure the software warehouse
  • No manual intervention is required during the entire installation process
    Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_49343462/article/details/109437088
Recommended