PXE介绍
PXE工作原理
PXE自动化安装CentOS7
yum -y install httpd tftp-server dhcp syslinux system-config-kickstart
systemctl enable httpd 把http服务设置为开机自启动
systemctl start httpd 启动http服务
mkdir -p /var/www/html/centos/{7,ks} 创建挂载光盘以及存放kickstart的目录
mount /dev/sr0 /var/www/html/centos/7 挂载光盘
登录http服务进行测试,是否搭建成功
cp ks7.cfg /var/www/html/ksdir
chmod 644 /var/www/html/ksdir/ks7.cfg
dhcp配置文件默认为空,使用模板文件进行修改
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
更改内容:域名、dns、subnet本地网卡所在网段,dhcp分配地址池范围、网关
最重要的是:filename "pxelinux.0"
next-server 192.168.32.129 指向本机(本机作为tftp服务器)
vim /etc/dhcp/dhcpd.conf
27 subnet 192.168.32.0 netmask 255.255.255.0 {
28 range 192.168.32.10 192.168.32.100;
29 filename "pexlinux.0";
30 next-server 192.168.32.129;
31 }
systemctl enable dhcpd
systemctl start dhcpd
systemctl enable tftp.socket 把tftp服务设置为开机自启动
systemctl start tftp.socket 开启tftp服务
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目录下文件列表如下:
tree /var/lib/tftpboot/
├── initrd.img
├── menu.c32
├── pxelinux.0
├── pxelinux.cfg
│ └── default
└── vmlinuz
vim /var/lib/tftpboot/pxelinux.cfg/default
1 default menu.c32
2 timeout 60
3
4 menu title PXE CentOS 7
5
6 label linux
7 menu label Auto Install ^Mini CentOS 7
8 kernel vmlinuz
9 append initrd=initrd.img ks=http://192.168.32.129/ksdir/ks7.cfg
10
11 label local
12 menu default
13 menu label Boot from ^local drive
14 localboot 0xffff
重启tftp服务
systemctl restart tftp
查看三个服务端口68,67,80是否启动
测试是否能够通过网络启动
PXE自动化安装CentOS6
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
mkdir -pv /var/www/html/centos/{6,ks}
mount /dev/sr0 /var/www/html/centos/6
把光盘挂载到/var/www/html/centos/6
mkdir /var/www/html/centos/6
mount /dev/sr0 /var/www/html/centos/6
配置tftp服务,复制文件到/var/lib/tftpboot
复制pxelinux.0文件到/var/lib/tftpboot
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
不使用自定义菜单,使用系统默认菜单
复制/mnt/cdrom/isolinux/下启动菜单用到的文件到/var/lib/tftpboot目录下
mkdir /var/lib/tftpboot/pxelinux.cfg
cp /mnt/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
其他文件:
cp /mnt/cdrom/isolinux/{boot.msg,initrd.img,splash.jpg,vesamenu.c32,vmlinuz} /var/lib/tftpboot
/var/www/tftpboot目录结构如下:
tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── boot.msg
├── initrd.img
├── pxelinux.0
├── pxelinux.cfg
│ └── default
├── splash.jpg
├── vesamenu.c32
└── vmlinuz
1 directory, 7 files
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 linux
menu label ^Auto Install an Mini system
menu default
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.32.128/ksdir/ks6.cfg
最小化安装系统指定应答文件路径ks=http://192.168.32.128/ksdir/ks6.cfg
label vesa
menu label ^Manual Install an system
kernel vmlinuz
append initrd=initrd.img repo=http://192.168.32.128/centos/6
手动安装,类似于救援模式,只需去掉rescue单词即可
label rescue
menu label ^Rescue installed system
kernel vmlinuz
append initrd=initrd.img rescue repo=http://192.168.32.128/centos/6
救援模式要使用救援模式,需要指定仓库路径repo=http://192.168.32.128/centos/6
label local
menu default
menu label Boot from ^local drive
localboot 0xffff
本地安装 更改系统默认启动项为本地启动
cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
vim /etc/dhcp/dhcpd.conf
subnet 192.168.32.0 netmask 255.255.255.0 {
range 192.168.32.10 192.168.32.100
next-server 192.168.32.128
filename "pxelinux.0"
}
service dhcpd start
查看三个服务端口68,67,80是否启动
测试是否能够通过网络启动