更多: zhilu jiaocheng

解决方案

这是在客户端挂载 NFS 的常见问题,可能由于许多问题而发生。
以下是一些最常见的问题。

1. 尝试挂载 NFSv3

有时 NFS 服务器可能只支持 NFSv3 连接。
默认情况下,mount 命令使用 NFSv4,这可能会导致错误。
为避免这种情况,请在挂载共享时指定 NFSv3.

# mount -t nfs -o nfsvers=3 x.x.x.x:/share /mnt

2. 检查 /etc/exports 以获取正确的共享选项

确保 /etc/exports 正确引用正确的 NFS 客户端信息以提供访问权限。
一些 NFS 服务器要求 NFS 客户端名称可解析为 IP,因此应可通过 DNS 解析或者在 NFS 服务器的 /etc/hosts 中指定。
/etc/exports 文件的格式为:

dir client1 (options) [client2(options)...]

客户端选项包括(首先列出默认值):

ro / rw :

a) ro :允许客户端只读访问共享。

b) rw :允许客户端对共享进行读写访问。

sync / async

a) sync:NFS 服务器仅在先前请求所做的更改写入磁盘后才回复请求。

b) async :指定服务器不必等待。

wdelay/no_wdelay

a) wdelay :当 NFS 服务器怀疑另一个写请求即将到来时,它会延迟提交写请求。

b) no_wdelay :使用此选项禁用延迟。
no_wdelay 选项只能在启用默认同步选项时启用。

no_all_squash/all_squash :

a) no_all_squash :不改变远程用户的映射。

b) all_squash :压缩包括 root 在内的所有远程用户。

root_squash/no_root_squash :

a) root_squash :防止远程连接的 root 用户拥有 root 访问权限。
有效压缩远程 root 权限。

b) no_root_squash :禁用根挤压。

例子 :

# vi /etc/exports
/test nfs_client(rw)

3.检查NFS服务器权限

共享 NFS 共享的 NFS 服务器可能存在问题。
尝试在另一个 NFS 客户端上安装有问题的共享,以排除 NFS 服务器出现问题的可能性。

在服务器端为 nfs 导出设置权限为 (ro,no_root_squash,sync) 并运行命令:

# exportfs -r

然后尝试挂载NFS共享目录。
如果通过域或者主机名在 /etc/exports 中指定 NFS 客户端确保域名映射到正确的 IP,例如 /etc/hosts 中的不正确条目可能会导致访问被拒绝。

4.使用tcpdump

在极少数情况下,我们可能必须使用 tcpdump 来捕获挂载操作的 tcpdump。
首先运行以下命令开始捕获网络数据包。
在另一个终端启动 NFS 挂载操作。

# tcpdump -s0 -i [eth#] host [nfs_server_ip] -w /tmp/tcpdump.pcap

问题

在 NFS 客户端上从 CentOS/RHEL NFS 服务器挂载 nfs 共享会出现如下所示的错误:

# mount -t nfs x.x.x.x:/share /mnt
mount.nfs: access denied by server while mounting x.x.x.x:/share

mount.nfs:当挂载x.x.x.x:/share时,服务器拒绝访问。

我们可以尝试使用详细选项运行 mount 命令以获取有关该问题的详细错误信息。

# mount -t nfs -vvvv server.example.com:/share /mnt
mount.nfs: timeout set for Fri Mar 9 17:56:57 2018
mount.nfs: trying text-based options 'vers=4.1,addr=x.x.x.x,clientaddr=x.x.x.x'
mount.nfs: mount(2): Protocol not supported
mount.nfs: trying text-based options 'vers=4.0,addr=x.x.x.x,clientaddr=x.x.x.x'
mount.nfs: mount(2): Protocol not supported
mount.nfs: trying text-based options 'addr=x.x.x.x'
mount.nfs: prog 100003, trying vers=3, prot=6
mount.nfs: trying x.x.x.x prog 100003 vers 3 prot TCP port 2049
mount.nfs: prog 100005, trying vers=3, prot=17
mount.nfs: trying x.x.x.x prog 100005 vers 3 prot UDP port 300
mount.nfs: mount(2): Permission denied
mount.nfs: access denied by server while mounting server.example.com:/share
mount.nfs: access denied by server while mounting
日期:2020-09-17 00:14:06 来源:oir作者:oir