目录
远程实现:不需要光盘、U盘等安装介质编辑PXE(Preboot eXcution Environment)
安装 tftp-server xinetd dhcp vsftpd syslinux 软件包
复制 vmlinuz initrd.img pxelinux.0 到 /var/lib/tftpboot/ 目录'
在 /var/lib/tftpboot/ 目录里准备 PXE 启动菜单配置文件 pxelinux.cfg/default
修改服务配置文件,启动 tftp-server xinetd dhcpd vsftpd 服务
安装 system-config-kickstart ,准备 kickstart 自动应答文件,修改 PXE 启动菜单配置文件
一.PXE概述
PXE批量部署的优点
- 规模化:同时装配多台服务器
- 自动化:安装系统、配置各种服务
远程实现:不需要光盘、U盘等安装介质
PXE(Preboot eXcution Environment)
- 预启动执行环境,在操作系统之前运行
服务端
- 运行DHCP服务,用来分配地址、定位引导程序
- 运行TFTP服务,提供引导程序下载
客户端
- 网卡支持PXE协议主板支持网络引导
PXE批量网络装机
- PXE(预启动执行环境,在操作系统之前运行)是由Intel公司开发的网络引导技术,工作在Client/Server模式,允许客户机通过网络从远程服务器下载引导镜像,并加载安装文件或者整个操作系统。
PXE具备以下三个优点
- 规模化:同时装配多台服务器
- 自动化:安装系统、配置各种服务
- 远程实现:不需要光盘、U 盘等安装介质
搭建 PXE 网络体系,必须满足以下几个前提条件
-
客户端
- 客户机的网卡要支持PXE协议(集成BOOTROM芯片),且主板支持网络引导。一般大多数服务器主机都支持,只需在BIOS设置中允许从 Network 或 LAN 启动即可。
-
服务端
- 网络中有一台 DHCP 服务器以便为客户机自动分配地址、指定引导文件位置。
- 服务器要通过 TFTP服务(简单文件传输协议)来提供系统内核和引导镜像文件的下载。
- 搭建 PXE 远程安装服务器
- PXE 远程安装服务器集成了 CentOS 7 安装源、TFTP 服务、DHCP 服务、FTP 服务,能够向客户机裸机发送 PXE引导程序、Linux 内核、启动菜单等数据,以及提供安装文件。
- TFTP(简单文件传输协议),是一个基于UDP协议实现的用于在客户机和服务器之间进行简单文件传输的协议,适合于小文件传输的应用场合。TFTP服务默认由xinetd服务进行管理,使用UDP 端口69
- xinetd是新一代的网络守护进程服务程序,又叫超级服务器,常用来管理多种轻量级Internet服务。
- 守护进程也称精灵进程(Daemon),是运行在后台的一种特殊进程。守护进程独立于控制终端,它们常常跟随系统启动时启动,在系统关闭时才结束。守护进程周期性的执行某些任务或者等待处理某些事件,Linux上的大多数服务都是用守护进程实现的。
- 在系统启动中默认的守护进程的父进程ID全都是init,守护进程特征就是在程序运行名后加了一个d,但不是所有的尾字母是d的进程都是守护进程。
二.实验实现 Kickstart 无人值守安装
安装 tftp-server xinetd dhcp vsftpd syslinux 软件包
[root@localhost ~]# yum install -y tftp-server ?xinetd ?dhcp ?vsftpd ?syslinux
复制 vmlinuz initrd.img pxelinux.0 到 /var/lib/tftpboot/ 目录'
[root@localhost]# cp vmlinuz initrd.img /var/lib/tftpboot/
[root@localhost]# cp pxelinux.0 /var/lib/tftpboot/
在 /var/lib/tftpboot/ 目录里准备 PXE 启动菜单配置文件 pxelinux.cfg/default
[root@localhost tftpboot]# mkdir pxelinux.cfg
[root@localhost tftpboot]# ls
initrd.img pxelinux.0 pxelinux.cfg vmlinuz
[root@localhost tftpboot]# cd pxelinux.cfg/
[root@localhost pxelinux.cfg]# vim default
修改服务配置文件,启动 tftp-server xinetd dhcpd vsftpd 服务
[root@localhost pxelinux.cfg]# vim /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = no
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
[root@localhost ~]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# cd pxelinux.cfg/
[root@localhost pxelinux.cfg]# vim default
default auto
prompt 0
label auto
kernel vmlinuz
append initrd=initrd.img method=ftp://192.168.80.88/centos7 ks=ftp://192.168.80.88/ks.cfg
label linux text
kernel vmlinuz
append text initrd=initrd.img method=ftp://192.168.80.88/centos7 ks=ftp://192.168.80.88/ks.cfg
label linux rescue
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://192.168.80.88/centos7 ks=ftp://192.168.80.88/ks.cfg
[root@localhost pxelinux.cfg]# vim /etc/dhcp/dhcpd.conf
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# option definitions common to all supported networks...
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
# Use this to enble / disable dynamic dns updates globally.
ddns-update-style none;
next-server 192.168.80.88;
filename "pxelinux.0";
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
subnet 10.152.187.0 netmask 255.255.255.0 {
}
# This is a very basic subnet declaration.
subnet 192.168.80.0 netmask 255.255.255.0 {
range 192.168.80.100 192.168.80.200;
option routers 192.168.80.88;
}
# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.
subnet 10.254.239.32 netmask 255.255.255.224 {
range dynamic-bootp 10.254.239.40 10.254.239.60;
option broadcast-address 10.254.239.31;
option routers rtr-239-32-1.example.org;
}
# A slightly different configuration for an internal subnet.
subnet 10.5.5.0 netmask 255.255.255.224 {
range 10.5.5.26 10.5.5.30;
option domain-name-servers ns1.internal.example.org;
option domain-name "internal.example.org";
option routers 10.5.5.1;
option broadcast-address 10.5.5.31;
"/etc/dhcp/dhcpd.conf" 108L, 3280C 10,1 顶端
[root@localhost ~]# systemctl start vsftpd tftp dhcpd xinetd
[root@localhost ~]# systemctl enable --now vsftpd tftp dhcpd xinetd
安装 system-config-kickstart ,准备 kickstart 自动应答文件,修改 PXE 启动菜单配置文件
[root@localhost ~]# yum -y install system-config-kickstart
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
软件包 system-config-kickstart-2.9.7-1.el7.noarch 已安装并且是最新版本
[root@localhost ~]# vim anaconda-ks.cfg
# Network information
network --bootproto=dhcp --device=ens33 --onboot=off --ipv6=auto --no-activate
network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted $6$8wN6Bd7Hn.W/Y5k3$8kd9DI8oejCxQGhhz80ozmzlkDXjap1g09dvLoUEhr/bFdVgZBhAzfAKIBKvDnYXLDzPEtYELwJDPFKP0BD49/
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
user --name=mwq --password=$6$8fFByNktNDFTsn6y$SJQ0h9QKIKYX3S/ZjT5/6gZwmCLIJmiVhCDrFSYWjtEjD9jdG2.TcKIOAMiwsxNuhSdr4XnlxBeRN2qQDfnqg/ --iscrypted --gecos="mwq"
# X Window System configuration information
xconfig --startxonboot
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel
%packages
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@development
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@print-client
@x11
chrony
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
[root@localhost ~]# vim ks.cfg
客户机要求至少内存2G,并设置成网络引导开机
三.PEX操作总结
- 安装4个服务
- xftp(根目录/var/lob’/tftpboot用于传输内核文件和系统镜像引导文件vmlinuz、initrd.img、pxelinux.0、pxelinux.cfg/default)
- xinetd 管理tftp服务的
- dhcp 用户给客户端自动分配IP地址、并指定pxelinux.0文件所在位置
- vsftpd 用于给客户端传输安装源软件包
- 安装4个文件
- vmlinuz(内核文件) initrd.img(系统镜像引导文件) /mnt/images/pxeboot/
- pxelinux.0(PXE程序引导文件) syslinux程序提供
- pxelinux.cfg/default(PXE启动菜单文件) 自建
- 自动应答
- 安装 system-config kickstart 生成自动应答文件 ks.cfg ,方到ftp目录
- 修改 pxelinux.cfg/default 文件,在append行后面添加ks=ftp://...指定ks.cfg文件路径
- 关闭防火墙,VMware的DHCP功能,客户端要求内存2G以上