PXE装机

1、关闭防火墙 SELLIUNX

1
2
3
4
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

2、安装软件

1
2
yum -y install tftp-server httpd  dhcp
yum install syslinux -y

3、配置dhcp

1
2
3
4
5
6
7
8
cat /etc/dhcp/dhcpd.conf 
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.200 ;
default-lease-time 600;
max-lease-time 7200;
next-server 192.168.1.10;# 指明tftp服务器的地址
filename "pxelinux.0";# 指明PXE文件位置,这个在申请ip的时候会发送给安装主机
}

4、配置tftp服务器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@localhost xinetd.d]# pwd
/etc/xinetd.d
[root@localhost xinetd.d]# cat 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 = no #改成no
per_source = 11
cps = 100 2
flags = IPv4
}
sed -i '/disable/c\\tdisable\t\t\t=no' /etc/xinetd.d/tftp
[root@localhost xinetd.d]# systemctl restart tftp.socket
[root@localhost xinetd.d]# systemctl status tftp.socket

5、复制引导文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cd /var/lib/tftpboot/
引导文件
cp /usr/share/syslinux/pxelinux.0 ./
菜单文件
cp /usr/share/syslinux/menu.c32 ./

挂载镜像
mount /dev/sdg /media/cdrom/
# 安装引导文件
cp /media/cdrom/isolinux/vmlinuz ./
cp /media/cdrom/isolinux/initrd.img ./
[root@localhost tftpboot]# ls
initrd.img menu.c32 pxelinux.0 vmlinuz


6、制作安装菜单

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@localhost tftpboot]# mkdir pxeliunx.cfg
[root@localhost tftpboot]# ls
initrd.img menu.c32 pxelinux.0 pxeliunx.cfg vmlinuz
[root@localhost pxeliunx.cfg]# touch default
编辑文件
[root@localhost pxeliunx.cfg]# cat default
default menu.c32
timeout 100
prompt 0

label 1
menu lable ^1) Install Pai_CentOS7_1.5.1
menu default
kernel vmliunz
append initrd=initrd.img method=http://172.16.1.18/Centos7 ks=http://172.16.1.18/ks.cfg

7、配置web服务器

1
2
3
4
5
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# mkdir Centos7
cp -r /media/cdrom/* /var/www/html/Centos7/
# 挂载也可以

1
2
3
4
5
6
7
8
[root@localhost ~]# cp anaconda-ks.cfg /var/www/html/
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
anaconda-ks.cfg Centos7
[root@localhost html]# mv anaconda-ks.cfg ks.cfg
[root@localhost html]# ls
Centos7 ks.cfg
[root@localhost html]# chmod +r ks.cfg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
[root@localhost html]# cat ks.cfg 
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
#cdrom
# 通过网络安装
url --url http://172.16.1.18/Centos7

# Use graphical install
#graphical
#禁用图形化安装 通过文本安装
text

# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang zh_CN.UTF-8

# Network information
network --bootproto=dhcp --device=eno1 --onboot=off --ipv6=auto --no-activate
network --bootproto=dhcp --device=eno2 --onboot=off --ipv6=auto
network --bootproto=dhcp --device=enp6s0f0 --onboot=off --ipv6=auto
network --bootproto=dhcp --device=enp6s0f1 --onboot=off --ipv6=auto
network --hostname=localhost.localdomain

# Root password
rootpw --iscrypted $6$IKZAiSjkoRXBNe5W$KXOQ0jbavV4LHxDJ20OQQ.2Sx1ywBkfJOhVAWwJ05lz1BnKrpSppFUGJI2mU/a/qMKXfFufSqtmxYEPniGqx81
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
# 只初始化系统盘 sda
clearpart --all --initlabel --drives=sda

%packages
@^minimal
@core
chrony

%end

%addon com_redhat_kdump --disable --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

# 重启
reboot

8、重启所有服务器

1
2
3
4
5
6
7
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart tftp.socket
[root@localhost ~]# systemctl restart dhcpd
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# systemctl enable tftp.socket
[root@localhost ~]# systemctl enable dhcpd