1.安装第三方源。
sudo yum install -y epel-release #安装epel源,可能有部分软件安装需要依赖三方源
yum repolist all
2.关闭防火墙。
systemctl disable firewalld
systemctl stop firewalld
3.关闭SElinux。
setenforce 0
vim /etc/selinux/config
config文件配置模板
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled #永久关闭selinux
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
4.服务器配置地址(确保网络环境中没有dhcp服务器)
配置地址举例,pxe用网卡无需配置网关
nmcli connection modify ens33 ipv4.addresses 172.17.1.1/24 ipv4.method manual\
connection.autoconnect yes
nmcli connection up ens33
5.安装必要服务
所需服务(dhcp、tftp、xinetd、http)
1.安装DHCP
yum -y install dhcp
vim /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
#
subnet 172.17.1.0 netmask 255.255.255.0 {
range 172.17.1.100 172.17.1.200; # 可分配的起始IP-结束IP
option subnet-mask 255.255.255.0;
default-lease-time 21600;
max-lease-time 43200;
next-server 172.17.1.1;
filename "BOOTX64.EFI";
}
查看软件监听端口
netstat -tunlp |grep dhcpd
查询端口的服务
grep 67 /etc/services
启动dhcp开机自启
systemctl start dhcpd
systemctl enable dhcpd
查询状态
[root@template ~]# systemctl status dhcpd
● dhcpd.service - DHCPv4 Server Daemon
Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2021-11-24 03:58:32 PST; 18h ago
Docs: man:dhcpd(8)
man:dhcpd.conf(5)
Main PID: 1001 (dhcpd)
Status: "Dispatching packets..."
CGroup: /system.slice/dhcpd.service
└─1001 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid
Nov 24 08:07:51 template dhcpd[1001]: DHCPREQUEST for 172.16.1.107 (172.16.1.1) from 00:0c:29:94:3c:74 via ens36
Nov 24 08:07:51 template dhcpd[1001]: DHCPACK on 172.16.1.107 to 00:0c:29:94:3c:74 via ens36
Nov 24 10:08:30 template dhcpd[1001]: Wrote 0 class decls to leases file.
Nov 24 10:08:30 template dhcpd[1001]: Wrote 0 deleted host decls to leases file.
Nov 24 10:08:30 template dhcpd[1001]: Wrote 0 new dynamic host decls to leases file.
Nov 24 10:08:30 template dhcpd[1001]: Wrote 8 leases to leases file.
Nov 24 21:23:25 template dhcpd[1001]: Wrote 0 class decls to leases file.
Nov 24 21:23:25 template dhcpd[1001]: Wrote 0 deleted host decls to leases file.
Nov 24 21:23:25 template dhcpd[1001]: Wrote 0 new dynamic host decls to leases file.
Nov 24 21:23:25 template dhcpd[1001]: Wrote 8 leases to leases file.
Hint: Some lines were ellipsized, use -l to show in full.
[root@template ~]#
2.安装tftp
yum -y install tftp-server
yum -y install xinetd
查看tftp配置文件
vim /etc/xinetd.d/tftp
修改disable yes改成no
# 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 = no
per_source = 11
cps = 100 2
flags = IPv4
}
启动tftp开机自启
systemctl start tftp
systemctl enable tftp
systemctl enable xinetd
systemctl start xinetd
3.安装HTTP服务
yum -y install httpd
创建页面文件夹
mkdir /var/www/html/CentOS-7.9
挂载或者cp镜像文件到文件夹中
mount /dev/sr0 /var/www/html/CentOS-7.9/
4.生成需要的文件
cp -R /var/www/html/CentOS-7.9/EFI/BOOT/* /var/lib/tftpboot/ #复制引导文件到启动根目录
cp /var/www/html/CentOS-7.9/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/ #复制微内核到启动根目录
vim /var/lib/tftpboot/grub.cfg
启动配置文件样板
set default="1"
set timeout=3
menuentry 'Install CentOS 7' {
linuxefi /vmlinuz inst.stage2=http://172.17.1.1/CentOS-7.9/ks=http://172.17.1.1/centos7-ks/anaconda-ks.cfg
initrdefi /initrd.img
}
重启tftp服务
systemctl restart tftp
创建ks文件目录
mkdir /var/www/html/centos7-ks
创建ks文件 (以下为模板)
vim /var/www/html/centos7-ks/anaconda-ks.cfg
#version=DEVEL
# System authorization information
auth --useshadow --enablemd5
# Install OS instead of upgrade
install
# Use CDROM installation media
selinux --disable
cdrom
# Use graphical install
graphical
# Firewall configuration
firewall --disable
firstboot --disable
ignoredisk --only-use=sda
url --url=http://172.17.1.1/CentOS-7.9
# Keyboard layouts
# old format: keyboard us
# new format:
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# Network information
network --bootproto=dhcp --device=link --activate
network --hostname=localhost.localdomain
# Reboot after installation
reboot
# Root password
rootpw --iscrypted $1$iTFW6UOe$0XOVKpliRfFku6ZHN7GEe/
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
# X Window System configuration information
xconfig --startxonboot
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part swap --fstype="swap" --size=4096
part /boot --fstype="xfs" --size=1024
part / --fstype="xfs" --size=10240 --grow
part /boot/efi --fstype="xfs" --size 1024
%post
%end
%packages
@base
@core
@desktop-debugging
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@print-client
@x11
binutils
chrony
ftp
gcc
kernel-devel
kexec-tools
make
open-vm-tools
patch
python
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
启动http服务
systemctl enable httpd
systemctl start httpd
配置完成
##ARM操作系统注意引导文件位置可能在image目录
##ARM操作系统注意grub.cfg文件可能不是linuxefi initrdefi而是linux initrd
set default="1"
set timeout=3
menuentry 'Install CentOS 7' {
linux /vmlinuz inst.stage2=http://172.17.1.1/CentOS-7.9/ ks=http://172.17.1.1/centos7-ks/anaconda-ks.cfg
initrd /initrd.img
}