PXE 批量部署服务器 操作手册
1. 实验拓扑 及需求

- 操作系统 : centos7 (PXE-server)
- IP地址规划 : centos 7(PXE-server) : 192.168.17.17
centos 7(PXE-Client) : 192.168.17.100 ~ 192.168.17.200 - 技术选型 :
- dhcp 服务搭建 (为pxe-client 客户端分配ip)
- httpd 将镜像服务 ,及pxe-server的kfs文件 放到http服务上
- tfpt 文件传输服务
2. 实验步骤
在PXE-server服务器上进行操作
- 关闭 vmware 的dhcp服务
因为需要使用的自己的虚拟机作为dhcp服务 , 所以需要将vwware自己的dhcp分配取消 否则会导致 , pxe-client无法获取到pxe-server分配的ip

-
为PXE-server配置一个静态ip

-
将PXE-server的防火墙和selinux 关闭
[root@localhost ~]# systemctl stop firewalld //关闭防火墙
[root@localhost ~]# systemctl disable firewalld //将防火墙设为开机不启动
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled //将此行改为 disabled 关闭selinux
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
- 在PXE-server 上配置dhcp服务
//使用yum 安装dhcp 服务
[root@localhost ~]# yum -y install dhcp
//修改dhcp的配置文件 , 配置dhcp服务
[root@localhost ~]# vi /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.17.0 netmask 255.255.255.0 {
option routers 192.168.17.2; #网关
option domain-name-servers 192.168.17.2; #DNS
range 192.168.17.100 192.168.17.200;#地址池
next-server 192.168.17.17;#dhcp服务器
filename "pxelinux.0";
}
//启动dhcp服务
[root@localhost ~]# systemctl start dhcpd
//查看dhcp服务状态
[root@localhost ~]# systemctl status dhcpd
- 搭建http 服务
//使用yum安装 httpd 服务
[root@localhost ~]# yum -y install httpd
//创建光盘镜像挂载目录
[root@localhost ~]# mkdir /var/www/html/centos
//将光盘挂载到创建的目录下
[root@localhost ~]# mount /dev/sr0 /var/www/html/centos/
mount: /dev/sr0 写保护,将以只读方式挂载
//启动httpd 服务
[root@localhost ~]# systemctl start httpd
- 配置tftp 服务 , 并将需要的文件生成
//使用yum 安装 tftp服务
[root@localhost ~]# yum -y install tftp tftp-server
//复制需要的文件
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@localhost ~]# cp /var/www/html/centos/isolinux/{vmlinuz,*.c32,initrd.img} /var/lib/tftpboot/
[root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
//编辑引导文件
[root@localhost ~]# vi /var/lib/tftpboot/pxelinux.cfg/default
default linux
prompt 0
timeout 10
label linux
kernel vmlinuz
Append initrd=initrd.img ip=dhcp method=http://192.168.17.17/centos ks=http://192.168.17.17/ks.cfg
//启动tftp服务
[root@localhost tftpboot]# systemctl start tftp
//将tftp服务设为开机自启动
[root@localhost tftpboot]# systemctl enable tftp
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
- 生成ks.cfg 文件
[root@localhost ~]# cp /root/anaconda-ks.cfg /var/www/html/ks.cfg
[root@localhost ~]# vi /var/www/html/ks.cfg
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# vi/var/www/html/ks.cfg
ignoredisk --only-use=sda
autopart --type=lvm
clearpart --all
graphical
url --url="http://192.168.17.17/centos" //此处为本地http的服务
rootpw --plaintext P@ssw0rd01!
keyboard --vckeymap=cn --xlayouts='cn'
lang zh_CN.UTF-8
selinux --disabled
network --bootproto=dhcp --device=ens33 --ipv6=auto --activate
network --hostname=localhost.localdomain
xconfig --startxonboot
firstboot --disable
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all
# Disk partitioning information
reboot
eula --agreed
%packages
@^graphical-server-environment
%end
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
//将ks.cfg文件进行授权
[root@localhost ~]# chmod a+r /var/www/html/ks.cfg
//启动http服务
[root@localhost ~]# systemctl start httpd
- 配置完毕 , 进行测试
在vmware上新建一台虚拟机 , 最小设置内存为 , 2g , 不需要给它配置镜像 , 直接启动即可
所遇bug
-

-
当pxe自动部署到这一步的时候 , 他无法去选择 , 一些必要的选项
问题所在 :
在经检查后, 发现我所指定的ks文件 , 被单独放在了一行 , 没有跟在Append 标签的后面 , 导致他无法检测到ks文件 , 导致无法进行选择 选择。

本文详细指导如何在CentOS 7上通过PXE服务器进行批量部署,包括配置DHCP、HTTP、TFTP服务,以及解决ks.cfg文件引用问题。重点在于设置dhcp、httpd和tftp服务,确保pxe-client正确获取镜像并进行选择。

1万+

被折叠的 条评论
为什么被折叠?



