PXE网络批量装机

一.批量装机环境

1.PXE组件及过程分析

• 什么是PXE网络
– 预启动执行环境,在操作系统之前运行
– 可用于远程安装

• 需要哪些服务组件?
–DHCP服务,分配IP地址、定位引导程序
–TFTP服务,提供引导程序下载
–HTTP服务(或FTP/NFS),提供yum安装源

• 客户机应具备的的条件
–网卡芯片必须支持PXE协议
–主板支持从网卡启动
在这里插入图片描述

2.部署DHCP服务器

1.虚拟机安装dhcp软件包
[root@svr7 /]# yum -y install dhcp

2.修改配置文件 /etc/dhcp/dhcpd.conf
[root@svr7 /]# vim /etc/dhcp/dhcpd.conf
在vim末行模式下 :r /usr/share/doc/dhcp*/dhcpd.conf.example,删除多余的配置并修改:
subnet 192.168.4.0 netmask 255.255.255.0 { #分配的网段 ------>指定要分配的网段
range 192.168.4.100 192.168.4.200; #分配的IP范围 ------>指定要分配的IP范围
option domain-name-servers 192.168.4.7; #分配DNS服务器 ------>指定DNS服务器IP地址
option routers 192.168.4.254; #分配网关地址 ------>指定分配的网关地址
default-lease-time 600;
max-lease-time 7200;
next-server 192.168.4.7; #指定下一个服务器地址  ------>指定该服务器的IP地址
filename “pxelinux.0”; #指定引导文件名称(安装说明书)
}

3.重启服务
[root@svr7 /]# systemctl restart dhcpd

3.部署TFTP服务

1.安装软件包tftp-server
[root@svr7 /]# yum -y install tftp-server

2.重启tftp服务
[root@svr7 /]# systemctl restart tftp

3.部署pxelinux.0文件
]# yum provides */pxelinux.0 #查询哪个包产生该文件
]# yum -y install syslinux
]# rpm -ql syslinux | grep pxelinux.0 #查询软件包安装清单
]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
]# ls /var/lib/tftpboot/

4.部署菜单文件(虚拟机需要有光驱设备并且有内容)
[root@svr7 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@svr7 ~]# ls /mnt/
[root@svr7 ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@svr7 ~]# cp /mnt/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@svr7 ~]# ls /var/lib/tftpboot/pxelinux.cfg/
[root@svr7 ~]# ls -l /var/lib/tftpboot/pxelinux.cfg/

5.部署 图形模块(vesamenu.c32) 与 背景图片(splash.png)
[root@svr7 ~]# cp /mnt/isolinux/vesamenu.c32 /mnt/isolinux/splash.png /var/lib/tftpboot/
[root@svr7 ~]# ls /var/lib/tftpboot/

6.部署 启动内核(vmlinuz) 与 驱动程序(initrd.img)
[root@svr7 ~]# cp /mnt/isolinux/vmlinuz /mnt/isolinux/initrd.img /var/lib/tftpboot/
[root@svr7 ~]# ls /var/lib/tftpboot/
  initrd.img pxelinux.cfg vesamenu.c32
  pxelinux.0 splash.png vmlinuz 
  
7.修改菜单文件内容
[root@svr7 ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
1 default vesamenu.c32 #默认加载图形模块
2 timeout 600 #读秒时间60秒 1/10秒
10 menu background splash.png #指定背景图片
11 menu title NSD1903 PXE Server #修改标题
61 label linux
62 menu label ^Install CentOS 7 #屏幕显示
63 menu default #读秒结束默认选择  
64 kernel vmlinuz #调用内核
65 append initrd=initrd.img #解压驱动程序
 
8.检查服务启动
[root@svr7 ~]# systemctl restart dhcpd
[root@svr7 ~]# systemctl enable dhcpd
[root@svr7 ~]# systemctl restart tftp
[root@svr7 ~]# systemctl enable tftp

3.部署Web服务

1.安装软件包httpd
[root@svr7 ~]# yum -y install httpd

2.重启httpd服务
[root@svr7 ~]# systemctl restart httpd
[root@svr7 ~]# systemctl enable httpd

3.共享光盘所有内容
[root@svr7 ~]# mkdir /var/www/html/centos
[root@svr7 ~]# ls /var/www/html/centos
[root@svr7 ~]# mount /dev/cdrom /var/www/html/centos
mount: /dev/sr0 写保护,将以只读方式挂载
[root@svr7 ~]# ls /var/www/html/centos
[root@svr7 ~]# firefox 192.168.4.7/centos

4.部署无人值守安装,生成应答文件

1.安装图形的system-config-kickstart工具,生成应答文件
[root@svr7 ~]# yum -y install system-config-kickstart

2.运行system-config-kickstart工具,进行配置
[root@svr7 ~]# LANG=en system-config-kickstart
首先查看软件包选择(Package Select),是否可以使用,需要Yum仓库的支持,必须要求Yum光盘仓库标识为 [development]
[root@svr7 ~]# vim /etc/yum.repos.d/local.repo
[development]

[root@svr7 ~]# LANG=en system-config-kickstart
[root@svr7 ~]# ls /root/
[root@svr7 ~]# vim /root/ks.cfg
在这里插入图片描述在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3.利用Web服务,将应答文件ks.cfg,共享给客户端
[root@svr7 ~]# cp /root/ks.cfg /var/www/html/
[root@svr7 ~]# ls /var/www/html/

4.修改菜单文件,指定应答文件ks.cfg
]# vim /var/lib/tftpboot/pxelinux.cfg/default

label linux
menu label ^Install CentOS 7
menu default
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.4.7/ks.cfg

验证:
新建一台虚拟机,安装方式选择 “网络引导安装(PXE)”
网络类型选择"private1"
内存必须2G以上

发布了7 篇原创文章 · 获赞 3 · 访问量 594

猜你喜欢

转载自blog.csdn.net/qq_44895681/article/details/89608881