本文主要介绍通过客户端的网络自动链接服务器的PXE环境实现的客端系统快速安装部署。具体PXE的介绍亲们在网络上自己查找资料学习。
一、基础环境
Centos7.9的服务器一台
Centos7.9的安装光盘(iso文件)
yum install -y syslinux system-config-kickstart
yum groupinstall "GNOME Desktop" -y
二、网络环境
客户端服务器和服务器端服务器之间的80端口和tftp端口能互相通讯
需要能够访问互联网,不是必备条件。
三、部署方法
1、在服务器上搭建DHCP服务
yum install dhcp -y
vim /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
#
subnet 192.168.126.0 netmask 255.255.255.0 {
range 192.168.126.100 192.168.126.200;
option routers 192.168.126.2;
option domain-name-servers 8.8.8.8;
# option domain-name "example.com";
filename "pxelinux.0";
next-server 192.168.126.131; # PXE服务器的IP地址
}
systemctl enable --now dhcpd
2、在服务器上搭建tftp服务
yum install tftd-hpa -y
systemctl enable --now tftp
默认tftp路径:
cd /var/lib/tftpboot/
修改tftp路径:
vi /etc/xinetd.d/tftp
cat /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 = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = yes
per_source = 11
cps = 100 2
flags = IPv4
}
3、通过本地安装光盘获取内核文件
将光盘或ISO文件放入光驱
mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
cd /var/lib/tftpboot/
cp /mnt/cdrom/Packages/syslinux-version-architecture.rpm .
rpm2cpio syslinux-version-architecture.rpm | cpio -dimv
cp usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/pxelinux.0
4、通过本地安装光盘获取img文件
cd /var/lib/tftpboot/
cp /mnt/cdrom/images/pxeboot/initrd.img .
5、在服务器上配置安装引导文件
cd /var/lib/tftpboot/
cp usr/share/syslinux/menu.c32 .
mkdir -p /var/lib/tftpboot/pxelinux/pxelinux.cfg
vi /var/lib/tftpboot/pxelinux/pxelinux.cfg/default
default menu.c32
prompt 1
timeout 600
#menu title PXE Boot Menu
label 1
menu label ^1) Install CentOS 7 (graphical)
kernel vmlinuz
append initrd=initrd.img ip=dhcp inst.repo=hd:UUID=05be16d6-47e1-4dd9-8766-f6d941964f16:/mnt/cdrom method=http://192.168.126.131:8080/centos
label 2
menu label ^2) Install CentOS 7 (auto)
menu default
kernel vmlinuz
append initrd=initrd.img ip=dhcp inst.repo=hd:UUID=05be16d6-47e1-4dd9-8766-f6d941964f16:/mnt/cdrom method=http://192.168.126.131:8080/centos ks=http://192.168.126.131:8080/ks.cfg
6、在服务器上搭建http服务
yum install tomcat -y
vim /etc/tomcat/server.xml
(添加/etc/tomcat/webapps和/mnt/cdrom的两行)
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<Context path="/" docBase="/etc/tomcat/webapps" reloadable="true"></Context>
<Context path="/centos" docBase="/mnt/cdrom" reloadable="true"></Context>
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
vim /etc/tomcat/web.xml
(启用列表功能)
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
7、在服务器上配置安装配置文件
vi /etc/tomcat/webapps/ks.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# System language
lang en_US
# System authorszation information
firstboot --disable
auth --useshadow --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp
# Reboot after installation
# System timezone
rootpw ms@D312
timezone Asia/Shanghai
# Use network installation
url --url="http://192.168.126.131:8080/centos"
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=512
part /home --fstype="xfs" --size=5000
part / --asprimary --fstype="xfs" --grow --size=1
reboot
8、客户端安装配置
修改启动顺序为网络启动,然后就开始自动安装,安装时间大概20分钟,具体根据不同的操作系统而定。