环境准备
关闭虚拟机的SELinux
[root@server ~]# setenforce 0 #修改当前运行模式
[root@server ~]# getenforce #查看当前运行模式
Permissive
[root@server ~]# vim /etc/selinux/config #永久修改
SELINUX=permissive
设置虚拟机防火墙
[root@server ~]# yum -y remove firewalld
[root@server ~]# rpm -q firewalld
● 构建DHCP服务
•Dynamic Host Configuration Protocol
–动态主机配置协议,由 IETF(Internet 网络工程师任务小组)组织制定,用来简化主机地址分配管理
•主要分配以下入网参数
–IP地址/子网掩码/广播地址
–默认网关地址、DNS服务器地址
•DHCP地址分配的四次会话(广播进行,先到先得原理)
–DISCOVERY --> OFFER --> REQUEST -->ACK
在一个网络中,保证只有一台DHCP服务器
•服务端基本概念
–租期:允许客户机租用IP地址的时间期限,单位为秒
–作用域:分配给客户机的IP地址所在的网段
–地址池:用来动态分配的IP地址的范围
● 部署DHCP服务
1.安装软件包dhcp-server
[root@server /]# yum -y install dhcp-server
2.修改主配置文件
[root@server /]# vim /etc/dhcp/dhcpd.conf
末行模式下:r /usr/share/doc/dhcp-server/dhcpd.conf.example #读入其他文本文件内容
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp-server/dhcpd.conf.example
# see dhcpd.conf(5) man page
subnet 192.168.88.0 netmask 255.255.255.0 { #分配的网段
range 192.168.88.100 192.168.88.200; #分配的IP地址范围
option domain-name-servers 8.8.8.8; #分配的DNS服务器地址
option routers 192.168.88.254; #分配的网关地址
default-lease-time 600; #默认的租期时间
max-lease-time 7200; #最大的租期时间
}
[root@server /]# systemctl restart dhcpd
● 网络装机服务器介绍
网络装机的优势
•规模化:同时装配多台主机
•自动化:装系统、配置各种服务
•远程实现:不需要光盘、U盘等物理安装介质
•PXE,Pre-boot eXecution Environment
–预启动执行环境,在操作系统之前运行
–可用于远程安装
•工作模式
–PXE client 集成在网卡的启动芯片中
–当计算机引导时,从网卡芯片中把PXE client调入内存执行,获取PXE server配置、显示菜单,根据用户选择将远程引导程序下载到本机运行
•服务器
–DHCP服务,分配IP地址、定位引导程序
–TFTP服务,提供引导程序下载
–WEB服务或FTP服务,提供yum软件仓库
•客户机应具备的条件
–网卡芯片必须支持PXE协议
–主板支持从网卡启动
PXE网络装机的流程图:
网络装机服务器构建
1)DHCP服务构建
[root@server /]# vim /etc/dhcp/dhcpd.conf
subnet 192.168.88.0 netmask 255.255.255.0 {
range 192.168.88.100 192.168.88.200;
option domain-name-servers 8.8.8.8;
option routers 192.168.88.254;
default-lease-time 600;
max-lease-time 7200;
next-server 192.168.88.240; #下一个服务器为192.168.88.240
filename "pxelinux.0"; #指明网卡引导文件
}
[root@server /]# systemctl restart dhcpd
pxelinux.0:网卡引导文件,网络装机说明书,二进制文件,安装一个软件即可获得
2)TFTP服务
tftp:简单的文本传输协议 默认端口为:udp 69
默认共享数据的路径:/var/lib/tftpboot
1.安装软件包
[root@server /]# yum -y install tftp-server
2.重启服务
[root@server /]# systemctl restart tftp
3.部署pxelinux.0网卡引导文件
[root@server /]# yum provides */pxelinux.0 #查询仓库中那个软件包产生改文件
[root@server /]# yum -y install syslinux-tftpboot
[root@server /]# rpm -ql syslinux-tftpboot | grep pxelinux.0 #查询软件包安装的清单
[root@server /]# cp /tftpboot/pxelinux.0 /var/lib/tftpboot/
[root@server /]# ls /var/lib/tftpboot/
pxelinux.0
3)总结思路:
1.构建DHCP服务:分配IP地址、next-server、filename pxelinux.0
2.构建tftp服务:pxelinux.0
3.pxelinux.0文件:读取菜单文件/var/lib/tftpboot/pxelinux.cfg/default
4)部署菜单文件
]# mkdir /var/lib/tftpboot/pxelinux.cfg
]# ls /var/lib/tftpboot/
]# ls /dvd #查看光盘的内容
]# cp /dvd/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default #复制光盘菜单文件到tftp服务共享目录
]# ls /var/lib/tftpboot/pxelinux.cfg/
5)部署众多引导数据
]# mount /dev/cdrom /dvd
]# ls /dvd
AppStream EFI isolinux media.repo
BaseOS images LICENSE TRANS.TBL
]# cp /dvd/isolinux/* /var/lib/tftpboot
]# ls /var/lib/tftpboot/
boot.cat isolinux.bin libutil.c32 splash.png
boot.msg isolinux.cfg memtest TRANS.TBL
grub.conf ldlinux.c32 pxelinux.0 vesamenu.c32
initrd.img libcom32.c32 pxelinux.cfg vmlinuz
7)菜单文件内容的修改
[root@server ~]# chmod 644 /var/lib/tftpboot/pxelinux.cfg/default
[root@server /]# vim /var/lib/tftpboot/pxelinux.cfg/default
末行模式下 :set nu
1 default vesamenu.c32 #默认加载图形模块
2 timeout 600 #读秒时间 1/10
......内容不变
10 menu background splash.png #背景图片
11 menu title NSD PXE Server #菜单界面的标题
......内容不变
61 label linux
62 menu label NSD install RockyLinux #屏幕显示
63 menu default #读秒写书后,默认的选择,需要手写
64 kernel vmlinuz #加载vmlinuz内核
65 append initrd=initrd.img #加载initrd.img驱动程序
以下内容全部删除
8)总结思路:
1.构建DHCP服务:分配IP地址、next-server、filename pxelinux.0
2.构建tftp服务:pxelinux.0
3.pxelinux.0文件:读取菜单文件/var/lib/tftpboot/pxelinux.cfg/default
4.default菜单文件:众多的引导文件、显示标题、显示菜单......
9)初步测试:
客户端开机启动项
1.硬盘
2.光驱设备
3.U盘或移动存储设备
4.通过网卡发布PXE广播
准备工作,服务启动
[root@server /]# systemctl restart dhcpd
[root@server /]# systemctl restart tftp
关闭VMware虚拟机软件的dhcp功能(为了防止dhcp服务干扰)
修改网络类型
开启虚拟机
10)Web服务,提供光盘内容
注意虚拟Web主机的影响
[root@server /]# yum -y install httpd
[root@server /]# systemctl restart httpd
[root@server /]# mkdir /var/www/html/rockylinux
[root@server /]# mount /dev/cdrom /var/www/html/rockylinux
mount: /dev/sr0 写保护,将以只读方式挂载
[root@server /]# ls /var/www/html/rockylinux
真机图形浏览器 http://192.168.88.240/rockylinux #图形浏览
11)部署无人值守安装,生成应答文件
[root@localhost ~]# cat /var/www/html/ks.cfg
#version=RHEL8
# System language
lang en_US.UTF-8
# Keyboard layout
keyboard us
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# Root password (use a secure, hashed password in production)
#rootpw --iscrypted $6$randomsalt$hashedpassword
rootpw --plaintext a
# System timezone
timezone Asia/Shanghai --isUtc
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
# Clear all existing partitions and initialize the disk label
clearpart --all --initlabel
# Disk partitioning information
#part /boot --fstype=xfs --size=1024
part / --fstype=xfs --grow --size=1
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled
# Do not configure the X Window System (this is for text-based installations; we want graphical)
# skipx
graphical
# Reboot after installation
reboot
# Install OS instead of upgrade
install
# Use network installation
url --url="http://192.168.88.240/rockylinux"
# System authorization information
auth --useshadow --passalgo=sha512
# Run the Setup Agent on first boot
firstboot --disable
# System services
services --enabled=sshd,chronyd
# Percentage of packages to be upgraded at first boot
#percentage 95
# Package groups to install
%packages
@^minimal-environment
%end
# Pre-installation script
%pre
#!/bin/bash
echo "Pre-installation script is running."
# Add your pre-installation commands here
%end
# Post-installation script
%post
#!/bin/bash
echo "Post-installation script is running."
yum -y remove firewalld
useradd zhangsan
echo 123 | passwd --stdin zhangsan
# Add your post-installation commands here
%end
修改菜单文件,指定应答文件
[root@server /]# vim /var/lib/tftpboot/pxelinux.cfg/default
........上面内容不变
61 label linux
62 menu label NSD install RockyLinux
63 menu default
64 kernel vmlinuz
65 append initrd=initrd.img ks=http://192.168.88.240/ks.cfg
以下内容全部删除
13)测试
重启所需的服务
[root@server /]# systemctl restart dhcpd
[root@server /]# systemctl restart tftp
[root@server /]# systemctl restart httpd
[root@server /]# ls /var/www/html/rockylinux #查看是否有光盘内容
总结思路:
1.构建DHCP服务:分配IP地址、next-server、filename pxelinux.0
2.构建tftp服务:pxelinux.0
3.pxelinux.0文件:读取菜单文件/var/lib/tftpboot/pxelinux.cfg/default
4.default菜单文件:vesamenu.c32、splash.png 、显示标题、显示菜单、ks应答文件......
5.ks应答文件:支持的语言、分区、root密码、获取软件包方式........