PXE,Pre-boot eXcution Environment
预启动执行环境,在操作系统之前运行
可用于远程安装,构建无盘工作站
服务端
运行DHCP服务,用来分配地址,定位引导程序
引导程序:微代码,存放在TFTP服务器中
运行TFTP服务器,提供引导程序下载
TFTP服务器时UDP协议,端口号69
镜像文件存放在:vsftpd,TCP协议,端口号20,21
客户端
网卡支持PXE协议
主板支持网络启动
基本部署过程
TFTP服务及引导文件
DHCP服务的PXE设置
[root@localhost ~]#yum install dhcp -y
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.20 192.168.100.30;
option routers 192.168.100.100;
option domain-name-servers 6.6.6.6;
next-server 192.168.100.100; '指定TFTP服务器地址'
filename "pxelinux.0"; 'filename:指定要下载的引导程序文件'
}
[root@localhost ~]#systemctl start dhcpd
[root@localhost ~]#systemctl enable dhcpd
默认的启动菜单文件☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆
创建/var/lib/tftpboot/pxelinux.cfg/default
最终创建的default文件输入内容
1.设置双网卡,
2.设置DHCP,用来自动获取IP地址,引导定位TFTP位置
next-server TFTP IP
filename “pxelinux.0”
3.设置TFTP(先安装tftp-server并设置)
为客户机安装系统
环境
使用VMware软件中centos 7系统
打开一台centos 7
'第一步,在服务器设置双网卡'
在centos 7添加一个网络适配器,并设置为仅主机模式。 '用来装机,做服务器的网卡'
原本的网络适配器保持NAT模式不变。 '用来安装yum包'
'第二步,设置添加的网卡IP地址,关闭防火墙'
[root@localhost ~]# cd /etc/sysconfig/network-scripts
[root@localhost network-scripts]# cp -p ifcfg-ens33 ifcfg-ens36
[root@localhost network-scripts]# ls
[root@localhost network-scripts]# vim ifcfg-ens36
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens36"
UUID="fe60a0ac-7d04-46a3-b29c-633a50b88f33" 'UUDI删除掉'
DEVICE="ens36"
ONBOOT="yes"
IPADDR=192.168.100.100
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# ifconfig '发现设置成功'
[root@localhost network-scripts]# systemctl stop firewalld.service
[root@localhost network-scripts]# setenforce 0
'第三步,设置DHCP服务'
[root@localhost ~]#yum install dhcp* -y
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.20 192.168.100.30;
option routers 192.168.100.100;
option domain-name-servers 6.6.6.6;
next-server 192.168.100.100; '指定TFTP服务器地址'
filename "pxelinux.0"; 'filename:指定要下载的引导程序文件'
}
'第四步:设置TFTP--配置安装tftp-server'
[root@localhost ~]# yum install tftp-server -y
[root@localhost ~]# rpm -ql tftp-server
/etc/xinetd.d/tftp '配置文件'
/usr/lib/systemd/system/tftp.service
/usr/lib/systemd/system/tftp.socket
/usr/sbin/in.tftpd
/usr/share/doc/tftp-server-5.2
/usr/share/doc/tftp-server-5.2/CHANGES
/usr/share/doc/tftp-server-5.2/README
/usr/share/doc/tftp-server-5.2/README.security
/usr/share/man/man8/in.tftpd.8.gz
/usr/share/man/man8/tftpd.8.gz
/var/lib/tftpboot '站点'
[root@localhost network-scripts]# vim /etc/xinetd.d/tftp '编辑配置文件'
disable = no '将此改成no'
[root@localhost network-scripts]# cd /var/lib/tftpboot '进入站点'
[root@localhost tftpboot]# ls
'第五步:安装并设置syslinux'
[root@localhost tftpboot]# yum install syslinux -y '安装syslinux'
[root@localhost tftpboot]# rpm -ql syslinux | grep pxelinux.0
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0
[root@localhost tftpboot]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot '将syslinux中的pxelinux.0复制过来'
[root@localhost tftpboot]# ls
pxelinux.0
[root@localhost tftpboot]# yum install vsftpd -y
[root@localhost tftpboot]# rpm -ql vsftpd '查看站点'
...省略内容
/var/ftp
/var/ftp/pub
[root@localhost tftpboot]# mkdir /var/ftp/centos7 '创建centos7目录用来挂载'
[root@localhost tftpboot]# cd /var/ftp
[root@localhost ftp]# ls
centos7 pub
[root@localhost ftp]# ls centos7 '发现镜像文件中没有东西'
'挂载之前先点击已连接'
[root@localhost ftp]# mount /dev/sr0 /var/ftp/centos7/ '挂载'
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ftp]# df -hT
[root@localhost ftp]# ls centos7 '再次查看centos7文件,发现有了内容'
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
'第六步,在镜像中复制出文件'
[root@localhost ftp]# cd centos7/images
[root@localhost images]# cd pxeboot
[root@localhost pxeboot]# ls '发现目标文件,准备复制'
initrd.img TRANS.TBL vmlinuz
[root@localhost pxeboot]# cp vmlinuz initrd.img /var/lib/tftpboot/ '将文件复制到tftp站点中'
[root@localhost pxeboot]# ls /var/lib/tftpboot
initrd.img pxelinux.0 vmlinuz
'第七步,设置默认配置文件'
[root@localhost pxeboot]# cd /var/lib/tftpboot
[root@localhost tftpboot]# ls
initrd.img pxelinux.0 vmlinuz
[root@localhost tftpboot]# mkdir pxelinux.cfg '创建pxelinux配置文件'
[root@localhost tftpboot]# cd pxelinux.cfg/
[root@localhost pxelinux.cfg]# vim default '创建默认配置文件'
'输入以下内容'
default auto
prompt 1
label auto
kernel vmlinuz
append initrd=initrd.img method=ftp://192.168.100.100/centos7
label linux text
kernel vmlinuz
append text initrd=initrd.img method=ftp://192.168.100.100/centos7
label linux rescue
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://192.168.100.100/centos7
[root@localhost pxelinux.cfg]#systemctl start dhcpd
[root@localhost pxelinux.cfg]#systemctl start tftp
[root@localhost pxelinux.cfg]#systemctl start vsftpd
第八步,开启虚拟机,选择
[root@localhost ~]# yum install system-config-kickstart -y
'安装kickstart工具'
[root@localhost ~]# cd /var/ftp
[root@localhost ftp]# ls
centos7 ks.cfg pub
[root@localhost ftp]# cd
[root@localhost ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg 下载 公共 图片 文档 桌面 模板 视频 音乐
[root@localhost ~]# vim anaconda-ks.cfg
...'复制以下内容'
%packages
@^graphical-server-environment
@base
@core
@desktop-debugging
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@hardware-monitoring
@input-methods
@internet-browser
@multimedia
@print-client
@x11
chrony
kexec-tools
%end
[root@localhost ~]# vim /var/ftp/ks.cfg '复制的粘贴到此'
[root@localhost ~]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# ls
initrd.img pxelinux.0 pxelinux.cfg vmlinuz
[root@localhost tftpboot]# cd pxelinux.cfg/
[root@localhost pxelinux.cfg]# ls
default
[root@localhost pxelinux.cfg]# vim default
..
label auto
kernel vmlinuz
append initrd=initrd.img method=ftp://192.168.100.100/centos7 ks=ftp://192.168.100.100/ks.cf
g '在原本此段内容后面输入ks=ftp://192.168.100.100/ks.cf
g'
[root@localhost pxelinux.cfg]# systemctl restart dhcpd '重启服务'
[root@localhost pxelinux.cfg]# systemctl restart tftp
[root@localhost pxelinux.cfg]# systemctl restart vsftpd