PXE 使用总结
最近用到了PXE批量安装集群OS,现整理相关操作指南如下,具体安装使用请读者根据自身现场环境进行调整。
CentOS 7 PXE Server 安装指南
系统配置
- 关闭系统防火墙;
- 关闭SElinux;
软件包安装
yum install httpd dhcp xinetd tftp-server syslinux
配置HTTP Server
HTTP Server 作用: PXE client 从网络安装系统时,从指定的HTTP Server下载安装文件。
- 挂载CentOS ISO
mount /root/CentOS-7-xxx.iso /mnt
- 将ISO内容拷贝到HTTP Server服务目录
mkdir -p /var/www/centos7
cp -a /mnt/* /var/www/centos7
chmod -R 755 /var/www/centos7
- 创建HTTP服务器pxe.conf
vim /etc/httpd/conf.d/pxe.conf
Alias /centos7 /var/www/centos7/
<Diretory /var/www/centos7/>
Options Indexes FollowSymLinks
Order Deny,Allow
Allow from all
</Directory>
- 重启httpd服务
systemctl enable httpd
systemctl restart httpd
HTTPD 安装验证
登陆 x.x.x.x/centos7 就可以查看相应镜像文件。具体截图略
配置TFTP Server
TFTP Server 作用:在PXE引导过程中,PXE Client使用TFTP协议从TFTP服务器下载bootstrap文件并执行。
cd /usr/share/syslinux/
cp prelinux.0 menu.c32 memdisk mboot.c32 chain.c32 /var/lib/tftpboot/
mkdir /var/lib/tftpboot/centos7
cp /mnt/images/pxeboot/vmlinuz /var/lib/tftpboot/centos7
cp /mnt/images/pxeboot/initrd.img /var/lib/tftpboot/centos7
mkdir /var/lib/tftpboot/pxelinux.cfg
vim /var/lib/tftpboot/pxelinux.cfg/default
# .... code above ...
default menu.c32
prompt 0
timeout 300
ONTIMEOUT 1
menu titile ##### CentOS 7 PXE BOOT MEnu #####
lable 1
menu label ^1) Install CentOS 7
menu default
kernel centos7/vmlinuz
append initrd=cetos7/initrd.img method=http://x.x.x.x/centos7 devfs=nomount
label 2
menu label ^2) Boot from local drive
localboot 0
编辑 /etc/xinetd.d/tftp文件,将disable=yes改为disable=no
vim /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftd
server_args = -s /var/lib/tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
tftp 服务由xinetd服务管理,启动xinetd完成tftp-server
systemctl enable xinetd
systemctl restart xinetd
TFTP 安装验证
验证操作:查看tftp-server的监听端口69已经打开
netstat -tunlp | grep xinetd
验证操作:通过tftp-client访问服务器,成功下载文件到本地。
配置DHCP Server
两种方式:对某个网段进行配置,或者是对某个host进行配置
vim /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
# specify domain name
option domain-name "server.world";
# specify name server's hostname or IP address
option domain-name-servers x.x.x.x;
# default lease time
default-lease-time 600;
# max lease time
max-lease-time 7200
# this DHCP server to be declared valid
authoritative;
# allow booting;
# allow bootp;
# specify network address and subnet mask
# 这里添加网段信息
subnet x.x.x.x netmask 255.255.255.0{
# specify the range of lease IP address
range dynamic-bootp x.x.x.x x.x.x.y;
# specify broadcast address
option broadcast-address x.x.x.255;
# specify default gateway
option router x.x.x.1
# specify the bootstrap file
filename "pxelinux.0";
# specify tftp server ip
next-server x.x.x.x;
}
# specify single host
# we want the nameserver to appear at a fixed addresss
# 这里添加单个节点的信息
host node1{
hardware ethernet {network-card-mac-info};
fixed-address x.x.x.x;
}
# this DHCP server to be declared valid
authoritative;
# allow booting;
# allow bootp;
systemctl enable dhcpd
systemctl restart dhcpd
至此pxe服务器配置完毕,客户机重启之后在bios进入pxe启动,会自动开始与网络中pxe服务器进行匹配,匹配之后在屏幕界面选择需要的光盘镜像进行安装即可。
FAQ
- pxe client 启动报错:“no boot filename received”
问题原因:dhcp配置中遗漏 “filename” “next-server” 配置。
问题解决:修改/etc/dhcp/dhcpd.conf,增加相应配置即可。
# /etc/dhcp/dhcpd.conf
filename "pxelinux.0"
next-server x.x.x.x;
- pxe client 启动报错:“Media test failure, check cable”
问题原因:物理网卡没有插好。
问题解决:重新插拔物理网卡,重启系统即可。