在讨论这个问题的时候,我们先描述下我们的场景

这个部分涉及到两个服务器:
1. 10.158.1.112
2. 10.158.1.113

他们都有同一个用户:adamhuan
但是这个用户在两端的UID却是不一样的。

112:

[root@cloudera2 ~]# useradd -u 1055 adamhuan
[root@cloudera2 ~]# id adamhuan
uid=1055(adamhuan) gid=1055(adamhuan) groups=1055(adamhuan)
[root@cloudera2 ~]# 
[root@cloudera2 ~]# 

113:

[root@cloudera3 ~]# useradd -u 2055 adamhuan
[root@cloudera3 ~]# id adamhuan
uid=2055(adamhuan) gid=2055(adamhuan) groups=2055(adamhuan)
[root@cloudera3 ~]# 

112,将作为NFS的服务端。

112,创建测试数据:

[root@cloudera2 ~]# mkdir -p /nfs_test/adamhuan
[root@cloudera2 ~]# 
[root@cloudera2 ~]# touch /nfs_test/adamhuan/me
[root@cloudera2 ~]# 
[root@cloudera2 ~]# chown -R adamhuan.adamhuan /nfs_test/
[root@cloudera2 ~]# 
[root@cloudera2 ~]# ls -ltr /nfs_test/adamhuan/
total 0
-rw-r--r-- 1 adamhuan adamhuan 0 Apr 23 14:31 me
[root@cloudera2 ~]# 

NFS Server,启动:

[root@cloudera2 ~]# cat /etc/exports 
/nfs_test/adamhuan      10.158.1.113/24(rw)
[root@cloudera2 ~]# 
[root@cloudera2 ~]# service nfs status
rpc.svcgssd is stopped
rpc.mountd is stopped
nfsd is stopped
rpc.rquotad is stopped
[root@cloudera2 ~]# 
[root@cloudera2 ~]# service nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]
[root@cloudera2 ~]# 
[root@cloudera2 ~]# service nfs status
rpc.svcgssd is stopped
rpc.mountd (pid 79038) is running...
nfsd (pid 79054 79053 79052 79051 79050 79049 79048 79047) is running...
rpc.rquotad (pid 79033) is running...
[root@cloudera2 ~]# 
[root@cloudera2 ~]# showmount -e localhost
Export list for localhost:
/nfs_test/adamhuan 10.158.1.113/24
[root@cloudera2 ~]# 

113,挂载112分发的NFS服务:

[root@cloudera3 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_cloudera3-lv_root
                       48G  4.3G   42G  10% /
tmpfs                 7.8G   72K  7.8G   1% /dev/shm
/dev/sda1             477M   41M  411M  10% /boot
/dev/mapper/vg_cloudera3-lv_home
                      4.6G  9.6M  4.4G   1% /home
[root@cloudera3 ~]# 
[root@cloudera3 ~]# mkdir -p /nfs_test/client
[root@cloudera3 ~]# 
[root@cloudera3 ~]# showmount -e 10.158.1.112
Export list for 10.158.1.112:
/nfs_test/adamhuan 10.158.1.113/24
[root@cloudera3 ~]# 
[root@cloudera3 ~]# mount 10.158.1.112:/nfs_test/adamhuan /nfs_test/client/
[root@cloudera3 ~]# 
[root@cloudera3 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_cloudera3-lv_root
                       48G  4.3G   42G  10% /
tmpfs                 7.8G   72K  7.8G   1% /dev/shm
/dev/sda1             477M   41M  411M  10% /boot
/dev/mapper/vg_cloudera3-lv_home
                      4.6G  9.6M  4.4G   1% /home
10.158.1.112:/nfs_test/adamhuan
                       48G   14G   32G  31% /nfs_test/client
[root@cloudera3 ~]# 
[root@cloudera3 ~]# mount | grep adamhuan
10.158.1.112:/nfs_test/adamhuan on /nfs_test/client type nfs (rw,vers=4,addr=10.158.1.112,clientaddr=10.158.1.113)
[root@cloudera3 ~]# 

113上看看NFS中的目录权限:

[root@cloudera3 ~]# cd /nfs_test/client/
[root@cloudera3 client]# ll
total 0
-rw-r--r-- 1 adamhuan adamhuan 0 Apr 23 14:31 me
[root@cloudera3 client]# 

这个是没问题的,不过也仅仅是显示。

写入还是有问题的:
113:

[root@cloudera3 ~]# cd /nfs_test/client/
[root@cloudera3 client]# ls -ltr
total 0
-rw-r--r-- 1 adamhuan adamhuan 0 Apr 23 14:31 me
[root@cloudera3 client]# 
[root@cloudera3 client]# touch you
touch: cannot touch `you': Permission denied
[root@cloudera3 client]# 

看看操作系统版本:

[root@cloudera3 client]# cat /etc/redhat-release 
CentOS release 6.9 (Final)
[root@cloudera3 client]# 

但是,如果NFS SERVER的操作系统版本是:RHEL 6.7,就会遇到我标题所描述的问题:
NFS SERVER

[root@quickstart ~]# cat /etc/redhat-release 
CentOS release 6.7 (Final)
[root@quickstart ~]# 
[root@quickstart ~]# cat /etc/exports 
/nfs_test 192.168.174.0/24(rw)
[root@quickstart ~]# 
[root@quickstart ~]# rpm -qa | grep nfs
nfs-utils-lib-1.1.5-13.el6.x86_64
nfs-utils-1.2.3-75.el6_9.x86_64
nfs-utils-lib-devel-1.1.5-13.el6.x86_64
[root@quickstart ~]# 
[root@quickstart ~]# showmount -e localhost
Export list for localhost:
/nfs_test 192.168.174.0/24
[root@quickstart ~]# 
[root@quickstart ~]# ls -ltr /nfs_test/
total 0
-rw-r--r-- 1 adamhuan root 0 Apr 22 23:50 me
[root@quickstart ~]# 
[root@quickstart ~]# id adamhuan
uid=2000(adamhuan) gid=2000(adamhuan) groups=2000(adamhuan)
[root@quickstart ~]# 

NFS Client

[root@jumpserver ~]# cat /etc/redhat-release 
CentOS Linux release 7.1.1503 (Core) 
[root@jumpserver ~]# 
[root@jumpserver ~]# mkdir /nfs_test
[root@jumpserver ~]# id adamhuan
uid=1000(adamhuan) gid=1000(adamhuan) groups=1000(adamhuan)
[root@jumpserver ~]# 
[root@jumpserver ~]# mount 192.168.174.136:/nfs_test /nfs_test/
[root@jumpserver ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/sda3                   45G  6.4G   39G  15% /
devtmpfs                   3.9G     0  3.9G   0% /dev
tmpfs                      3.9G   80K  3.9G   1% /dev/shm
tmpfs                      3.9G   25M  3.8G   1% /run
tmpfs                      3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1                  297M  112M  185M  38% /boot
tmpfs                      782M     0  782M   0% /run/user/0
tmpfs                      782M     0  782M   0% /run/user/42
/dev/dm-1                   10G  1.2G  8.8G  12% /var/lib/docker/devicemapper/mnt/2c9174581b1725cac44d97460dc9405187e96c7669e949de3b1f37ce83263a38
shm                         64M     0   64M   0% /var/lib/docker/containers/632a9a99b1f7c01790efa0c015d66b4190a26dd489ecc65df98f1f5e209d43e9/mounts/shm
192.168.174.136:/nfs_test   55G  9.2G   43G  18% /nfs_test
[root@jumpserver ~]# 
[root@jumpserver ~]# ls -ltr /nfs_test/
total 0
-rw-r--r-- 1 nobody nobody 0 Apr 22 23:50 me
[root@jumpserver ~]# 
[root@jumpserver ~]# rpm -qa | grep nfs
libnfsidmap-0.25-11.el7.x86_64
nfs4-acl-tools-0.3.3-13.el7.x86_64
nfs-utils-1.3.0-0.8.el7.x86_64
[root@jumpserver ~]# 
[root@jumpserver ~]# mount | grep nfs
192.168.174.136:/nfs_test on /nfs_test type nfs4 (rw,relatime,vers=4.0,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.174.131,local_lock=none,addr=192.168.174.136)
[root@jumpserver ~]# 

解决方法:
Step 1:
挂载的时候指定版本:

[root@jumpserver ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/sda3                   45G  6.4G   39G  15% /
devtmpfs                   3.9G     0  3.9G   0% /dev
tmpfs                      3.9G   80K  3.9G   1% /dev/shm
tmpfs                      3.9G   25M  3.8G   1% /run
tmpfs                      3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1                  297M  112M  185M  38% /boot
tmpfs                      782M     0  782M   0% /run/user/0
tmpfs                      782M     0  782M   0% /run/user/42
/dev/dm-1                   10G  1.2G  8.8G  12% /var/lib/docker/devicemapper/mnt/2c9174581b1725cac44d97460dc9405187e96c7669e949de3b1f37ce83263a38
shm                         64M     0   64M   0% /var/lib/docker/containers/632a9a99b1f7c01790efa0c015d66b4190a26dd489ecc65df98f1f5e209d43e9/mounts/shm
192.168.174.136:/nfs_test   55G  9.2G   43G  18% /nfs_test
[root@jumpserver ~]# 
[root@jumpserver ~]# umount /nfs_test
[root@jumpserver ~]# 
[root@jumpserver ~]# df -h | grep nfs
[root@jumpserver ~]# 
[root@jumpserver ~]# mount -t nfs -o vers=3 192.168.174.136:/nfs_test /nfs_test/
[root@jumpserver ~]# 
[root@jumpserver ~]# df -h | grep nfs
192.168.174.136:/nfs_test   55G  9.2G   43G  18% /nfs_test
[root@jumpserver ~]# 
[root@jumpserver ~]# mount | grep nfs
192.168.174.136:/nfs_test on /nfs_test type nfs (rw,relatime,vers=3,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=192.168.174.136,mountvers=3,mountport=55104,mountproto=udp,local_lock=none,addr=192.168.174.136)
[root@jumpserver ~]# 

再次查看NFS Client路径的权限:

[root@jumpserver ~]# ls -ltr /nfs_test/
total 0
-rw-r--r-- 1 2000 root 0 Apr 22 23:50 me
[root@jumpserver ~]# 

Step 2:
将NFS的客户端与服务端的UID/GID改成一致的:

Server

[root@quickstart ~]# id adamhuan
uid=2000(adamhuan) gid=2000(adamhuan) groups=2000(adamhuan)
[root@quickstart ~]# 

Client

[root@jumpserver ~]# id adamhuan
uid=1000(adamhuan) gid=1000(adamhuan) groups=1000(adamhuan)
[root@jumpserver ~]# 
[root@jumpserver ~]# usermod -u 2000 adamhuan
[root@jumpserver ~]# 
[root@jumpserver ~]# id adamhuan
uid=2000(adamhuan) gid=1000(adamhuan) groups=1000(adamhuan)
[root@jumpserver ~]# 

这时候再查看,NFS的nobody的问题就没有了:

[root@jumpserver ~]# ls -ltr /nfs_test/
total 0
-rw-r--r-- 1 adamhuan root 0 Apr 22 23:50 me
[root@jumpserver ~]# 

————————————————————————
Done。

说点什么

avatar

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

  Subscribe  
提醒