关于NFS指定用户显示nobody的解决方法(网上搜索的)

回复 收藏
本帖最后由 dadatian 于 2016-8-23 18:03 编辑

在NFS指定用户的操作教学视频演示按照视频的操作设置挂载NFS指定版本的命令一直显示nobody,在网上查到的命令指定NFS版本为3后显示为指定的用户,我也弄不明白到底按照视频的操作哪里出现了问题。此帖的详细内容发到论坛,希望对大家有帮助,帖子的第二种操作本人没有实验,有兴趣的可试验一下。
原文如下:http://my.oschina.net/panzhc/blog/191663
nfs只能挂载为nobody的解决方法
panzhc
发布时间: 2014/01/09 11:24 阅读: 4371 收藏: 3 点赞: 1 评论: 2
不得不承认centos6较centos5发生了很大的变化,在新部署的centos 6.4上又遇到nfs挂载的问题。问题现象是,在配置完nfs后,无论配置里指定的是何用户,挂载成功后显示的只能是nobody用户,本想通过修改/etc/passwd和/etc/group对应的uid和gid号解决,发现重新挂载后,用户仍然是nobody 。

造成该问题的原因是,在centos 6版本中默认使用的nfs-v4版本,其提供了称为rpc.idmapd 的守护进程,并使用 /etc/idmapd.conf 的配置文件。当请求加载nfsv4 时,该守护进程将处理 UID 和 GID 映射。默认使用nis,没有nis它会自动映射成nobody用户。

既然找到了原因,找解决方法也就不难了,大致找了下网上的解决方法,分如下两种。

方法一:mount中指定参数法

在mount挂载的时候指定使用v3版本去挂载,如下:

mount -t nfs -o vers=3 ip:/data1 /data1
显然不推荐该方法,既然有了V4版本,其肯定较V3版本做了很多优化,如果再用V3,显然跟不上时代的步伐 。

方法二:修改/etc/idmapd.conf文件

修改前,先看下为什么会mount成nobody,在/etc/idmapd.conf文件中,mapping配置下有如下两句 。

[Mapping] Nobody-User = nobody Nobody-Group = nobody
有人肯定说,直接修改这两句,变成想要的用户和组不就行了 ? 当然没这么简单,这里改了后,会发现mount的目录只有读的权限,没有写的权限 。想在彻底的解决该文件,只需要客户端和服务端各改一行就行了。修改方法为,取消/etc/idmapd.conf中如下行的注释,改为你所使用的根域名:

#Domain = local.domain.edu
如:都改为:

Domain = 361way.com
更改完成后,重启idmapd服务:

service rpcidmapd restart
至此,问题解决。记得是客户端和服务端都要修改才行,只改一处,问题仍然无法解决 。另外在umount的过程中,还可能遇到无法umount的问题:

root@test:/# umount /data1/nfs/ umount.nfs: /data1/nfs: device is busy umount.nfs: /data1/nfs: device is busy
遇到该问题时只需要使用fuser命令就可以解决:

root@test:/# fuser -km /data1/nfs/ 或 root@test:/# fuser -f /data1/nfs/
执行完上面的操作后,再去umount就可以了。fuser上面用到的几个参数的意义如下:
-f silently ignored (for POSIX compatibility) -i ask before killing (ignored without -k) -k kill processes accessing the named file -m show all processes using the named filesystems
2016-08-23 17:57 举报
已邀请:
0

dadatian

赞同来自:

我又重新按照视频教程的操作步骤重新又做了一遍,这次就正常按照视频的操作设置挂载NFS指定版本的命令挂载后用户显示为服务端指定的用户了
[root@CentOS-Lnmp ~]# mount -t nfs -onolock,nfsvers=3 192.168.1.10:/tmp/test/ /tmp/test/
[root@CentOS-Lnmp ~]# cd /tmp
[root@CentOS-Lnmp tmp]# ls
test  yum.log
[root@CentOS-Lnmp tmp]# cd test/
[root@CentOS-Lnmp test]# ls
11.txt  1.txt
[root@CentOS-Lnmp test]# ll
总用量 0
-rw-r--r-- 1 test test 0 8月  14 02:24 11.txt
-rw-r--r-- 1 test test 0 8月  14 02:13 1.txt

并且检查了笔记是否漏掉视频中所作的操作,但并没有发现哪里有不同,并且做不限制root用户的实验时,出现这个问题:
[root@CentOS-Lnmp ~]# mount -t nfs -onolock,nfsvers=3 192.168.1.10:/tmp/test/ /tmp/test/
mount.nfs: requested NFS version or transport protocol is not supported
指定版本为4就可以挂载上:
[root@CentOS-Lnmp ~]# mount -t nfs -onolock,nfsvers=4 192.168.1.10:/tmp/test/ /tmp/test/
[root@CentOS-Lnmp ~]# cd /tmp/test/
[root@CentOS-Lnmp test]# ls
11.txt  1.txt
[root@CentOS-Lnmp test]# ll
总用量 0
-rw-r--r-- 1 nobody nobody 0 8月  14 02:24 11.txt
-rw-r--r-- 1 nobody nobody 0 8月  14 02:13 1.txt
检查测试发现好像是我重启相关服务的顺序不对导致出现这个错误,我是把两个服务都重启,一开始我是先重启的rpcbind后重启的nfs,后来我把启动顺序掉过来做一遍,在客户端重新挂载就可以了:
[root@CentOS-Lnmp ~]# mount -t nfs -onolock,nfsvers=3 192.168.1.10:/tmp/test/ /tmp/test/
[root@CentOS-Lnmp ~]# cd /tmp/test/
[root@CentOS-Lnmp test]# ll
总用量 0
-rw-r--r-- 1 test test 0 8月  14 02:24 11.txt
-rw-r--r-- 1 test test 0 8月  14 02:13 1.txt
[root@CentOS-Lnmp test]# touch 222.txt
[root@CentOS-Lnmp test]# ll
总用量 0
-rw-r--r-- 1 test test 0 8月  14 02:24 11.txt
-rw-r--r-- 1 test test 0 8月  14 02:13 1.txt
-rw-r--r-- 1 root root 0 8月  24 22:39 222.txt
[root@CentOS-Lnmp test]#
不知道还有没人和我出现同样问题的。

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: