共享服务器配置与客户端挂载

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} p {mso-style-noshow:yes; mso-style-priority:99; mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:宋体; mso-bidi-font-family:宋体;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.Section1 {page:Section1;} -->

服务器端配置

创建共享目录

        # mkdir /home/share

        # chown root /home/share

创建或修改/etc/exports 配置文件

这个文件的内容非常简单,每一行由抛出路径,客户名列表以及每个客户名后紧跟的访问选项构成:

        [ 共享的目录] [ 主机名或IP( 参数, 参数)]

其中参数是可选的,当不指定参数时,nfs 将使用默认选项。默认的共享选项是 sync,ro,root_squash,no_delay

当主机名或IP 地址为空时,则代表共享给任意客户机提供服务。

当将同一目录共享给多个客户机,但对每个客户机提供的权限不同时,可以这样:

        [ 共享的目录] [ 主机名1IP1( 参数1, 参数2)] [ 主机名2IP2( 参数3, 参数4)]

下面是一些NFS 共享的常用参数:

        ro                      只读访问

        rw                      读写访问

        sync                    所有数据在请求时写入共享

        async                   NFS 在写入数据前可以相应请求

        secure                  NFS 通过1024 以下的安全TCP/IP 端口发送

        insecure                NFS 通过1024 以上的端口发送

        wdelay                   如果多个用户要写入NFS 目录,则归组写入(默认)

        no_wdelay               如果多个用户要写入NFS 目录,则立即写入,当使用async 时,无需此设置。

        hide                    NFS 共享目录中不共享其子目录

        no_hide                 共享NFS 目录的子目录

        subtree_check           如果共享/usr/bin 之类的子目录时,强制NFS 检查父目录的权限(默认)

        no_subtree_check        和上面相对,不检查父目录权限

        all_squash              共享文件的UIDGID 映射匿名用户anonymous ,适合公用目录。

        no_all_squash           保留共享文件的UIDGID (默认)

        root_squash             root 用户的所有请求映射成如anonymous 用户一样的权限(默认)

        no_root_squas           root 用户具有根目录的完全管理访问权限

        anonuid=xxx             指定NFS 服务器/etc/passwd 文件中匿名用户的UID

        anongid=xxx             指定NFS 服务器/etc/passwd 文件中匿名用户的GID

配置文件/etc/exports 内容如下:

        $ cat /etc/exports

 

        /home/share 192.168.102.15(rw,sync) 192.168.102.16(rw,sync) 。。。

配置说明: 对192.168.102.15 赋予读写权限,其他机器仅有只读权限。

重启NFS 服务

         # /etc/init.d/nfs-kernel-server restart

# /etc/rc.d/init.d/portmap start

 ( 第一次刚用NFS, 这一步一定要, 不然会出现这样的错误:root_nfs failed, reason given by server: 权限不够)

/etc/rc.d/init.d/nfs start

 

在客户机上查看NFS 的资源共享情况

        # showmount -e 192.168.102.47

 

        Export list for 192.168.102.47:

        /home/share (everyone)

使用mount 命令即可挂栽共享资源

在客户机 192.168.102.15 上加载共享资源

        # mount 192.168.102.47:/home/share /mnt

 

        # cd /mnt

       

        # echo '12345'> 123

即可发现对服务器共享目录可写

        # umount /mnt

在客户机 192.168.102.61 上加载共享资源

        # mount 192.168.102.47:/home/share /mnt

 

        # cd /mnt

 

        # ls

        123

 

        # touch 321

 

        touch: cannot touch `321': Permission denied

 

        # echo '123455' >123

 

        -bash: 123: Permission denied

即可发现对服务器共享目录只有读取权限,

这与我们在服务器端的权限设置是相符的。

是不是我们每次修改了配置文件都需要重启nfs 服务呢? 这个时候我们就可以用exportfs 命令重新扫描/etc/exports 文件,来使改动立刻生效。

比如:

        # exportfs -au 卸载所有共享目录

 

        # exportfs -rv 重新共享所有目录并输出详细信息

exportfs 命令有软件包 nfs-kernel-server 提供,详细的 exportfs 命令说明请查看:

        man exportfs

中文的手册说明可以查看这里:

exportfs 联机手册

当完成资源共享, 我们如何知道发布了哪些权限呢?这时我们可以查看 /var/lib/nfs/etab 文件,它是有 exportfs 命令根据 /etc/exports 生成的。

        # cat /var/lib/nfs/etab

 

        /home/share     192.168.102.15(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,subtree_check,secure_locks,acl,mapping=identity,anonuid=65534,anongid=65534)

        /home/share     *(ro,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,subtree_check,secure_locks,acl,mapping=identity,anonuid=65534,anongid=65534)

现在我们来查看服务器上有关NFS 服务器启动了哪些端口:

        tonybox:/home/share# lsof -i|grep rpc

        portmap   1931 daemon    3u  IPv4   4289       UDP *:sunrpc

        portmap   1931 daemon    4u  IPv4   4290       TCP *:sunrpc (LISTEN)

        rpc.statd 3206  statd    3u  IPv4   7081       UDP *:1029

        rpc.statd 3206  statd    6u  IPv4   7072       UDP *:838

        rpc.statd 3206  statd    7u  IPv4   7085       TCP *:1031 (LISTEN)

        rpc.mount 3483   root    6u  IPv4   7934       UDP *:691

        rpc.mount 3483   root    7u  IPv4   7937       TCP *:694 (LISTEN)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值