nfs+http综合练习

nfs+http综合练习

配置nfs服务器和web服务器
1.配置nfs服务器,要求将两个网站的资源文件通过nfs服务器共享给web服务器。
#通过两个共享目录分别网页文件例如:/openlab/index.html/xianoupeng/index.html(网页文件内容自定义)。
2.通过nfs共享网页文件,配置web服务实现www.openlab.com以及www.xianoupeng.com访问各自的网站信息。

无论是服务端还是客户端首先关闭防火墙和selinux

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0

S服务器端配置(ip:192.168.164.128):

要部署NFS服务,必须安装下面两个软件包:nfs-utils:NFS主程序,rpcbind:PRC主程序
#查看NFS软件包

[root@localhost ~]# rpm -qa | egrep "nfs|rpcbind" 
sssd-nfs-idmap-2.2.3-20.el8.x86_64
rpcbind-1.2.5-7.el8.x86_64
libnfsidmap-2.3.3-31.el8.x86_64
nfs-utils-2.3.3-31.el8.x86_64

启动nfs服务

[root@localhost ~]# systemctl start  nfs-server.service 

查看nfs服务运行状态(Active:active 说明启动成功)

[root@localhost ~]# systemctl status nfs-server.service 
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)
   Active: active (exited) since Sun 2021-07-11 07:13:02 EDT; 2s ago
  Process: 3567 ExecStart=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssprox>
  Process: 3553 ExecStart=/usr/sbin/rpc.nfsd (code=exited, status=0/SUCCESS)
  Process: 3552 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
 Main PID: 3567 (code=exited, status=0/SUCCESS)

当nfs服务启动成功时会相应的启动rpc服务

[root@localhost ~]# systemctl status rpc-statd-notify.service 
● rpc-statd-notify.service - Notify NFS peers of a restart
   Loaded: loaded (/usr/lib/systemd/system/rpc-statd-notify.service; static; vendor preset: disabled)
   Active: active (exited) since Sun 2021-07-11 06:43:38 EDT; 30min ago
  Process: 1137 ExecStart=/usr/sbin/sm-notify (code=exited, status=0/SUCCESS)
    Tasks: 0 (limit: 23663)
   Memory: 0B
   CGroup: /system.slice/rpc-statd-notify.service

创建目录文件openlab,xianoupeng以及创建index.html网页文件

[root@localhost ~]# mkdir /openlab
[root@localhost ~]# mkdir /xianoupeng
[root@localhost ~]# echo this is openlab > /openlab/index.html
[root@localhost ~]# echo this is xianoupeng > /xianoupeng/index.html

编写nfs配置文件

[root@localhost ~]# vim  /etc/exports
/openlab  *(rw)
/xianoupeng  *(rw)

C客户端配置(ip:192.168.164.129):

创建两个目录并进行挂载

[root@localhost ~]# mkdir /openlab
[root@localhost ~]# mkdir /xianoupeng
[root@localhost ~]# mount 192.168.164.128:/openlab  /openlab
[root@localhost ~]# mount 192.168.164.128:/xianoupeng  /xianoupeng

查看文件是否共享

[root@localhost ~]# cd /openlab
[root@localhost openlab]# cat index.html 
this is openlab

编写yum仓库并下载httpd服务器

[root@localhost openlab]# mount /dev/sr0 /mnt
[root@localhost openlab]# vim /etc/yum.repos.d/base.repo
[BaseOS]
name=BaseOS
baseurl=file:///mnt/BaseOS
gpgcheck=0
[AppStream]
name=AppStream
baseurl=file:///mnt/AppStream
gpgcheck=0
[root@localhost openlab]# yum install httpd -y

启动web服务并编写配置文件

[root@localhost ~]# systemctl start httpd
[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf
<VirtualHost 192.168.164.129:80>
        ServerName www.openlab.com
        DocumentRoot /openlab
</VirtualHost>
<Directory /openlab>
        AllowOverride none
        Require all granted
</Directory>
<VirtualHost 192.168.164.129:80>
        ServerName www.xianoupeng.com
        DocumentRoot /xianoupeng
</VirtualHost>
<Directory /xianoupeng>
        AllowOverride none
        Require all granted
</Directory>

在Linux下hosts添加两行代码

[root@localhost ~]# vim /etc/hosts
192.168.164.129  www.openlab.com
192.168.164.129  www.xianoupeng.com

在window下C:\Windows\System32\drivers\etc\hosts添加两行代码

192.168.164.129  www.openlab.com
192.168.164.129  www.xianoupeng.com

重启httpd服务

[root@localhost ~]# systemctl restart httpd

在测试Linux中测试:(只写Linux中的hosts)

[root@localhost ~]# curl www.openlab.com
this is openlab
[root@localhost ~]# curl www.xianoupeng.com
this is xianoupeng
[root@localhost ~]# 

在测试window中测试(既要写Linux中的hosts又要写window中的hosts):在这里插入图片描述在这里插入图片描述

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值