系统环境:

[root@nfs-client2 ~]#  cat /etc/redhat-release 

CentOS release 6.7 (Final)

[root@nfs-client2 ~]# 

[root@nfs-client2 ~]# uname -r

2.6.32-573.el6.x86_64

[root@nfs-client2 ~]# uname -m

x86_64

[root@nfs-client2 ~]# rpm -qa nfs-utils rpcbind

[root@nfs-client2 ~]# yum install nfs-utils rpcbind -y

...........

已安装:

  nfs-utils.x86_64 1:1.2.3-64.el6              rpcbind.x86_64 0:0.2.0-11.el6             


作为依赖被安装:

  keyutils.x86_64 0:1.4-5.el6                libevent.x86_64 0:1.4.13-4.el6               

  libgssglue.x86_64 0:0.1-11.el6             libtirpc.x86_64 0:0.2.1-10.el6               

  nfs-utils-lib.x86_64 0:1.1.5-11.el6        python-argparse.noarch 0:1.2.1-2.1.el6       


完毕!

[root@nfs-client2 ~]# rpm -qa nfs-utils rpcbind 

nfs-utils-1.2.3-64.el6.x86_64

rpcbind-0.2.0-11.el6.x86_64


[root@nfs-server ~]# /etc/init.d/rpcbind status

rpcbind 已停

[root@nfs-server ~]# /etc/init.d/rpcbind start

正在启动 rpcbind:                                         [确定]

[root@nfs-server ~]# /etc/init.d/rpcbind status

rpcbind (pid  27104) 正在运行...

[root@nfs-server ~]# lsof -i :111

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

rpcbind 27104  rpc    6u  IPv4  31439      0t0  UDP *:sunrpc 

rpcbind 27104  rpc    8u  IPv4  31442      0t0  TCP *:sunrpc (LISTEN)

rpcbind 27104  rpc    9u  IPv6  31444      0t0  UDP *:sunrpc 

rpcbind 27104  rpc   11u  IPv6  31447      0t0  TCP *:sunrpc (LISTEN)


[root@nfs-server ~]# netstat -lntup|grep rpcbind

tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      27104/rpcbind       

tcp        0      0 :::111                      :::*                        LISTEN      27104/rpcbind       

udp        0      0 0.0.0.0:991                 0.0.0.0:*                               27104/rpcbind       

udp        0      0 0.0.0.0:111                 0.0.0.0:*                               27104/rpcbind       

udp        0      0 :::991                      :::*                                    27104/rpcbind       

udp        0      0 :::111                      :::*                                    27104/rpcbind       


[root@nfs-server ~]# chkconfig --list rpcbind

rpcbind         0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭


[root@nfs-server ~]# rpcinfo -p localhost

   program vers proto   port  service

    100000    4   tcp    111  portmapper

    100000    3   tcp    111  portmapper

    100000    2   tcp    111  portmapper

    100000    4   udp    111  portmapper

    100000    3   udp    111  portmapper

    100000    2   udp    111  portmapper

[root@nfs-server ~]# /etc/init.d/nfs status

rpc.svcgssd 已停

rpc.mountd 已停

nfsd 已停

rpc.rquotad 已停

[root@nfs-server ~]# /etc/init.d/nfs start

启动 NFS 服务:                                            [确定]

关掉 NFS 配额:                                            [确定]

启动 NFS mountd:                                          [确定]

启动 NFS 守护进程:                                        [确定]

正在启动 RPC idmapd:                                      [确定]


[root@nfs-server ~]# netstat -lntup|grep 2049             ------nfs主端口

tcp        0      0 0.0.0.0:2049                0.0.0.0:*                   LISTEN      -                   

tcp        0      0 :::2049                     :::*                        LISTEN      -                   

udp        0      0 0.0.0.0:2049                0.0.0.0:*                               -                   

udp        0      0 :::2049                     :::*                                    - 


[root@nfs-server ~]# rpcinfo -p localhost    

   program vers proto   port  service

    100000    4   tcp    111  portmapper

    100000    3   tcp    111  portmapper

    100000    2   tcp    111  portmapper

    100000    4   udp    111  portmapper

    100000    3   udp    111  portmapper

    100000    2   udp    111  portmapper

    100011    1   udp    875  rquotad

    100011    2   udp    875  rquotad

    100011    1   tcp    875  rquotad

    100011    2   tcp    875  rquotad

    100005    1   udp  40562  mountd

    100005    1   tcp  43893  mountd

    100005    2   udp  53127  mountd

    100005    2   tcp  36081  mountd

    100005    3   udp  56672  mountd

    100005    3   tcp  52133  mountd

    100003    2   tcp   2049  nfs

    100003    3   tcp   2049  nfs

    100003    4   tcp   2049  nfs

    100227    2   tcp   2049  nfs_acl

    100227    3   tcp   2049  nfs_acl

    100003    2   udp   2049  nfs

    100003    3   udp   2049  nfs

    100003    4   udp   2049  nfs

    100227    2   udp   2049  nfs_acl

    100227    3   udp   2049  nfs_acl

    100021    1   udp  42438  nlockmgr

    100021    3   udp  42438  nlockmgr

    100021    4   udp  42438  nlockmgr

    100021    1   tcp  36179  nlockmgr

    100021    3   tcp  36179  nlockmgr

    100021    4   tcp  36179  nlockmgr

加入开机自启动:

[root@nfs-server ~]# cat /etc/rc.local 

......

/etc/init.d/rpcbind start

/etc/init.d/nfs start


[root@nfs-server ~]# ps -ef|egrep "nfs|rpc"

rpc      27104     1  0 10:35 ?        00:00:00 rpcbind

root     27208     2  0 10:44 ?        00:00:00 [rpciod/0]

root     27209     2  0 10:44 ?        00:00:00 [rpciod/1]

root     27218     1  0 10:44 ?        00:00:00 rpc.rquotad     磁盘配额进城

root     27223     1  0 10:44 ?        00:00:00 rpc.mountd      权限管理验证

root     27230     2  0 10:44 ?        00:00:00 [nfsd4]

root     27231     2  0 10:44 ?        00:00:00 [nfsd4_callbacks]

root     27232     2  0 10:44 ?        00:00:00 [nfsd]      =====>nfs主进程

root     27233     2  0 10:44 ?        00:00:00 [nfsd]      =====>nfs主进程

root     27234     2  0 10:44 ?        00:00:00 [nfsd]      =====>nfs主进程

root     27235     2  0 10:44 ?        00:00:00 [nfsd]

root     27236     2  0 10:44 ?        00:00:00 [nfsd]

root     27237     2  0 10:44 ?        00:00:00 [nfsd]

root     27238     2  0 10:44 ?        00:00:00 [nfsd]

root     27239     2  0 10:44 ?        00:00:00 [nfsd]

root     27270     1  0 10:44 ?        00:00:00 rpc.idmapd

root     27299  2056  0 10:54 pts/1    00:00:00 grep -E nfs|rpc


[root@nfs-server ~]# mkdir /data


[root@nfs-server ~]# cat /etc/exports 

/data  10.0.0.*(rw,sync)


[root@nfs-server ~]# /etc/init.d/nfs reload        重新加载服务


[root@nfs-server ~]# showmount -e 127.0.0.1         ======>查看共享的记录

Export list for 127.0.0.1:

/data 10.0.0.*


[root@nfs-server ~]# mount -t nfs 10.0.0.7:/data /mnt      将/data目录挂载到/mnt下面


[root@nfs-server ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3        19G  1.5G   16G   9% /

tmpfs           937M     0  937M   0% /dev/shm

/dev/sda1       190M   36M  145M  20% /boot

10.0.0.7:/data   19G  1.5G   16G   9% /mnt                ======>已挂载成功


[root@nfs-server mnt]# touch /data/oldboy.txt

[root@nfs-server mnt]# ll /data/

总用量 0

-rw-r--r-- 1 root root 0 11月 23 11:16 oldboy.txt


[root@nfs-client1 ~]# /etc/init.d/rpcbind start

正在启动 rpcbind:                                         [确定]

[root@nfs-client1 ~]# chkconfig rpcbind on

[root@nfs-client1 ~]# showmount -e 10.0.0.7

Export list for 10.0.0.7:

/data 10.0.0.0/24

客户端挂载:

[root@nfs-client1 ~]# mount -t nfs 10.0.0.7:/data /mnt

[root@nfs-client1 ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3        19G  1.5G   16G   9% /

tmpfs           937M     0  937M   0% /dev/shm

/dev/sda1       190M   36M  145M  20% /boot

10.0.0.7:/data   19G  1.5G   16G   9% /mnt


[root@nfs-server data]# touch oldboy.txt       =======>服务端创建一个文件oldboy.txt 

[root@nfs-server data]# ll

总用量 0

-rw-r--r-- 1 root root 0 11月 23 11:25 oldboy.txt


[root@nfs-client1 mnt]# ll

总用量 0

-rw-r--r-- 1 root root 0 11月 23 11:25 oldboy.txt         ======>客户端查看是存在的


[root@nfs-client1 mnt]# touch abc.txt                    ======>在客户端没有写的权限

touch: 无法创建"abc.txt": 权限不够

出现此问题在于权限不对,服务器端需要对此目录进行授权,权限为nfsnobody

[root@nfs-server data]# chown -R nfsnobody /data/          ======>授权服务端对/data具有写权限

[root@nfs-server data]# ll /data/

总用量 0

-rw-r--r-- 1 nfsnobody root 0 11月 23 11:25 oldboy.txt     ======>属主权限已改

然后再在客户端创建


[root@nfs-client1 mnt]# touch abc.txt                     =======>客户端已能够成功创建文件

[root@nfs-client1 mnt]# 


[root@nfs-client2 ~]# /etc/init.d/rpcbind start

正在启动 rpcbind:                                         [确定]

[root@nfs-client2 ~]# chkconfig rpcbind on

[root@nfs-client2 ~]# mount -t nfs 10.0.0.7:/data /mnt    =======>挂载

[root@nfs-client2 ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3        19G  1.5G   16G   9% /

tmpfs           937M     0  937M   0% /dev/shm

/dev/sda1       190M   36M  145M  20% /boot

10.0.0.7:/data   19G  1.5G   16G   9% /mnt               =======>已挂载成功


[root@nfs-client2 mnt]# touch 9.txt

[root@nfs-client1 mnt]# ll

-rw-r--r-- 1 nfsnobody nfsnobody 0 11月 23 11:41 9.txt

[root@nfs-server data]# rm -f 9.txt

已删除。

结论:无论在哪个nfs目录下创建文件,其他客户端都能够进行删除,解决了共享存储问题。


检查思路:

1  ping 

2  telnet

3  出现no route to host,则必须要检查防火墙和安全策略

4  showmount