1、简介
使用pxe+tftp+ftp+dhcp+Kickstart安装部署系统
基本原理:
-
DHCP:为客户端分配IP地址(注意,必须要使用服务器搭建DHCP服务,不可以使用网络中的其他DHCP服务器);
-
TFTP:使用UDP(简单文件传输协议)为客户端提供引导及驱动,当客户端有了引导及驱动后使用vsftpd传输完整镜像给客户端;
-
SYSLinux:用于提供引导加载的服务程序,其包含很多引导文件及文件夹,引导文件位于/usr/share/syslinux/目录中;
-
Vsftpd:用于给客户端传输完整的镜像文件;
-
创建Kickstart应答文件。
-
部署环境:
服务器地址:10.168.1.10
注意事项:关闭selinux和firewalld
2、部署DHCP服务
安装dhcp-server服务:
yum install -y dhcp-server
修改DHCP服务配置:
vim /etc/dhcp/dhcpd.conf
allow booting;
allow bootp;
ddns-update-style none;
ignore client-updates;
subnet 10.168.1.0 netmask 255.255.255.0 {
option subnet-mask 255.255.255.0; #子网掩码
option routers 10.168.1.1; #定义客户端网关
option domain-name-servers 10.168.1.10; #定义客户端DNS(DHCP服务器)
range dynamic-bootp 10.168.1.100 10.168.1.200; #分配IP范围
default-lease-time 21600; #租期
max-lease-time 43200; #最大预约时间
next-server 10.168.1.10; #DHCP服务器地址
filename "pxelinux.0";
}
注:当前pxelinux.0文件不存在,后面部署syslinux时会创建
启动并加入开机启动项
systemctl start dhcpd #启动dhcp服务 systemctl enable dhcpd #将dhcp服务加入开机启动项 systemctl status dhcpd #查看dhcp运行状态
3、部署TFTP服务
安装TFTP服务
yum install -y tftp-server xinetd
创建配置文件
vim /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no #需要开启TFTP服务时,只需要在xinetd服务程序的配置文件中把disable参数改为no
per_source = 11
cps = 100 2
flags = IPv4
}
启动并加入开机启动项
systemctl start xinetd systemctl enable xinetd 如最后程序启动后不成功,则需要手动启动tftp服务: systemctl start tftp.server systemctl enable tftp.server
4、部署SYSlinux服务
安装syslinux服务
yum install -y syslinux
将syslinux提供的引导文件"pxelinux.0"复制到TFTP默认目录中,另外还需要将光盘系统镜像中的引导文件复制到TFTP默认目录中。
挂载光盘
首先在media下创建cdrom目录然后挂载 mkdir /media/cdrom mount /dev/cdrom /media/cdrom
复制引导文件
cd /media/cdrom/ cp -a /usr/share/syslinux/pxelinux.0/ ./ cp -a /media/cdrom/images/pxeboot/* ./ cp -a /media/cdrom/isolinux/* ./ 若多目录保存着相同的文件,则手动敲击y进行覆盖即可。
开机菜单中有3个选项:安装系统、对安装介质进行检验、排错模式。
编辑default:
-
将第1行“default”改为“linux”,这样系统开机后会默认执行名称为linux的选项。
-
将第64行:默认的光盘安装方式修改为ftp传输方式,并制定好系统镜像ftp获取路径和Kickstart应答文件的获取路径。
append initrd=initrd.img inst.stage2=ftp://10.168.1.10 ks=ftp://10.168.1.10/pub/ks.cfg quiet
cd /media/cdrom/ mkdir pxelinux.cfg cp ./isolinux.cfg ./pxelinux.cfg/default
1 default linux #将“default”改为“linux”
2 timeout 600
3
4 display boot.msg
5
6 # Clear the screen when exiting the menu, instead of leaving the menu displayed.
7 # For vesamenu, this means the graphical background is still displayed without
8 # the menu itself for as long as the screen remains in graphics mode.
9 menu clear
10 menu background splash.png
11 menu title Red Hat Enterprise Linux 8.0.0
12 menu vshift 8
13 menu rows 18
14 menu margin 8
15 #menu hidden
16 menu helpmsgrow 15
17 menu tabmsgrow 13
18
19 # Border Area
20 menu color border * #00000000 #00000000 none
21
22 # Selected item
23 menu color sel 0 #ffffffff #00000000 none
24
25 # Title bar
26 menu color title 0 #ff7ba3d0 #00000000 none
27
28 # Press [Tab] message
29 menu color tabmsg 0 #ff3a6496 #00000000 none
30
31 # Unselected menu item
32 menu color unsel 0 #84b8ffff #00000000 none
33
34 # Selected hotkey
35 menu color hotsel 0 #84b8ffff #00000000 none
36
37 # Unselected hotkey
38 menu color hotkey 0 #ffffffff #00000000 none
39
40 # Help text
41 menu color help 0 #ffffffff #00000000 none
42
43 # A scrollbar of some type? Not sure.
44 menu color scrollbar 0 #ffffffff #ff355594 none
45
46 # Timeout msg
47 menu color timeout 0 #ffffffff #00000000 none
48 menu color timeout_msg 0 #ffffffff #00000000 none
49
50 # Command prompt text
51 menu color cmdmark 0 #84b8ffff #00000000 none
52 menu color cmdline 0 #ffffffff #00000000 none
53
54 # Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.
55
56 menu tabmsg Press Tab for full configuration options on menu items.
57
58 menu separator # insert an empty line
59 menu separator # insert an empty line
60
61 label linux
62 menu label ^Install Red Hat Enterprise Linux 8.0.0
63 kernel vmlinuz
64 append initrd=initrd.img inst.stage2=ftp://10.168.1.10 ks=ftp://10.168.1.10/pub/ks.cfg quiet #默认的光盘安装方式修改为ftp传输方式并制定好系统镜像ftp获取路径和Kickstart应答文件的获取路径。
65
66 label check
67 menu label Test this ^media & install Red Hat Enterprise Linux 8.0.0
68 menu default
69 kernel vmlinuz
70 append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-8-0-0-BaseOS-x86_64 rd.live.check quiet
71
72 menu separator # insert an empty line
73
74 # utilities submenu
75 menu begin ^Troubleshooting
76 menu title Troubleshooting
77
78 label vesa
79 menu indent count 5
80 menu label Install Red Hat Enterprise Linux 8.0.0 in ^basic graphics mode
81 text help
82 Try this option out if you're having trouble installing
83 Red Hat Enterprise Linux 8.0.0.
84 endtext
85 kernel vmlinuz
86 append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-8-0-0-BaseOS-x86_64 nomodeset quiet
87
88 label rescue
89 menu indent count 5
90 menu label ^Rescue a Red Hat Enterprise Linux system
91 text help
92 If the system will not boot, this lets you access files
93 and edit config files to try to get it booting again.
94 endtext
95 kernel vmlinuz
96 append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-8-0-0-BaseOS-x86_64 rescue quiet
97
98 label memtest
99 menu label Run a ^memory test
100 text help
101 If your system is having issues, a problem with your
102 system's memory may be the cause. Use this utility to
103 see if the memory is working correctly.
104 endtext
105 kernel memtest
106
107 menu separator # insert an empty line
108
109 label local
110 menu label Boot from ^local drive
111 localboot 0xffff
112
113 menu separator # insert an empty line
114 menu separator # insert an empty line
115
116 label returntomain
117 menu label Return to ^main menu
118 menu exit
119
120 menu end
踩过的坑:注意地址填写正确
5、部署vsftpd服务
安装
yum install -y vsftpd
修改配置文件
vsftpd默认关闭匿名访问,需要手动开启匿名访问:
修改第12行:NO改为YES
12 anonymous_enable=YES
启动并加入开机启动项
systemctl start vsftpd systemctl enable vsftpd
确认系统镜像光盘已经挂载,将光盘中的全部文件复制到vsftp共享目录中:
cp -a /media/cdrom/* /var/ftp/ 此过程大概需要3-5分钟
6、创建Kickstart应答文件
此文件可以帮客户端填写安装过程中出现的选项,而不用单独每一台都去使用鼠标进行点点点操作。
cp ~/anaconda-ks.cfg /var/ftp/pub/ks.cfg chmod 644 /var/ftp/pub/ks.cfg
修改配置文件
vim /var/ftp/pub/ks.cfg
-
1~10行表示硬盘名称为sda及使用LVM技术(虚拟机环境中硬盘一定要选scsi或sata类型,否则找不到硬盘导致安装失败)
-
第2行注意硬盘的类型
-
第8行的软件仓库改为ftp提供的网络路径
-
第10行安装源也需要将CDROM改为ftp网络安装源
1 #version=RHEL8
2 ignoredisk --only-use=sda
3 autopart --type=lvm
4 # Partition clearing information
5 clearpart --none --initlabel
6 # Use graphical install
7 graphical
8 repo --name="AppStream" --baseurl=ftp://10.168.1.10/AppStream
9 # Use CDROM installation media
10 url --url=ftp://10.168.1.10/BaseOS
-
11-20行注意第12行和第17行
-
第12行可修改系统语言,'us'为英文'zh'为中文
-
第17行网卡信息将bootproto改为dhcp模式,将noboot改为on
-
第20行为root用户密码的密文,可复制/etc/shadow中的加密密文(以下笔记中密文的root密码为 123. )
11 # Keyboard layouts
12 keyboard --vckeymap=us --xlayouts='us'
13 # System language
14 lang en_US.UTF-8
15
16 # Network information
17 network --bootproto=dhcp --device=ens160 --onboot=on --ipv6=auto --no-activate
18 network --hostname=localhost
19 # Root password
20 rootpw --iscrypted $6$0J58TQ7KPHSoMWw7$iWVKSUaMRY0sR9MNxhTd8HgN0n3twPZmXUyzhzgDhty5CRFm kZ84hv59Z4XcppPyZZfUfxlXAIhn8f/ui0UBV1
-
第21-30行timezone定义系统默认时区为“亚洲/上海”(Asia/Shanghai)
-
第29行为创建普通用户的信息,密钥等解释如上root用户
21 # X Window System configuration information
22 xconfig --startxonboot
23 # Run the Setup Agent on first boot
24 firstboot --enable
25 # System services
26 services --disabled="chronyd"
27 # System timezone
28 timezone Asia/Shanghai --isUtc --nontp
29 user --name=admin --password=$6$0J58TQ7KPHSoMWw7$iWVKSUaMRY0sR9MNxhTd8HgN0n3twPZmXUyzhz gDhty5CRFmkZ84hv59Z4XcppPyZZfUfxlXAIhn8f/ui0UBV1 --iscrypted --gecos="admin"
30
-
31~44行表示软件来源,graphical-server-environment代表图形化界面服务器环境,对应安装界面中的Server With GUI
31 %packages
32 @^graphical-server-environment
33 @rpm-development-tools
34 kexec-tools
35
36 %end
37
38 %addon com_redhat_kdump --enable --reserve-mb='auto'
39
40 %end
41
42 %anaconda
43 pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
44 pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
45 pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
46 %end
7、虚拟机部署客户端需要注意的事项




虚拟机网络模式设为NAT,使其服务端和客户端在同一网络中,关闭虚拟机的DHCP。
按上述创建虚拟机后开启虚拟机,不需要任何操作,等待虚拟机安装完成。
centos8中最后客户端安装完成后需要手动重启并勾选许可
本文详细介绍了如何通过PXE、TFTP、DHCP和Kickstart服务,配合FTP服务器,实现自动化部署CentOS系统的步骤。包括安装和配置DHCP服务、TFTP服务、SYSlinux、vsftpd服务,以及创建Kickstart应答文件,最终实现客户端无交互式安装。
5万+





