PXE

1.PXE介绍

 PXE:
Preboot Excution Environment 预启动执行环境
Intel公司研发
基于Client/Server的网络模式,支持远程主机通过网络
从远端服务器下载映像,并由此支持通过网络启动操作系统
PXE可以引导和安装Windows,linux等多种操作系统

2.PXE工作原理

PXE_第1张图片
Paste_Image.png
 Client向PXE Server上的DHCP发送IP地址请求消息,DHCP检测Client是否合法(主要是检测Client的网卡MAC地址),如果合法则返回Client的IP地址,同时将启动文件pxelinux.0的位置信息一并传送给Client
 Client向PXE Server上的TFTP发送获取pxelinux.0请求消息,TFTP接收到消息之后再向Client发送pxelinux.0大小信息,试探Client是否满意,当TFTP收到Client发回的同意大小信息之后,正式向Client发送pxelinux.0
 Client执行接收到的pxelinux.0文件
 Client向TFTP Server发送针对本机的配置信息文件(在TFTP 服务的pxelinux.cfg目录下),TFTP将配置文件发回Client,继而Client根据配置文件执行后续操作。
 Client向TFTP发送Linux内核请求信息,TFTP接收到消息之后将内核文件发送给Client
 Client向TFTP发送根文件请求信息,TFTP接收到消息之后返回Linux根文件系统
 Client启动Linux内核
 Client下载安装源文件,读取自动化安装脚本

3.PXE自动化安装CentOS 7

(1)安装前准备:关闭防火墙和SELINUX,DHCP服务器静态IP
(2)安装软件包

httpd tftp-server dhcp syslinux system-config-kickstart

(3)配置文件共享服务:

systemctl enable httpd
systemctl start httpd
mkdir /var/www/html/centos/7
mount /dev/sr0 /var/www/html/centos/7配置网络yum源
 准备kickstart文件
/var/www/html/ks/centos7.cfg 注意:权限
 配置tftp服务
systemctl enable tftp.socket (centos6:chkconfig tftp on)
systemctl start tftp.socket (centos6:service xinetd restart)
 配置DHCP服务
systemctl enable dhcpd
vim /etc/dhcp/dhcpd.conf
option domain-name "example.org";
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.1 192.168.100.200;
filename "pxelinux.0";
next-server 192.168.100.100;
}
systemctl start dhcpd

 准备相关文件
mkdir /var/lib/tftpboot/pxelinux.cfg/
cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/
cp /misc/cd/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/
cp /misc/cd/isolinux/isolinux.cfg
/var/lib/tftpboot/pxelinux.cfg/default
文件列表如下:
/var/lib/tftpboot/
├── initrd.img
├── menu.c32
├── pxelinux.0
├── pxelinux.cfg
│ └── default
└── vmlinuz

 准备启动菜单
Vim /var/lib/tftpboot/pxelinux.cfg/default

default menu.c32
timeout 600
menu title PXE INSTALL MENU
label autoa
menu label Auto Install CentOS 7
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.100.100/ks/centos7.cfg
label manual
menu label Manual Install CentOS 7
kernel vmlinuz
append initrd=initrd.img inst.repo=http://192.168.100.100/centos/7
label local
menu default
menu label ^Boot from local drive
localboot 0xffff

4.PXE自动化安装CentOS 6

 安装前准备:关闭防火墙和SELINUX,DHCP服务器静态IP
 1 安装相应软件包

Yum install dhcp httpd tftp-server syslinux
chkconfig tftp on
chkconfig xinetd on
chkconfig httpd on
chkconfig dhcpd on
service httpd start
service xneted start

 2 准备Yum 源和相关目录
mkdir -pv /var/www/html/centos/{6,ks}
mount /dev/sr0 /var/www/html/centos/6
 3 准备kickstart文件
/var/www/html/centos/ks/centos6.cfg
注意权限:
chmod 644 /var/www/html/centos/ks/centos6.cfg
 4 准备相关的启动文件

mkdir /var/lib/tftpboot/pxelinux.cfg/
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cd /misc/cd/images/pxeboot/
cp vmlinuz initrd.img /var/lib/tftpboot
Cd /misc/cd/isolinux/
cp boot.msg vesamenu.c32 splash.jpg /var/lib/tftpboot

 5 准备启动菜单文件
cp /misc/cd/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
vim /var/lib/tftpboot/pxelinux.cfg/default

default vesamenu.c32 指定菜单风格
#prompt 1
timeout 600
display boot.msg
menu background splash.jpg
menu title Welcome to wang CentOS 6
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color scrollbar 0 #ffffffff #00000000
label auto
menu label ^Automatic Install Centos6
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.100.100/centos/ks/centos6.cfg
label manual
menu label ^Manual Install Centos
kernel vmlinuz
append initrd=initrd.img inst.repo=http://192.168.100.100/centos/6
label local
menu default
menu label Boot from ^local drive
localboot 0xffff

目录结构如下:
tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── boot.msg
├── initrd.img
├── pxelinux.0
├── pxelinux.cfg
│ └── default
├── splash.jpg
├── vesamenu.c32
└── vmlinuz
 6 配置dhcp服务
cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
vim /etc/dhcp/dhcpd.conf

option domain-name "magedu.com";
option domain-name-servers 192.168.100.1;
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.1 192.168.100.200;
option routers 192.168.100.1;
filename "pxelinux.0";
next-server 192.168.100.100;
}

service dhcpd start

你可能感兴趣的:(PXE)