一、准备工作
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.16.1.1/24 ipv4.method manual connection.autoconnect yes
nmcli connection up ens33
二、安装必要服务
所需服务(dhcp、tftp、xinetd、http、syslinux)
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.16.1.0 netmask 255.255.255.0 {
range 172.16.1.100 172.16.1.200; # 可分配的起始IP-结束IP
option subnet-mask 255.255.255.0; #子网掩码
default-lease-time 21600; #默认超时时间
max-lease-time 43200; #最大超时时间
next-server 172.16.1.1; #指定下一条服务器地址
filename "/pxelinux.0"; #引导文件名
}
查看软件监听端口
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.安装syslinux
yum -y install syslinux
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ #复制引导文件到启动根目录
cp -a /var/www/html/CentOS-7.9/isolinux/* /var/lib/tftpboot/ #复制微内核到启动根目录
mkdir -p /var/lib/tftpboot/pxelinux.cfg #创建配置文件目录(pxelinux.cfg是目录)
cp /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default #复制启动配置文件
vim /var/lib/tftpboot/pxelinux.cfg/default #修改启动配置文件
启动配置文件样板
default centos7
promet 0
timeout 60
display boot.msg
# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title CentOS 7
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13
# Border Area
menu color border * #00000000 #00000000 none
# Selected item
menu color sel 0 #ffffffff #00000000 none
# Title bar
menu color title 0 #ff7ba3d0 #00000000 none
# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none
# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none
# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none
# Unselected hotkey
menu color hotkey 0 #ffffffff #00000000 none
# Help text
menu color help 0 #ffffffff #00000000 none
# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none
# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none
# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none
# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.
menu tabmsg Press Tab for full configuration options on menu items.
menu separator # insert an empty line
menu separator # insert an empty line
label centos7
menu default
kernel vmlinuz
append initrd=initrd.img inst.stage2=http://172.16.1.1/CentOS-7.9/ks=http://172.16.1.1/centos7-ks/anaconda-ks.cfg
label linux
menu label ^Install CentOS 7
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet
label check
menu label Test this ^media & install CentOS 7
menu default
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet
menu separator # insert an empty line
# utilities submenu
menu begin ^Troubleshooting
menu title Troubleshooting
label vesa
menu indent count 5
menu label Install CentOS 7 in ^basic graphics mode
text help
Try this option out if you're having trouble installing
CentOS 7.
endtext
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 xdriver=vesa nomodeset quiet
label rescue
menu indent count 5
menu label ^Rescue a CentOS system
text help
If the system will not boot, this lets you access files
and edit config files to try to get it booting again.
endtext
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rescue quiet
label memtest
menu label Run a ^memory test
text help
If your system is having issues, a problem with your
system's memory may be the cause. Use this utility to
see if the memory is working correctly.
endtext
kernel memtest
menu separator # insert an empty line
label local
menu label Boot from ^local drive
localboot 0xffff
menu separator # insert an empty line
menu separator # insert an empty line
label returntomain
menu label Return to ^main menu
menu exit
menu end
创建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.16.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
%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服务
[root@localhost centos7-ks] systemctl enable httpd
[root@localhost centos7-ks] systemctl start httpd
配置完成