简介

PXE是基于 server/client 模式的技术,让客户端从远程服务器下载启动镜像,从而实现网络启动。客户端要求服务器通过 DHCP 分配 IP 地址,再通过 TFTP 下载启动镜像。

Kickstart 将安装过程中需要手动设置的参数保存为应答文件,通过读取应答文件实现无人值守安装。

安装源可以通过 FTP,NFS,HTTP 等提供。

服务器配置

实验环境

  • 操作平台:VMWare Workstation 15.2
  • 网络模式:仅主机,关闭 DHCP
  • 服务端系统:Centos 7.6
  • 客户端为空白虚拟机,仅主机模式,Bios 设置 PXE 启动

配置主机名和 IP 地址

[root@localhost ~]# hostnamectl set-hostname kickstart.example.com
[root@kickstart ~]# nmcli con add con-name static type ethernet ifname ens32 ip4  172.25.254.254/24
[root@kickstart ~]# nmcli con up static

安装所需软件

[root@kickstart ~]# yum -y install dhcp tftp-server vsftpd syslinux

关闭防火墙和 selinux

[root@kickstart ~]# systemctl stop firewalld
[root@kickstart ~]# systemctl disable firewalld
[root@kickstart ~]# setenforce 0
[root@kickstart ~]# vim /etc/selinux/config
SELINUX=permissive

DHCP 配置

[root@kickstart ~]# vim /etc/dhcp/dhcpd.conf
log-facility local7;
subnet 172.25.254.0 netmask 255.255.255.0 {
range 172.25.254.1 172.25.254.250;
option domain-name-servers kickstart.example.com;
option routers 172.25.254.254;
default-lease-time 600;
max-lease-time 7200;
next-server 172.25.254.254;
filename "pxelinux.0";
}
[root@kickstart ~]# systemctl restart dhcpd
[root@kickstart ~]# systemctl enable dhcpd

TFTP 配置

[root@kickstart ~]# vim /etc/xinetd.d/tftp
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}
[root@kickstart ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@kickstart ~]# mount /dev/sr0
[root@kickstart ~]# mount /dev/sr0 /var/ftp/pub/
[root@kickstart ~]# cp /var/ftp/pub/isolinux/* /var/lib/tftpboot/
[root@kickstart ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@kickstart ~]# cp /var/ftp/pub/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@kickstart ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
label linux
  menu label ^Install CentOS 7
  kernel vmlinuz
  append initrd=initrd.img inst.ks=ftp://172.25.254.254/ks.cfg ip=dhcp quiet
label check
[root@kickstart ~]# chmod 644 /var/lib/tftpboot/pxelinux.cfg/default
[root@kickstart ~]# systemctl restart tftp
[root@kickstart ~]# systemctl enable tftp

FTP 配置

[root@kickstart ~]# vim /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=NO
listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
[root@kickstart ~]# systemctl restart vsftpd
[root@kickstart ~]# systemctl enable vsftpd

Kickstart 应答文件

# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
# SELinux configuration
selinux --enforcing
# Do not configure the X Window System
skipx

# Firewall configuration
firewall --disabled
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --fstype="xfs" --ondisk=sda --size=10000

%packages
@^minimal
@core
chrony
kexec-tools
%end

测试安装服务器

新建空白虚拟机,网络模式为仅主机,Bios 设置 PXE 启动,测试安装服务器是否正常工作。