PXE简介:
PXE(preboot execute environment,预启动执行环境)是由Intel公司开发的,工作于C/S网络模式,支持通过网络从远端服务器下载映像,并支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)协议下载一个启动软件包到本机内存中执行,由这个启动软件包完成终端(客户端)基本软件设置,从而引导预先安装在服务器中的终端操作系统。
实现PXE需要的硬件和软件:
硬件需求:
1、客户端需要一块支持PXE引导模块的网卡
2、客户端主板BIOS需要支持网卡启动
软件需求:
1、PXE引导服务
2、DHCP地址分配服务
3、安装TFTP简单文件服务
4、安装ftp服务器
服务作用说明:
1、PXE引导服务:可以给客户端提供系统启动指令,引导模块和内核模块
2、DHCP服务:客户端没有操作系统,所以无法手动配置IP地址,唯一的方式就通过DCHP获取IP地址
3、TFTP服务:服务器给客户端传输引导模块和内核文件
4、FTP服务:服务器给客户端传输操作系统安装文件
PXE的配置详细步骤:
1、关闭沙盒、防火墙,配置网卡
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
服务器ip:192.168.1.10
[root@localhost ~]#systemctl restart network
2、安装ftp服务,配置yum源
[root@localhost ~]# umount /dev/cdrom
[root@localhost ~]# mount /dev/cdrom /media/
[root@localhost ~]# rm -rf /etc/yum.repos.d/*
[root@localhost ~]# vim /etc/yum.repos.d/yum.repo
[yum]
baseurl=file:///media
enabled=1
gpgcheck=0
[root@localhost ~]# yum -y install vsftpd
[root@localhost ~]# mkdir /var/ftp/centos7
[root@localhost ~]# cp -rf /media/* /var/ftp/centos7
3、安装tftp和xinetd软件包: tftp服务依赖于xinetd超级服务
[root@localhost ~]# yum -y install tftp-server tftp xinetd
4、修改tftp配置文件
将 disable =yes
改为 disable =no
5、启动tftp服务
[root@localhost ~]# systemctl restart tftp
[root@localhost ~]# systemctl restart xinetd
6、配置DHCP服务:
[root@localhost ~]# yum -y install dhcp
编辑主配置文件:
[root@localhost~]#cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
修改:
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.11 192.168.1.20;
option routers 192.168.1.10;
option broadcast-address 192.168.1.255;
default-lease-time 600;
max-lease-time 7200;
//在此处添加下列两行
next-server 192.168.1.10; 指定tftp的服务器地址
filename "pxelinux.0"; 指定PXE引导启动程序文件名
}
7、重启DHCP服务
[root@localhost ~]# systemctl restart dhcpd
8、准备内核文件和初始化镜像文件,拷贝到tftp目录下:
[root@localhost ~]# cd /media/images/pxeboot/
[root@localhost pxeboot]# ls
initrd.img TRANS.TBL vmlinuz
vmlinuz:内核文件
initrd.img:简化系统镜像
[root@localhost pxeboot]# cp vmlinuz initrd.img /var/lib/tftpboot/
9、准备支持PXE软件包:
[root@localhost ~]# yum -y install syslinux
[root@localhost ~]# cd /usr/share/syslinux/
[root@localhost syslinux]# cp pxelinux.0 /var/lib/tftpboot/
10、准备启动并修改菜单:
[root@localhost syslinux]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@localhost syslinux]# cp /media/isolinux/boot.msg /var/lib/tftpboot/
[root@localhost syslinux]# cd /var/lib/tftpboot/pxelinux.cfg/
[root@localhost pxelinux.cfg]# vim default
default auto 自动选择
prompt 1 是否等待控制(1等待,0不等待)
timeout 600 等待时间
display boot.msg 内核文件名
label auto 常规安装
kernel vmlinuz
append initrd=initrd.img method=ftp://192.168.1.10/centos7
解释:
//append initrd:加载镜像
//initrd.img:镜像文件,类似于windows pe系统
//method:ftp镜像路径
11、重启所有服务
[root@localhost pxelinux.cfg]# systemctl restart vsftpd
[root@localhost pxelinux.cfg]# systemctl restart tftp
[root@localhost pxelinux.cfg]# systemctl restart dhcpd
[root@localhost pxelinux.cfg]# systemctl restart xinetd
[root@localhost pxelinux.cfg]# systemctl stop firewalld
[root@localhost pxelinux.cfg]# setenforce 0
12、调节同一虚拟网卡实现dhcp广播