不使用 Portmapper 挂载 NFS 共享

不使用 Portmapper 挂载 NFS 共享

我正在尝试通过 SSH 隧道使用 NFS 来共享目录。我明确指定了 TCP 端口 2049,但显然我还需要做更多。这似乎与“portmapper”服务有关,但我对此并不熟悉。是否可以不使用 portmapper 服务来操作 NFS?正如我所说,我明确指定了我想要使用的端口。

如下文所示,如果我让客户端直接连接到共享,一切都会正常。但是,如果我让客户端尝试通过 SSH 隧道连接到共享,则无法正常工作。

我该如何解决这个问题?

服务器(我的 NFS 服务器)

root@my-NFS-Server:~# ls -l /consolidate
total 1
-rw-rw-r-- 1 root automation 0 Dec 19 13:33 thisFileExistsOnlyInShareOnServer

root@my-NFS-Server:~# cat /etc/fstab
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/zvol/rpool/swap none swap sw 0 0
proc /proc proc defaults 0 0
/consolidate /export/consolidate none bind 0 0

root@my-NFS-Server:~# cat /etc/exportfs
/export *(sync,rw,wdelay,no_root_squash,no_subtree_check,sec=sys,secure,no_all_squash,fsid=0)
/export/consolidate *(sync,rw,wdelay,no_root_squash,no_subtree_check,sec=sys,secure,no_all_squash)

root@my-NFS-Server:~# grep NEED_SVCGSSD /etc/default/nfs-kernel-server
NEED_SVCGSSD=no

root@my-NFS-Server:~# service nfs-kernel-server restart

root@my-NFS-Server:~# ssh -N -R localhost:2049:localhost:2049 root@my-NFS-Client

客户端(my-NFS-Client)

root@my-NFS-Client-1:~# ls -l /consolidate
total 0

root@my-NFS-Client-1:~# mount -v -t nfs4 -o proto=tcp,port=2049 my-NFS-Server:/consolidate /consolidate
mount.nfs4: timeout set for Wed Dec 20 12:51:49 2017
mount.nfs4: trying text-based options 'proto=tcp,port=2049,vers=4.2,addr=my-NFS-Server,clientaddr=my-FNS-Client'

root@my-NFS-Client-1:~# ls -l /consolidate
total 1
-rw-rw-r-- 1 root automation 0 Dec 19 13:33 thisFileExistsOnlyInShareOnServer

root@my-NFS-Client-1:~# umount /consolidate

root@my-NFS-Client-1:~# ls -l /consolidate
total 0

root@my-NFS-Client-1:~# mount -v -t nfs4 -o proto=tcp,port=2049 localhost:/consolidate /consolidate
mount.nfs4: timeout set for Wed Dec 20 12:52:16 2017
mount.nfs4: trying text-based options 'proto=tcp,port=2049,vers=4.2,addr=127.0.0.1,clientaddr=127.0.0.1'
mount.nfs4: mount(2): Operation not permitted
mount.nfs4: trying text-based options 'proto=tcp,port=2049,addr=127.0.0.1'
mount.nfs4: prog 100005, trying vers=3, prot=6
mount.nfs4: portmap query failed: RPC: Program not registered
mount.nfs4: requested NFS version or transport protocol is not supported

root@my-NFS-Client-1:~# ls -l /consolidate
total 0

答案1

我通过执行以下操作成功使 NFS over SSH 正常运行:

  • service stop portmap释放本地 TCP 端口 111 (portmapper)
    • 这似乎真的对我来说很糟糕,但因为我使用的是玩具虚拟机,所以我还是这么做了。毫无疑问这会破坏一些东西……
  • ssh user@remote -L 111:nfs-server-name:111
  • rpcinfo -p localhost并找到使用的端口mountd,在我的例子中是 300
  • ssh user@remote -L 300:nfs-server-name:300
  • mount -v -t nfs -o proto=tcp,vers=3,nolock localhost:/path /mountpoint

相关内容