震惊!!!是什么让程序员痛哭流涕!!!
实验题
1)准备3台虚拟机,一台Windows虚拟机PC1(不限制win7或者win10)、一台Linux服务器server1(IP是172.16.100.100/24)和一台空虚拟机server2。虚拟机网络使用仅主机模式。(10分)
2)server1提供DHCP服务给PC1和server2分配对应网段的IP地址。(10分)
3)server1提供PXE服务,能够使server2可以自动安装Centos7 Linux操作系统。(10分)
4)在server1安装和启动httpd服务对外提供Web服务,并搭建DNS服务负责解析地址www.kgc.com,使得PC1能够使用域名www.kgc.com访问Web服务器。(10分)
5)在server2安装NFS服务,提供共享目录/share
,在/share目录中创建文件index.html,文件内容自定义。把server2的/share目录通过NFS挂载到server1的/var/www/html目录下,使得PC1访问Web服务时能够显示自定义的内容。(10分)
PXE
在PXE装机中因为使用的是172.16.100.100,使用主机模式,要将DHCP关闭,如果不关闭所在DHCP服务器网段为192.168.30.0和题目要求的172.16.100.0不在同一网段,分配时就看客户机先分配到谁,就会得到哪个网段
设置成主机模式,修改网卡
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
重启网卡
[root@localhost ~]# systemctl restart network
[root@localhost ~]# mount /dev/sr0 /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
配置本地yum源仓库
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir repos.bak
[root@localhost yum.repos.d]# mv *.repo repos.bak
[root@localhost yum.repos.d]# cd repos.bak/
[root@localhost repos.bak]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@localhost repos.bak]# cd -
/etc/yum.repos.d
[root@localhost yum.repos.d]# vim local.repo
[root@localhost yum.repos.d]# yum clean all && yum makecache
安装TFPT
[root@localhost yum.repos.d]# cd ~
[root@localhost ~]# yum -y install tftp-server xinetd
[root@localhost ~]# vim /etc/xinetd.d/tftp
[root@localhost ~]# systemctl start tftp
[root@localhost ~]# systemctl enable tftp
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
[root@localhost ~]# systemctl start xinetd
[root@localhost ~]# systemctl enable xinetd
安装DHCP并启动服务
[root@localhost ~]# yum -y install dhcp
[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? y
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf #修改DHCP配置文件
[root@localhost ~]# systemctl start dhcpd
[root@localhost ~]# systemctl enable dhcpd
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
准备 Linux 内核、初始化镜像文件
[root@localhost ~]# mount /dev/sr0 /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
mount: /dev/sr0 已经挂载或 /mnt 忙
/dev/sr0 已经挂载到 /run/media/root/CentOS 7 x86_64 上
/dev/sr0 已经挂载到 /mnt 上
[root@localhost ~]# cd /mnt/images/pxeboot
[root@localhost pxeboot]# cp vmlinuz /var/lib/tftpboot/ #将Linux内核文件复制到tftp根目录下
[root@localhost pxeboot]# cp initrd.img /var/lib/tftpboot/ #将初始化镜像文件(linux引导加载模块)复制到TFTP根目录下
[root@localhost pxeboot]# ls /var/lib/tftpboot/
initrd.img vmlinuz
准备 PXE 引导程序
PXE引导程序由软件包 syslinux 提供所以安装syslinux
[root@localhost pxeboot]# yum -y install syslinux
复制PXE引导程序到tftp根目录下
[root@localhost pxeboot]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@localhost pxeboot]# ls /var/lib/tftpboot/
initrd.img pxelinux.0 vmlinuz
安装FTP,准备CentOS7安装源
[root@localhost pxeboot]# yum -y install vsftpd
[root@localhost pxeboot]# mkdir /var/ftp/centos7 #创建安装源目录
[root@localhost pxeboot]# cp -rf /mnt/* /var/ftp/centos7/ 将镜像文件全部复制到安装源目录
[root@localhost pxeboot]# systemctl start vsftpd
[root@localhost pxeboot]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
配置启动菜单文件
[root@localhost pxeboot]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@localhost pxeboot]# vim /var/lib/tftpboot/pxelinux.cfg/default
扫描二维码关注公众号,回复:
12120843 查看本文章
关闭防火墙
[root@localhost pxeboot]# systemctl stop firewalld.service
[root@localhost pxeboot]# setenforce 0
新建虚拟机
在Windows中选用DHCP自动分配获取地址
DNS
开启httpd服务,httpd服务适用于域名的,开启了才能用网址
[root@localhost ~]# yum install -y httpd
[root@localhost ~]# systemctl start httpd.service
安装bind包
[root@localhost ~]# yum -y install bind
[root@localhost ~]# rpm -qc bind
/etc/logrotate.d/named
/etc/named.conf
/etc/named.iscdlv.key
/etc/named.rfc1912.zones
/etc/named.root.key
/etc/rndc.conf
/etc/rndc.key
/etc/sysconfig/named
/var/named/named.ca
/var/named/named.empty
/var/named/named.localhost
/var/named/named.loopback
配置主配置文件
[root@localhost ~]# vim /etc/named.conf
配置区域配置文件
[root@localhost ~]# vim /etc/named.rfc1912.zones
[root@localhost ~]# cd /var/named/
[root@localhost named]# cp -p named.localhost xyw.com 复制模板
[root@localhost named]# ls #文件已复制
data named.ca named.localhost slaves
dynamic named.empty named.loopback xyw.com
配置区域数据配置文件
[root@localhost named]# vim /var/named/xyw.com
重启服务,关闭防火墙
[root@localhost named]# systemctl start named
[root@localhost named]# systemctl stop firewalld
[root@localhost named]# setenforce 0
添加DNS服务器地址
[root@localhost named]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
[root@localhost named]# systemctl restart network
测试DNS解析
[root@localhost named]# host www.kgc.com
www.kgc.com has address 172.16.100.100
[root@localhost named]# nslookup www.kgc.com
Server: 172.16.100.100
Address: 172.16.100.100#53
Name: www.kgc.com
Address: 172.16.100.100
Windows中测试
NFS
文件服务器(可用PXE自动安装的虚拟机,DHCP分配IP为172.16.100.103)
[root@localhost ~]# rpm -q rpcbind nfs-utils
rpcbind-0.2.0-42.el7.x86_64
nfs-utils-1.3.0-0.48.el7.x86_64
停止进程
[root@localhost ~]# yum -y install nfs-utils rpcbind
已加载插件:fastestmirror, langpacks
/var/run/yum.pid 已被锁定,PID 为 4226 的另一个程序正在运行。
Another app is currently holding the yum lock; waiting for it to exit...
另一个应用程序是:PackageKit
内存: 26 M RSS (437 MB VSZ)
已启动: Mon Dec 14 22:43:48 2020 - 00:03之前
状态 :睡眠中,进程ID:4226
Another app is currently holding the yum lock; waiting for it to exit...
另一个应用程序是:PackageKit
内存: 26 M RSS (437 MB VSZ)
已启动: Mon Dec 14 22:43:48 2020 - 00:05之前
状态 :睡眠中,进程ID:4226
^C
Exiting on user cancel.
[root@localhost ~]# kill -9 4226
因为没有配置yum仓库本地源,所以安装不了
[root@localhost ~]# yum -y install nfs-utils rpcbind
已加载插件:fastestmirror, langpacks
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"
One of the configured repositories failed (未知),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3. Run the command with the repository temporarily disabled
yum --disablerepo=<repoid> ...
4. Disable the repository permanently, so yum won't use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:
yum-config-manager --disable <repoid>
or
subscription-manager repos --disable=<repoid>
5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true
Cannot find a valid baseurl for repo: base/7/x86_64
安装yum源仓库
[root@localhost ~]# mount /dev/sr0 /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir repos.bak
[root@localhost yum.repos.d]# mv *.repo repos.bak
[root@localhost yum.repos.d]# vim local.repo
[root@localhost yum.repos.d]# yum clean all && yum makecache
[root@localhost yum.repos.d]# yum -y install nfs-utils rpcbind
配置共享目录
[root@localhost yum.repos.d]# cd ~
[root@localhost ~]# mkdir -p /opt/share
[root@localhost ~]# chmod 777 /opt/share/
设置输出的各项配置:对象,权限等
[root@localhost ~]# cd /etc/exports
bash: cd: /etc/exports: 不是目录
[root@localhost ~]# cd /etc/
[root@localhost etc]# ls
exports nfs.conf system-release
exports.d nfsmount.conf system-release-cpe
[root@localhost etc]# vim /etc/exports
启动 NFS 服务程序
手动加载NFS共享服务时,应该先启动rpcbind,再启动nfs
[root@localhost etc]# systemctl start rpcbind
[root@localhost etc]# systemctl start nfs
[root@localhost etc]# systemctl enable rpcbind
[root@localhost etc]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@localhost etc]# netstat -anpt | grep 111
创建文件、配置内容
[root@localhost etc]# cd /opt/share
[root@localhost share]# touch indel.html
[root@localhost share]# ls
indel.html index.html
[root@localhost share]# vim index.html
发布并查看共享
[root@localhost etc]# exportfs -rv
exporting 172.16.100.100/24:/opt/share
[root@localhost etc]# showmount -e
Export list for localhost.localdomain:
/opt/share 172.16.100.100/24
最后记得关防火墙
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
客户机IP:172.16.100.100
安装 nfs-utils、rpcbind 软件包
[root@localhost named]# cd ~
[root@localhost ~]# rpm -q rpcbind nfs-utils
rpcbind-0.2.0-42.el7.x86_64
nfs-utils-1.3.0-0.48.el7.x86_64
[root@localhost ~]# yum -y install nfs-utils rpcbind
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
软件包 1:nfs-utils-1.3.0-0.48.el7.x86_64 已安装并且是最新版本
软件包 rpcbind-0.2.0-42.el7.x86_64 已安装并且是最新版本
无须任何处理
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl enable rpcbind
关闭防火墙
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
因为在文件服务器中没有关闭防火墙所以获取不到
[root@localhost ~]# showmount -e 172.16.100.103
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
关闭后即可获取
[root@localhost html]# showmount -e 172.16.100.103
Export list for 172.16.100.103:
/opt/share 172.16.100.0/24
挂载
[root@localhost html]# mount 172.16.100.103:/opt/share /var/www/html/
查看发现已经实时共享
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
indel.html index.html
[root@localhost html]# vim index.html