《云计算》-集群:配置并访问NFS共享

3 案例3:配置并访问NFS共享
3.1 问题

服务器利用NFS机制发布2个共享目录,要求如下:

将目录/root共享给192.168.2.100,客户机的root用户有权限写入
将/usr/src目录共享给192.168.2.0/24网段,只开放读取权限

    
    
  • 1
  • 2

从客户机访问NFS共享:

分别查询/挂载上述NFS共享目录
查看挂载点目录,并测试是否有写入权限

    
    
  • 1
  • 2

3.2 方案

使用2台RHEL7虚拟机,其中一台作为NFS共享服务器(192.168.2.5)、另外一台作为测试用的Linux客户机(192.168.2.100),如图-5所示。
在这里插入图片描述
图-5

NFS共享的配置文件:/etc/exports 。

配置记录格式:文件夹路径 客户地址1(控制参数… …) 客户地址2(… …) 。
3.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:配置NFS服务器,发布指定的共享

1)确认服务端程序、准备共享目录

软件包nfs-utils用来提供NFS共享服务及相关工具,而软件包rpcbind用来提供RPC协议的支持,这两个包在RHEL7系统中一般都是默认安装的:

[root@proxy ~]# rpm  -q  nfs-utils  rpcbind
nfs-utils-1.3.0-0.48.el7.x86_64
rpcbind-0.2.0-42.el7.x86_64

    
    
  • 1
  • 2
  • 3

根据本例的要求,需要作为NFS共享发布的有/root、/usr/src这两个目录:

[root@proxy ~]# ls  -ld  /root  /usr/src/
dr-xr-x---. 35 root root 4096 1月  15 18:52 /root
drwxrwxr-x+  4 root root 4096 1月  15 17:35 /usr/src/

    
    
  • 1
  • 2
  • 3

2)修改/etc/exports文件,添加共享目录设置

默认情况下,来自NFS客户端的root用户会被降权,若要保留其root权限,注意应添加no_root_squash控制参数(没有该参数,默认root会被自动降级为普通账户);另外,限制只读的参数为ro、可读可写为rw,相关配置操作如下所示:

[root@proxy ~]# vim  /etc/exports
/root           192.168.2.100(rw,no_root_squash)
/usr/src        192.168.2.0/24(ro)

    
    
  • 1
  • 2
  • 3

3)启动NFS共享相关服务,确认共享列表

依次启动rpcbiind、nfs服务:

[root@proxy ~]# systemctl restart rpcbind  ;  systemctl enable rpcbind
[root@proxy ~]# systemctl restart nfs ;  systemctl enable nfs

    
    
  • 1
  • 2

使用showmount命令查看本机发布的NFS共享列表:

[root@proxy ~]# showmount  -e  localhost
Export list for localhost:
/usr/src 192.168.2.0/24
/root    192.168.2.100

    
    
  • 1
  • 2
  • 3
  • 4

步骤二:从客户机访问NFS共享

1)启用NFS共享支持服务

客户机访问NFS共享也需要rpcbind服务的支持,需确保此服务已开启:

[root@web1 ~]# systemctl restart rpcbind  ;  systemctl enable rpcbind

    
    
  • 1

2)查看服务器提供的NFS共享列表

[root@web1 ~]# showmount  -e  192.168.2.5
Export list for 192.168.2.5:
/usr/src 192.168.2.0/24
/root    192.168.2.100

    
    
  • 1
  • 2
  • 3
  • 4

3)从客户机192.168.2.100访问两个NFS共享,并验证权限

将远程的NFS共享/root挂载到本地的/root5文件夹,并验证可读可写:

[root@web1 ~]# mkdir  /root5                          //建立挂载点
[root@web1 ~]# mount  192.168.2.5:/root  /root5          //挂载NFS共享目录
[root@web1 ~]# df  -hT  /root5                          //确认挂载结果
Filesystem        Type  Size  Used Avail Use% Mounted on
192.168.2.5:/root nfs    50G   15G   33G  31% /root5
[root@web1 ~]# cd  /root5                              //切换到挂载点
[root@web1 root5]# echo "NFS Write Test" >  test.txt     //测试写入文件
[root@web1 root5]# cat test.txt                      //测试查看文件
NFS Write Test

    
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

将远程的NFS共享/usr/src挂载到本地的/mnt/nfsdir,并验证只读:

[root@web1 ~]# mkdir  /mnt/nfsdir                      //建立挂载点
[root@web1 ~]# mount  192.168.2.5:/usr/src  /mnt/nfsdir/      //挂载NFS共享目录
[root@web1 ~]# df  -hT  /mnt/nfsdir/                          //确认挂载结果
Filesystem           Type  Size  Used Avail Use% Mounted on
192.168.2.5:/usr/src nfs    50G   15G   33G  31% /mnt/nfsdir
[root@web1 ~]# cd  /mnt/nfsdir/                          //切换到挂载点
[root@web1 nfsdir]# ls                                  //读取目录列表
debug  install.log  kernels  test.txt
[root@web1 nfsdir]# echo  "Write Test."  >  pc.txt  //尝试写入文件失败
-bash: pc.txt: 只读文件系统

    
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

!!!! 如果从未授权的客户机访问NFS共享,将会被拒绝。比如从NFS服务器本机尝试访问自己发布的/root共享(只允许192.168.2.100访问),结果如下所示:

[root@proxy ~]# mkdir  /root5
[root@proxy ~]# mount  192.168.2.5:/root  /root5    
mount.nfs: access denied by server while mounting 192.168.2.5:/root

    
    
  • 1
  • 2
  • 3

4)设置永久挂载

[root@web1 ~]# vim  /etc/fstab
.. ..
192.168.2.5:/usr/src  nfsdir         nfs  default,ro   0 0
192.168.2.5:/root     root5         nfs  default      0 0

    
    
  • 1
  • 2
  • 3
  • 4
                                </div>
            <link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-b6c3c6d139.css" rel="stylesheet">
                                            <div class="more-toolbox">
            <div class="left-toolbox">
                <ul class="toolbox-list">
                    
                    <li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
                        <use xlink:href="#csdnc-thumbsup"></use>
                    </svg><span class="name">点赞</span>
                    <span class="count">1</span>
                    </a></li>
                    <li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;popu_824&quot;}"><svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-csdnc-Collection-G"></use>
                    </svg><span class="name">收藏</span></a></li>
                    <li class="tool-item tool-active is-share"><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;1582594662_002&quot;}"><svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-csdnc-fenxiang"></use>
                    </svg>分享</a></li>
                    <!--打赏开始-->
                                            <!--打赏结束-->
                                            <li class="tool-item tool-more">
                        <a>
                        <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
                        </a>
                        <ul class="more-box">
                            <li class="item"><a class="article-report">文章举报</a></li>
                        </ul>
                    </li>
                                        </ul>
            </div>
                        </div>
        <div class="person-messagebox">
            <div class="left-message"><a href="https://blog.csdn.net/xie_qi_chao">
                <img src="https://profile.csdnimg.cn/B/F/6/3_xie_qi_chao" class="avatar_pic" username="xie_qi_chao">
                                        <img src="https://g.csdnimg.cn/static/user-reg-year/1x/2.png" class="user-years">
                                </a></div>
            <div class="middle-message">
                                    <div class="title"><span class="tit"><a href="https://blog.csdn.net/xie_qi_chao" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}" target="_blank">解启超</a></span>
                                        </div>
                <div class="text"><span>发布了355 篇原创文章</span> · <span>获赞 52</span> · <span>访问量 3万+</span></div>
            </div>
                            <div class="right-message">
                                        <a href="https://im.csdn.net/im/main.html?userName=xie_qi_chao" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
                    </a>
                                                        <a class="btn btn-sm attented bt-button personal-watch" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}">已关注</a>
                                </div>
                        </div>
                </div>
</article>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

尹汇川

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值