第一部分:基本流程梳理及准备工作
一、执行 PXE + KickStart安装需要准备内容:
• DHCP 服务器用来给客户机分配IP;
• TFTP 服务器用来存放PXE的相关文件,比如:系统引导文件;
• FTP 服务器用来存放系统安装文件;
• KickStart所生成的ks.cfg配置文件;
• 带有一个 PXE 支持网卡的将安装的主机;
二、安装ftp服务以及开启服务,设置为开机自动启动。
[root@localhost ~]# yum install vsftpd -y
[root@localhost ~]# systemctl start vsftpd
[root@localhost ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
三、安装TFTP,修改tftp配置文件及开启服务
[root@localhost ~]# yum install tftp tftp-server xinetd -y
配置tftp服务器:
[root@localhost ~]# vim /etc/xinetd.d/tftp
修改配置文件里面的13,14行。改成以下内容:
其中,server_args = -s /tftpboot是tftp服务器运行时的参数。
-s /tftpboot表示服务器默认的目录是 /tftpboot,当你执行put a.txt时,文件会被放到服务器的/tftpboot/a.txt,省去你敲put a /tftpboot/的麻烦。你也可以加其它服务器运行参数到这,具体可以执行man tftpd命令查阅。
-c :上传文件时,服务器上没有。就自动创建这个文件。
默认tftp客户端,只能上传tftp服务器已经有的文件。也就是只能传上去并覆盖服务器上的原文件。如果想上传原来目录中没有的文件,需要修改tftp服务器的配置文件并重起服务。需要修改如下:
打开/etc/xinetd.d/tftp文件,在 server_args 增加-c参数,如下所示:
server_args = -s /tftpboot -c
四、接着重新启动xinetd服务,然后查看服务端口是否打开。
[root@localhost ~]# systemctl start xinetd
[root@localhost ~]# netstat -antup | grep 69 #这种方法,只能看到xinetd进程
udp 0 0 0.0.0.0:69 0.0.0.0:* 3582/xinetd
[root@localhost ~]# lsof -i :69 #查看69端口正在被哪个进程使用
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
xinetd 1774 root 5u IPv4 31184 0t0 UDP *:tftp
五、安装dhcp,修改配置文件及开启服务:
[root@localhost ~]# yum install dhcp -y
配置DHCP服务器:
[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf #生成配置文件
cp: overwrite `/etc/dhcp/dhcpd.conf’? y
六、给DHCP服务器添加一张VMNET4网卡,ip设置为192.168.3.10(只要是3网段都行)
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:c7:5e:ed brd ff:ff:ff:ff:ff:ff
inet 192.168.0.111/24 brd 192.168.0.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fec7:5eed/64 scope link
valid_lft forever preferred_lft forever
3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:c7:5e:f7 brd ff:ff:ff:ff:ff:ff
inet6 fe80::b920:d283:f0a3:5552/64 scope link
valid_lft forever preferred_lft forever
[root@localhost ~]# ifconfig ens37 192.168.3.10/24
七、修改DHCP配置文件
[root@localhost ~]#vi /etc/dhcp/dhcpd.conf #只保留一个subnet {。。。} ,取掉其它subnet,改成如下内容:
subnet 192.168.3.0 netmask 255.255.255.0 {
range 192.168.3.100 192.168.3.200;
option domain-name-servers 192.168.3.1;
option domain-name "internal.example.org";
option routers 192.168.3.1;
option broadcast-address 192.168.3.255;
default-lease-time 600;
max-lease-time 7200;
next-server 192.168.3.10;
filename "pxelinix.0";
}
配置完,先不启动DHCP ,等所有的软件安装好,最后来启动。
第二部分:配置使用PXE启动所需的相关文件
一、安装kickstart软件
[root@localhost ~]# yum -y install system-config-kickstart syslinux
验证中: freetype-2.4.11-15.el7.x86_64 132/132
已安装:
syslinux.x86_64 0:4.05-15.el7 system-config-kickstart.noarch 0:2.9.7-1.el7
二、准备tftp需要共享出去的文件
[root@localhost ~]# mkdir /tftpboot
[root@localhost ~]# mkdir /tftpboot/pxelinux.cfg
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /tftpboot/
[root@localhost ~]# cp /media/images/pxeboot/initrd.img /tftpboot/
[root@localhost ~]# cp /media/images/pxeboot/vmlinuz /tftpboot/
[root@localhost ~]# cp /media/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default (该文件的权限需要为644)
三、修改default,指定安装操作系统的方式和ks.cfg文件路径
[root@localhost ~]# vim /tftpboot/pxelinux.cfg/default
修改第1行 default vesamenu.c32 为第61行 label linux 中的linux ,即 default linux 目的是避免标签选择,直接指定为linux标签
修改第64 行 append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet 为 append initrd=initrd.img inst.repo=ftp://192.168.3.10/pub inst.ks=ftp://192.168.3.10/ks.cfg
四、重新挂载本地光盘到/var/ftp/pub/目录,设置无人值守安装需要的配置参数
1、挂载光盘
[root@localhost ~]#mount /dev/sr0 /var/ftp/pub/
2、配置生成启动自动应答文件
[root@localhost ~]# system-config-kickstart #执行system-config-kickstart弹出来界面。
设置自己后期无人执守安装需要配置的参数:
注意:用xshell远程连接,执行上面的命令可能无法弹出选择框,
报错信息如下:
[root@localhost ~]# system-config-kickstart
Could not open display because no X server is running.
Try running 'system-config-kickstart --help' for a list of options.
需要这样解决:
安装gdm图形化支持插件。 当然也可以安装图像化组件
[root@localhost ~]# yum install -y gdm
验证中 : python-gobject-base-3.22.0-1.el7.x86_64 144/144
已安装:
gdm.x86_64 1:3.28.2-12.el7_6.1
使用Xstart连接主机
3、制作kickstart的无人值守安装文件
4、配置本地yum源
[root@localhost ~]# cd /etc/yum.repos.d/
[root@xuegod63 yum.repos.d]# ls
CentOS-Base.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo epel.repo
CentOS-Base.repo.old CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo epel-testing.repo
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv *.repo bak/
[root@localhost yum.repos.d]# vim my.repo
[cenos7]
name=CentOS7-DVD
baseurl=file:///var/ftp/pub
enabled=1
gpgcheck=0
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, langpacks
cenos7 | 3.6 kB 00:00:00
(1/4): cenos7/group_gz | 156 kB 00:00:00
(2/4): cenos7/primary_db | 3.1 MB 00:00:00
(3/4): cenos7/filelists_db | 3.1 MB 00:00:00
(4/4): cenos7/other_db | 1.2 MB 00:00:00
Loading mirror speeds from cached hostfile
Metadata Cache Created
重新执行system-config-kickstart
[root@localhost ~]# ll
总用量 8
-rw-------. 1 root root 1495 5月 20 14:03 anaconda-ks.cfg
-rw-r–r-- 1 root root 1050 5月 29 19:07 ks.cfg
[root@localhost01 ~]# systemctl restart vsftpd
[root@localhost01 ~]# systemctl restart dhcpd
5、测试安装系统
内存不能低于2G,否者会报存储不足的错误。