使用PXE+Kickstart无人值守安装Linux操作系统
本章主要使用PXE+DHCP+TFTP+SYSLinux+VSftpd+Kickstart服务程序搭建无人值守安装系统,从而批量部署客户机,实现自动化运维,避免重复性工作,提升工作效率。
1、配置DHCP服务
[root@linuxprobe ~]# yum install -y dhcp
Installed:
dhcp.x86_64 12:4.2.5-27.el7
[root@linuxprobe ~]# cat /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
#
allow booting;
allow bootp;
ddns-update-style interim;
ignore client-updates;
subnet 192.168.171.0 netmask 255.255.255.0{
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.171.1;
range dynamic-bootp 192.168.171.100 192.168.171.200;
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.171.128;
filename "pxelinux.0";
}
[root@linuxprobe ~]# systemctl restart dhcpd
[root@linuxprobe ~]# systemctl enable dhcpd
[root@linuxprobe ~]# firewall-cmd --permanent --add-service=dhcp
success
[root@linuxprobe ~]# firewall-cmd --reload
success
2、配置TFTP服务
[root@linuxprobe ~]# yum install -y tftp-server
Installed:
tftp-server.x86_64 0:5.2-11.el7
Dependency Installed:
xinetd.x86_64 2:2.3.15-12.el7
[root@linuxprobe ~]# 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
per_source = 11
cps = 100 2
flags = IPv4
}
[root@linuxprobe ~]# systemctl restart xinetd
[root@linuxprobe ~]# systemctl enable xinetd
[root@linuxprobe ~]# firewall-cmd --permanent --add-port=69/udp
success
[root@linuxprobe ~]# firewall-cmd --reload
success
3、配置SYSLinux服务
[root@linuxprobe ~]# yum install -y syslinux
Installed:
syslinux.x86_64 0:4.05-8.el7
[root@linuxprobe ~]# cd /var/lib/tftpboot/
[root@linuxprobe tftpboot]# cp /usr/share/syslinux/pxelinux.0 .
[root@linuxprobe tftpboot]# cp /media/cdrom/images/pxeboot/{vmlinuz,initrd.img} .
[root@linuxprobe tftpboot]# cp /media/cdrom/isolinux/{vesamenu.c32,*.msg} .
[root@linuxprobe tftpboot]# mkdir pxelinux.cfg
[root@linuxprobe tftpboot]# cp /media/cdrom/isolinux/isolinux.cfg pxelinux.cfg/default
[root@linuxprobe tftpboot]# vim pxelinux.cfg/default
1 default linux
64 append initrd=initrd.img inst.stage2=ftp://192.168.171.128 ks=ftp://192.168.171.128/pub/ks.cfg quiet
70 append initrd=initrd.img inst.stage2=ftp://192.168.171.128 rd.live.check ks=ftp://192.168.171.128/pub/ks.cfg quiet
4、配置VSFtpd服务
[root@linuxprobe tftpboot]# yum install -y vsftpd
Installed:
vsftpd.x86_64 0:3.0.2-9.el7
[root@linuxprobe tftpboot]# systemctl restart vsftpd
[root@linuxprobe tftpboot]# systemctl enable vsftpd
[root@linuxprobe tftpboot]# firewall-cmd --permanent --add-service=ftp
success
[root@linuxprobe tftpboot]# firewall-cmd --reload
success
[root@linuxprobe tftpboot]# cp -r /media/cdrom/* /var/ftp/
[root@linuxprobe tftpboot]# setsebool -P ftpd_connect_all_unreserved=on
将光盘镜像文件内容复制到FTP目录中,确保光盘已经挂载到/media/cdrom目录。
5、创建KickStart服务
[root@linuxprobe ~]# cp ~/anaconda-ks.cfg /var/ftp/pub/ks.cfg
[root@linuxprobe ~]# chmod +r /var/ftp/pub/ks.cfg
[root@linuxprobe ~]# vim /var/ftp/pub/ks.cfg
6 url --url=ftp://192.168.171.128
21 timezone Asia/Shanghai --isUtc
28 clearpart --all --initlabel