PXE使用需要以下几点:
客户端的网卡必须要支持PXE功能,并且开机选择从网卡启动,进入PXE程序
PXE服务器必须要提供至少含有DHCP以及TFTP的服务!
DHCP服务提供客户端网络,并且告知TFTP所在的位置;
TFTP提供客户端boot loader及kernel file下载路径
PXE工作流程:
Client向PXE Server上的DHCP发送IP地址请求消息,返回Client的IP地址,同时将pxe环境下的Boot
loader文件pxelinux.0的位置信息传送给Client
Client向PXE Server上的TFTP请求pxelinux.0
Client执行接收到的pxelinux.0文件
Client向TFTP请求pxelinux.cfg文件(里面放置的是是启动菜单,即grub的配置文件)
Client向TFTP发送Linux内核请求信息
Client向TFTP发送根文件请求信息
Client加载Linux内核
Client通过nfs/ftp/http下载系统安装文件进行安装
Kickstart是一种无人值守的安装方式
Kickstart工作流程:
步骤
1.先关掉防火墙和selinux
systemctl stop firewalld
setenforce 0
2.设置静态ip地址并重启网卡
cat /etc/sysconfig/network-scripts/ifcfg-ens33
/etc/init.d/network restaet
3.安装配置DHCP服务
yum -y install dhcp
vi /etc/dhcp/dhcpd.conf
subnet 192.168.50.0 netmask 255.255.255.0 { #设置网段
option routers 192.168.50.2; #设置网关
option subnet-mask 255.255.255.0; #设置子网掩码
option domain-name-servers 192.168.50.2; #设置dns服务器地址
range dynamic-bootp 192.168.50.200 192.168.50.205; #IP地址租用的范围
default-lease-time 21600; #默认租约时间
max-lease-time 43200; #最大租约时间
next-server 192.168.50.132; #tftp服务器地址
filename "pxelinux.0"; #tftp服务器根目录下面的文件名
}
开启服务并设置开机自启动
systemctl start dhcpd
systemctl enable dhcpd
4.安装搭建TFTP服务
yum -y install tftp -server tftp
vi /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 //将yes改为no,启动tftp服务
per_source = 11
cps = 100 2
flags = IPv4 }
开启服务并设置开机自启动
systemctl start tftp
systemctl enable tftp
systemctl start xinetd
systemctl enable xinetd
5.组建PXE服务环境
安装syslinux包
yum install syslinux -y
cd /var/lib/tftpbootcd
将pxelinux.0拷贝到tftp服务目录
cp /usr/share/syslinux/pxelinux.0 .
cp /mnt/images/pxeboot/{vmlinuz,initrd.img} .
cp /mnt/isolinux/{vesamenu.c32,boot.msg} .
在tftp服务目录下创建pxelinux.cfg目录
mkdir pxelinux.cfg
配置启动菜单文件,将系统自带的启动文件拷贝到TFTP目录下改名为
cp /mnt/isolinux/isolinux.cfg pxelinux.cfg/default
vi pxelinux.cfg/default 删除60行后的内容,自己编写
label linux
menu label ^Install CentOS 74
kernel vmlinuz 指定内核
append initrd=initrd.img ks=http://192.168.50.132/config/ks.cfg biosdevname=0
net.ifnames=0 //指定自动安装文件ks.cfg
6.搭建http服务
#通过HTTP协议把光盘镜像内容传给客户端
yum install httpd -y
cp -rf /mnt/* /var/www/html/
mkdir -p /var/www/html/config #新建目录,把自定义的文件、脚本等放置于此
开启服务并设置开机自启动
systemctl start http
systemctl enable http
7.创建kickstart文件
vi /var/www/html/config/ks.cfg
#platform=x86, AMD64 或 Intel EM64T
#version=
#Firewall configuration //关闭防火墙
firewall --disabled
#Install OS instead of upgrade //安装系统
install
#Use network installation //使用网络安装,配置http获取安装包
url --url="http://192.168.50.132/"
#!!!
#Use CDROM installation media
repo --name="yum" --baseurl=http://192.168.50.132/
#!!!
#Root password //配置root密码
rootpw --iscrypted $1$mi4lP.ZY$j5UDGX34knfGuSYPwd82u/ #redhat
#openssl passwd -1
#Use graphical install graphical or text
text
#Run the Setup Agent on first boot
firstboot --disable
#System keyboard //配置键盘
keyboard us
#System language //配置语言
lang en_US.UTF-8
#SELinux configuration //关闭selinux
selinux --disabled
#Reboot after installation //安装完重新引导
reboot
#System timezone //配置时区
timezone --isUtc Asia/Shanghai
#Network information //配置网络为自动获取
network --bootproto=dhcp --device=eth0 --noipv6 --activate
network --hostname=web
#!!!
#System bootloader configuration //系统引导程序配置
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
#Clear the Master Boot Record //清空主引导记录
zerombr
#Partition clearing information //分区信息
clearpart --all --initlabel
#!!!
#Disk partitioning information //指定分区大小
part /boot --fstype="xfs" --ondisk=sda --size=200
part swap --fstype="swap" --ondisk=sda --size=2048
part / --fstype="xfs" --ondisk=sda --size=17166
#!!!
%packages
@core
wget
%end
%post //配置yum
#yum_client
cd /etc/yum.repos.d/
rm -rf *
wget http://192.168.50.132/config/yum.repo
%end
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end
8.启动客户机安装
客户机要和服务器在同一局域网内