首页 > 配置 NFS 出错, permisson denied

配置 NFS 出错, permisson denied

参照这篇教程在局域网里搭建成功了, 13.04 到 13.04 两个都是桌面版:
然后我按照一样的方案从局域网的桌面版, 连接 VPS 上的 Server 版 13.04 .
操作步骤一样的, 都是按照教程, 然后添加 anonuid 等等..
/etc/exports 内容为:

/opt/nfs/ *(rw,sync,all_squash,no_subtree_check)

报错是这样的:

➤➤ sudo mount -t nfs jiyinyiyong.info:/opt/test/ work/ -v
mount.nfs: timeout set for Sun Jun 23 08:36:18 2013
mount.nfs: trying text-based options 'vers=4,addr=76.164.199.10,clientaddr=192.168.1.108'
mount.nfs: mount(2): Operation not permitted
mount.nfs: trying text-based options 'addr=76.164.199.10'
mount.nfs: prog 100003, trying vers=3, prot=6
mount.nfs: trying 76.164.199.10 prog 100003 vers 3 prot TCP port 2049
mount.nfs: prog 100005, trying vers=3, prot=17
mount.nfs: trying 76.164.199.10 prog 100005 vers 3 prot UDP port 41166
mount.nfs: mount(2): Permission denied
mount.nfs: access denied by server while mounting jiyinyiyong.info:/opt/test/

此外:

➤➤ sudo showmount -e jiyinyiyong.info
Export list for jiyinyiyong.info:
/opt/nfs *
➤➤ rpcinfo -p jiyinyiyong.info
   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
    100024    1   udp  48387  status
    100024    1   tcp  36828  status
    100003    2   tcp   2049  nfs
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    2   tcp   2049
    100227    3   tcp   2049
    100003    2   udp   2049  nfs
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    2   udp   2049
    100227    3   udp   2049
    100021    1   udp  35656  nlockmgr
    100021    3   udp  35656  nlockmgr
    100021    4   udp  35656  nlockmgr
    100021    1   tcp  54067  nlockmgr
    100021    3   tcp  54067  nlockmgr
    100021    4   tcp  54067  nlockmgr
    100005    1   udp  36975  mountd
    100005    1   tcp  45682  mountd
    100005    2   udp  43618  mountd
    100005    2   tcp  42398  mountd
    100005    3   udp  60350  mountd
    100005    3   tcp  54424  mountd

另外检查 selinux 的状态是 desabled, 应该可以排除

%%➤ sudo setenforce 0
setenforce: SELinux is disabled

Selinux 的限制

问题暂时解决了, 并不确定问题在哪里,, 说一下我查找资料时遇到的说法, 希望有帮助:
比较可能的问题是这里说的, KVM 上的 NFS, 被 Selinux 屏蔽了一些功能,
因此需要修改 Selinux 的策略来允许 NFS 资源的访问,, 链接里:
http://bbs.chinaunix.net/forum.php?mod=viewthread&action=printable&tid=1919880
但也有人提到说, 里边的文件没有, 那怎么办呢?
我搜索文档, 也提到了 Selinux 对 NFS 存在限制, 需要设置:
http://docs.fedoraproject.org/en-US/Fedora/13/html/Managing_Confined_Services/sect-Managing_Confined_Services-NFS-Configuration_Examples.html
https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Managing_Confined_Services/sect-Managing_Confined_Services-NFS-Configuration_Examples.html
其实文档没看懂.. 直接按上边命令尝试了一下, 结果运行成功了..

相关的 Bash 历史

下面是 Bash history 对应时间里的命令:

 1285  sudo vim /etc/selinux/semanage.conf
 1286  setsebool
 1287  sudo aptitude install policycoreutils
 1288  setsebool -P nfs_export_all_rw off
 1289  sudo setsebool -P nfs_export_all_rw off
 1290  l
 1291  sudo exportfs -rf
 1292  sudo setsebool -P nfs_export_all_rw 1
 1293  sudo service nfs restart
 1294  sudo service nfs-kernel-server restart
 1295  sudo exportfs -rv

我觉得起作用的可能是下面的命令, 但我没法重现了:

sudo setsebool -P nfs_export_all_rw 1
sudo service nfs restart

完成的效果

附上我运行成功时的 /etc/exports 文件内容:

/opt/nfs *(rw,sync,no_subtree_check,insecure,all_squash,anonuid=1000,anongid=1000)

完成后, 虽然有 170+ms 的延时, 但我本地保存文件, 服务器上监视保存事件, 延时不到半秒. 不错:

fs = require 'fs'

fs.watchFile 'b.txt', interval: 100, ->
  console.log 'file change'

kernel space 和 user space

搜索资料中间看到有说法, VPS 上不支持 kernel space 的 KVM 运行,
我尝试了安装 UNFS3, 安装运行, 但不懂配置搜不到文档最终放弃.
按现在我的结果, KVM 的 VPS 上是支持 kernel space 运行的.

【热门文章】
【热门文章】