#注意!本次实验使用CentOS7.4版本,如果你是7.0以外的版本就不用配了
NFS无人值守道理和HTTPD和FTP的无人值守是一样的,只是换了一种传输的方式罢了
PXE、DHCP、NFS、TFTP服务器:192.168.15.241
1、安装dhcp、tftp、nfs客户端、以及syslinux
[root@localhost ~]# yum -y install dhcp tftp tfpt-server xinetd nfs-utils syslinux
2、编辑dhcp配置文件
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
~
allow booting;
allow bootp;
ddns-update-style interim;
ignore client-updates;
subnet 192.168.15.0 netmask 255.255.255.0 {
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.15.241;
range dynamic-bootp 192.168.15.100 192.168.15.200;
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.15.241;
filename "pxelinux.0";
}
~
3、挂载光盘到/media/cdrom中,挂载后将里面所有文件以及目录及子目录下所有文件和目录都复制到/PXE目录下,PXE目录自行创建
[root@localhost ~]# mkdir /media/cdrom/
[root@localhost ~]# mkdir /PXE
[root@localhost ~]# mount /dev/sr0 /media/cdrom/
[root@localhost ~]# cp -R /media/cdrom/* /PXE/
4、编辑xinetd守护进程,将tftp启用,并到tftp文件存储根目录中,将镜像和安装的syslinux中必要的文件复制到里面!
[root@localhost ~]# vim /etc/xinetd.d/tftp
~
disable = no #将yes改为no即可!
~
[root@localhost ~]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# cp /usr/share/syslinux/pxelinux.0 ./
[root@localhost tftpboot]# cp /PXE/images/pxeboot/{vmlinuz,initrd.img} ./
[root@localhost tftpboot]# cp /PXE/isolinux/{vesamenu.c32,boot.msg} ./
[root@localhost tftpboot]# mkdir pxelinux.cfg
[root@localhost tftpboot]# cp /PXE/isolinux/isolinux.cfg pxelinux.cfg/default
5、编辑复制好的pxelinux.cfg目录中的default文件!并修改相应参数
[root@localhost tftpboot]# vim pxelinux.cfg/default
~
default linux //修改为linux
#第一次NFS为镜像位置,第二次NFS为ks文件位置
label linux
menu label ^Install CentOS 7
kernel vmlinuz
append initrd=initrd.img inst.stage2=nfs:192.168.15.241:/PXE ks=nfs:192.168.15
.241:/PXE/KS/ks.cfg quiet
~
6、复制ks.cfg文件,放入/PXE/KS目录中,并编辑ks.cfg文件,修改下相应参数,KS目录自行创建
[root@localhost ~]# mkdir /PXE
[root@localhost ~]# cp /root/anaconda-ks.cfg /PXE/KS/ks.cfg
[root@localhost ~]# vim /PXE/KS/ks.cfg
~
nfs --server=192.168.15.241 --dir=/PXE //自行添加,指定镜像位置
clearpart --all --initlabel
~
[root@localhost ~]# chmod +r /PXE/KS/ks.cfg
7、编辑NFS配置文件
[root@localhost ~]# vim /etc/exports
~
/PXE *(ro,sync) //指定镜像位置
/PXE/KS *(ro,sync) //指定ks.cfg文件位置
~
[root@localhost ~]# exportfs -rv
exporting *:/PXE/KS
exporting *:/PXE
8、启动dhcp、xinetd守护进程以及nfs服务,还需要关闭防火墙和selinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# iptables -F
[root@localhost ~]# systemctl start dhcpd
[root@localhost ~]# systemctl start xinetd
[root@localhost ~]# systemctl restart nfs
9、测试就打开虚拟机,设置同一网络模式,开机等待就可以了!