PXE batch installation and Kickstart unattended

PXE 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

Advantages of PXE batch deployment

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

Requirements for building a PXE network system

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 must provide the download of the boot image file through the TFTP service (Simple File Transfer Protocol).

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.

Install, modify and start the TFTP service
TFTP (Trivial File Transfer Protocol), a protocol for simple file transfer between client and server based on UDP protocol, is 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.

yum -y install tftp-server xinetd #Install and enable the TFTP service
Insert picture description here
vim /etc/xinetd.d/tftp #Modify the configuration file of the TFTP service
Insert picture description here

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

Install, modify and enable the DHCP service
DHCP (Dynamic Host Configuration Protocol, dynamic host configuration protocol) is a local area network network protocol, using the UDP protocol to work.

yum -y install dhcp #安装dhcp软件包

Insert picture description here
Insert picture description here

cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf #将dhcp配置模板复制到dhcp配置文件中
vim /etc/dhcp/dhcpd.conf #修改DHCP服务的配置文件

Insert picture description here

Insert picture description here
Insert picture description here

ddns-update-style none; #禁用 DNS 动态更新
next-server 192.168.78.11; #指定 TFTP 服务器的地址
filename “pxelinux.0”; #指定要下载的 PXE 引导程序的文件

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

Insert picture description here

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

Prepare the Linux kernel and initialize the image file

mount /dev/sr0 /mnt

Insert picture description here

cd /mnt/images/pxeboot

Insert picture description here

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

Insert picture description here
PXE bootloader preparation for installation

yum -y install syslinux #PXE引导程序由软件包 syslinux 提供

Insert picture description here
Insert picture description here

cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ #复制 PXE引导程序 到TFTP根目录下

Insert picture description here
Install FTP service, prepare CentOS 7 installation source

yum -y install vsftpd #安装vsftpd服务

Insert picture description here
Insert picture description here

mkdir /var/ftp/centos7 #在ftp根目录下创建目录centos7

Insert picture description here

cp -rf /mnt/* /var/ftp/centos7/ #将镜像文件强制复制到centos7目录中,可加&让它自己后台运行

Insert picture description here

systemctl start vsftpd #开启vsftpd服务
systemctl enable vsftpd #开启vsftpd服务开机自启

Insert picture description here
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

Insert picture description here

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

Insert picture description here

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

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

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

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

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

Insert picture description here

注意:使用 VMware创建的虚拟机进行测试,虚拟机内存至少需要 2GB,否则在启动安装时可能会报错。
开启虚拟机,在提示字符串“boot:”后直接按Enter键(或执行“auto”命令),将会自动通过网络下载安装文件,并进入默认的图形安装入口;
若执行“linux text”命令,则进入文本安装入口;若执行 “linux rescue”命令,则进入救援模式。

Insert picture description here

Kickstart unattended

Install the answer file

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

Insert picture description here
Open the "Kickstart Configuration Program" window

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

或直接执行 “system-config-kickstart” 命令打开

Insert picture description here
Configure kickstart options

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

Insert picture description here

安装方法
选FTP
FTP服务器:ftp://192.168.12.10
FTP目录:centos7

Insert picture description here

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

Insert picture description here

分区信息
主引导记录:清除主引导记录
分区:删除所有现存分区
磁盘标签:初始化磁盘标签
布局:添加分区
挂载点:/boot,文件系统类型:xfs,固定大小:500M
文件系统类型:swap,固定大小:4096M
挂载点:/home,文件系统类型:xfs,固定大小:4096M
挂载点:/,文件系统类型:xfs,使用磁盘上全部未使用空间
注意:各个分区分配大小自己设定,swap分区属于文件系统类型,其它的在挂载点中寻找

Insert picture description here
Insert picture description here

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

Insert picture description here

防火墙配置:
禁用 SELinux、禁用防火墙

Insert picture description here

安装后脚本:
勾选“使用解释程序”:/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.12.10/centos7
enabled=1
gpgcheck=0’ > /etc/yum.repos.d/local.repo

Insert picture description here

Save the auto answer file

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

Insert picture description here
Configure the packages that need to be installed

可以根据需要将/root/anaconda-ks.cfg 的软件包安装脚本复制到/root/ks.cfg文件中,只需要复制%packages 到%end 部分即可

Insert picture description here

Insert picture description here
Insert picture description here

如要求最小化安装,可复制下面内容:
注意:vim ks.cfg
%packages
@^minimal
%end

把/root/ks.cfg 复制到/var/ftp/目录中,开机引导读取的是/var/ftp内的内容

Insert picture description here

注意:将/root/anaconda-ks.cfg 的软件包安装脚本复制到/var/ftp/ks.cfg以实现桌面安装
注意:先后顺序,开机引导读取的是/var/ftp内的内容,不是/root,/root仅仅是暂时保存的对方,所以,修改完再复制过去,或者直接复制过去再修改。

Edit the boot menu file default, 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

当客户机每次以PXE方式引导时,将自动下载ks.cfg应答配置文件,然后根据其中的设置安装CentOS 7 系统,不需要手工干预

Insert picture description here

Guess you like

Origin blog.csdn.net/MQ107/article/details/114534482