#确认网段
#安装dhcp服务
yum install dhcp
#编辑dhcp配置文件
vim /etc/dhcp/dhcpd.conf
#将dhcp配置文件样本拷贝至dhcp配置文件
cat /usr/share/doc/dhcp*/dhcpd.conf.example > /etc/dhcp/dhcpd.conf
#编辑dhcp配置文件
vim /etc/dhcp/dhcpd.conf
##########################
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.230 192.168.1.240;
option routers 192.168.1.117;
filename "pxelinux.0";
next-server 192.168.1.117;
}
##########################
#安装xinetd相关服务
yum -y install xinetd tftp-server syslinux
#编辑xinted配置文件
vim /etc/xinetd.d/tftp
#######################
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot/linux-install
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
##########################
#创建配置文件中所写路径
mkdir -p /tftpboot/linux-install
#安装httpd服务
yum -y install httpd
#删除欢迎页面
rm -rf /etc/httpd/conf.d/welcome.conf
#进入http服务路径
cd /var/www/html/
#创建光盘挂载点
mkdir iso
#挂载光盘
mount /dev/cdrom /var/www/html/iso/
#进入光盘内核路径
cd iso/isolinux
#复制内核到xinted服务路径
cp vmlinuz /tftpboot/linux-install/vmlinuz
cp initrd.img /tftpboot/linux-install/initrd.img
mkdir -p /tftpboot/linux-install/pxelinux.cfg
cp isolinux.cfg /tftpboot/linux-install/pxelinux.cfg/default
cp /usr/share/syslinux/pxelinux.0 /tftpboot/linux-install/
#进入xinted服务路径
cd /tftpboot/linux-install/
#编辑启动文建,设置默认启动规则
vim pxelinux.cfg/default
#####################
default pxe7
label pxe7
menu label ^Install CentOS 7
kernel vmlinuz
append initrd=initrd.img method=http://192.168.116.134/iso ks=http://192.168.116.134/ks.cfg devfs=nomount
#######################
#复制ks文件
cp /root/anaconda-ks.cfg /var/www/html/ks.cfg
cd /var/www/html/
#编辑ks文件
vim ks.cfg
##################
#version=DEVEL
# Install OS instead of upgrade
install
url --url="http://192.168.116.134/iso"
selinux --disabled
firewall --disabled
###################
#给ks文件加读权限
chmod 644 ks.cfg
#启动所有相关服务
systemctl restart dhcpd xinetd httpd
systemctl enable dhcpd xinetd httpd
原文地址:https://www.cnblogs.com/fzlsss/p/9676549.html