1、安装 VSFTP 服务
[root@pxe ~]# systemctl stop firewalld
[root@pxe ~]# systemctl enable firewalld
[root@pxe ~]# yum -y install vsftp
2、挂载镜像文件
[root@pxe ~]# mount /dev/cdrom /media/
[root@pxe ~]# mkdir /var/ftp/centos7
[root@pxe ~]# cp -rf /media/* /var/ftp/centos7
[root@pxe ~]# systemctl start vsftpd
3、安装 TFTP 服务
[root@pxe ~]# yum -y install tftp-server
[root@pxe ~]# vim /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
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@pxe ~]# systemctl start tftp
[root@pxe ~]# cp /media/images/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/
4、准备 PXE 引导程序
[root@pxe ~]# yum -y install syslinux
[root@pxe ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
5、典型安装及无人值守安装菜单配置
[root@pxe ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
# 典型的启动菜单,无法实现无人值守安装
[root@pxe ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
default auto
prompt 1
label auto
kernel vmlinuz
append initrd=initrd.img method=ftp://192.168.2.16/centos7
label linux text
kernel vmlinuz
append text initrd=initrd.img method=ftp://192.168.2.16/centos7
label linux rescue
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://192.168.2.16/centos7
# 无人值守安装的启动菜单
[root@pxe ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
default auto
prompt 0
label auto
kernel vmlinuz
# append initrd=initrd.img method=http://192.168.2.16/download/centos7 ks=http://192.168.2.16/download/ftp-ks.cfg
append initrd=initrd.img method=ftp://192.168.2.16/centos7 ks=ftp://192.168.2.16/ftp-ks.cfg
6、安装 DHCP 服务
[root@pxe ~]# yum -y install dhcp
[root@pxe ~]# vim /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
#
subnet 192.168.2.0 netmask 255.255.255.0 { # 定义网段
range 192.168.2.17 192.168.2.20; # 分配地址池
# option domain-name-servers 192.168.1.10; DNS服务器地址
# option domain-name "yangshufan.com"; 域名
option routers 192.168.2.1; # 路由地址
option broadcast-address 192.168.2.255; # 广播地址
default-lease-time 600; # 默认租约时间
max-lease-time 7200; # 最大租约时间
next-server 192.168.2.16; # TFTP服务器IP地址
filename "pxelinux.0"; # PXE引导程序的文件名
}
[root@pxe ~]# systemctl start dhcpd
7、无人值守应答文件
[root@pxe ~]# vim /var/ftp/ks.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password -> wcznhz#2020
rootpw --iscrypted $1$P9O0DmfS$o4vv8BYCB250aLnRIdNps.
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
# SELinux configuration
selinux --disabled
# System services
services --enabled="chronyd"
# Do not configure the X Window System
skipx
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=ens192 --activate
# Halt after installation
reboot
# System timezone
timezone Asia/Shanghai --isUtc
# Use network installation
# url --url="http://192.168.2.6/download/centos7"
url --url="ftp://192.168.2.16/centos7"
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=350
part swap --fstype="swap" --size=3500
part / --fstype="xfs" --grow --size=1
# 安装后执行脚本
%post --interpreter=/bin/bash
# 设置静态IP
echo "IPADDR=`ip addr show ens192|grep inet|awk '{print $2}'|cut -d "/" -f 1`" >>/etc/sysconfig/network-scripts/ifcfg-ens192
echo "PREFIX=24" >>/etc/sysconfig/network-scripts/ifcfg-ens192
echo "GATEWAY=`ip route|grep default|awk '{print $3}'`" >>/etc/sysconfig/network-scripts/ifcfg-ens192
echo "DNS1=10.100.2.11" >>/etc/sysconfig/network-scripts/ifcfg-ens192
echo "DNS2=114.114.114.114" >>/etc/sysconfig/network-scripts/ifcfg-ens192
sed -i 's/dhcp/static/g' /etc/sysconfig/network-scripts/ifcfg-ens192
systemctl restart network
# 更换yum源
mkdir /etc/yum.repos.d/back
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/back
# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# curl -o /etc/yum.repos.d/CentOS-Base.repo http://192.168.2.16/download/CentOS-Base.repo
# curl -o /etc/yum.repos.d/CentOS-Base.repo http://192.168.2.16/download/epel.repo
# curl -o /root/aseit_optimize_fasten_linux http://192.168.2.16/download/aseit_optimize_fasten_linux
# curl -o /root/install_docker_rancher_k8s_kuboard-k8s1.17.5.sh http://192.168.2.16/download//install_docker_rancher_k8s_kuboard-k8s1.17.5.sh
curl -u anonymous:anonymous -o /etc/yum.repos.d/CentOS-Base.repo ftp://192.168.2.16/CentOS-Base.repo
curl -u anonymous:anonymous -o /etc/yum.repos.d/epel.repo ftp://192.168.2.16/epel.repo
# 固化
curl -u anonymous:anonymous -o /root/aseit_optimize_fasten_linux ftp://192.168.2.16/aseit_optimize_fasten_linux
curl -u anonymous:anonymous -o /root/install_docker_rancher_k8s_kuboard-k8s1.17.5.sh ftp://192.168.2.16/install_docker_rancher_k8s_kuboard-k8s1.17.5.sh
chmod +x /root/aseit_optimize_fasten_linux
chmod +x /root/install_docker_rancher_k8s_kuboard-k8s1.17.5.sh
%end
# 系统软件包
%packages
@^web-server-environment
@base
@compat-libraries
@core
@development
@hardware-monitoring
@java-platform
@large-systems
@load-balancer
@performance
@perl-web
@php
@python-web
@remote-system-management
@security-tools
@system-admin-tools
@web-server
@web-servlet
chrony
kexec-tools
%end
8、完成后目录如下
[root@pxe ~]# ll -h /var/lib/tftpboot/
total 60M
-rw-r--r--. 1 root root 53M Sep 1 19:16 initrd.img
-rw-r--r--. 1 root root 27K Sep 1 19:19 pxelinux.0
drwxr-xr-x. 2 root root 21 Sep 2 01:55 pxelinux.cfg
-rwxr-xr-x. 1 root root 6.5M Sep 1 19:16 vmlinuz
[root@pxe ~]# ll -h /var/ftp/
total 116K
-rwxr-xr-x. 1 root root 47K Sep 3 23:33 aseit_optimize_fasten_linux
drwxr-xr-x. 8 root root 220 Sep 3 23:28 centos7
-rw-r--r--. 1 root root 2.1K Sep 3 23:39 CentOS-Base.repo
-rw-r--r--. 1 root root 664 Sep 3 23:39 epel.repo
-rwxr-xr-x. 1 root root 56K Aug 19 11:45 install_docker_rancher_k8s_kuboard-k8s1.17.5.sh
-rw-r--r--. 1 root root 2.7K Sep 4 18:17 ks.cfg
drwxr-xr-x. 2 root root 6 Apr 1 12:55 pub