实验环境 1台Centos7.6的虚拟机 ip: 192.168.148.17/24 配置PXE环境;新建一台虚拟机作为测试机
本次实验采用 dnsmasq作为dhcp、tftp服务器; vsftpd 提供安装源
# 关闭防火墙
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
#syslinux 提供pxe启动的引导文件
[root@localhost ~]# yum -y install dnsmasq vsftpd syslinux
[root@localhost ~]# mkdir /var/ftp/pub/centos7
[root@localhost ~]# systemctl enable dnsmasq vsftpd
[root@localhost ~]# systemctl start vsftpd
[root@localhost ~]# mkdir /var/ftp/pub/centos7
[root@localhost ~]# mount /dev/sr0 /var/ftp/pub/centos7/
# 创建tftp服务目录
[root@localhost ~]# mkdir /var/lib/dnsmasq/tftpboot/
[root@localhost ~]# cd /var/lib/dnsmasq/tftpboot/
[root@localhost tftpboot]# cp /usr/share/syslinux/{menu.c32,gpxelinux.0} .
[root@localhost tftpboot]# mkdir pxelinux.cfg
[root@localhost tftpboot]# cp /var/ftp/pub/centos7/isolinux/isolinux.cfg pxelinux.cfg/default
# 编辑default文件最终内容如下 Gpxe除了支持传统的tftp还支持ftp,http方式下载文件
default menu.c32
timeout 600
menu title CentOS 7
label linux
menu label ^Install CentOS 7
kernel ftp://192.168.148.17/pub/centos7/isolinux/vmlinuz
append initrd=ftp://192.168.148.17/pub/centos7/isolinux/initrd.img inst.repo=ftp://192.168.148.17/pub/centos7/
label local
menu label Boot from ^local drive
menu default
localboot 0xffff
# 在/etc/dnsmasq.d/ 创建pxe.conf ;指定 dhcp地址池的范围,启用tftp功能,指定tftp服务器地址和引导文件;文件内容如下:
[root@localhost ~]# cat /etc/dnsmasq.d/pxe.conf
dhcp-range=192.168.148.50,192.168.148.100,255.255.255.0,12h
enable-tftp
dhcp-boot=/var/lib/dnsmasq/tftpboot/gpxelinux.0,192.168.148.17
[root@localhost ~]# systemctl start dnsmasq
# 检测ipv4 监听的udp端口
[root@localhost ~]# ss -4 -unl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
UNCONN 0 0 *:53 *:*
UNCONN 0 0 *:67 *:*
UNCONN 0 0 *:69 *:*
# 所需端口都正常开启
# 如果需要开启防火墙 需要添加对应的服务
[root@localhost ~]# systemctl enable firewalld
[root@localhost ~]# systemctl start firewalld
[root@localhost ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: eth0
sources:
services: ssh dhcpv6-client
ports:
protocols:
[root@localhost ~]# firewall-cmd --permanent --add-service=ftp
[root@localhost ~]# firewall-cmd --permanent --add-service=tftp
[root@localhost ~]# firewall-cmd --permanent --add-service=dhcp
[root@localhost ~]# firewall-cmd --reload
[root@localhost ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: eth0 eth1
sources:
services: ssh dhcpv6-client dhcp ftp tftp
启动另一台新的虚拟默认从网络启动进行系统安装