0.0.0.0/0 对 nfs 配置不可行

0.0.0.0/0 is not feasible for nfs configuration

我是 NFS(网络文件系统)的新手。 我试图在 k8s 集群中创建自己的 nfs 系统。 仅供参考,以下是我的 IP 设置。

# k8s cluster ip settings
master1 ansible_host=10.1.3.245 ip=10.1.3.245
node1 ansible_host=10.1.3.58 ip=10.1.3.58
node2 ansible_host=10.1.3.191 ip=10.1.3.191
node3 ansible_host=10.1.3.88 ip=10.1.3.88
node4 ansible_host=10.1.3.74 ip=10.1.3.74
node5 ansible_host=10.1.3.228 ip=10.1.3.228

所有节点都是 ubuntu18.04,我 运行 节点 1 (10.1.3.58) 上的 nfs 服务器。 下面是 node1 上的 /etc/hosts 文件。

# /etc/hosts
127.0.0.1 localhost localhost.localdomain

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback localhost6 localhost6.localdomain
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
# Ansible inventory hosts BEGIN
10.1.3.58 node1.cluster.local node1
10.1.3.191 node2.cluster.local node2
10.1.3.88 node3.cluster.local node3
10.1.3.74 node4.cluster.local node4
10.1.3.228 node5.cluster.local node5
10.1.3.245 master1.cluster.local master1
# Ansible inventory hosts END

为了服务 nfs 服务器,我编辑了 /etc/exports 文件。 据我了解,/etc/exports 文件的每一行格式如下: <path> <allowed_ips>(options).

例如 /mnt/node1nfsstorage 0.0.0.0/0(rw,sync,no_subtree_check,insecure) 表示允许从任何地方访问 nfs 目录 /mnt/node1nfsstorage

当我使用上面的配置时,我无法从 master1 访问 nfs 服务器 (node1)。 (我打开了 2049 端口,这是 nfs 的默认端口!)。仅供参考,这是我使用的命令。

# from master1
ubuntu@master1:~$ sudo mount 10.1.3.58:/mnt/node1nfsstorage /home/ubuntu/mount
mount.nfs: access denied by server while mounting 10.1.3.58:/mnt/node1nfsstorage

# from /var/log/syslog from node1
ubuntu@node1:/mnt$ tail -f /var/log/syslog | grep nfs
Jan 19 06:23:50 node1 kernel: [190747.809254] nfsd_dispatch: vers 4 proc 0  # I also cannot understand this log message

但是当我将配置更改为 /mnt/node1nfsstorage *(rw,sync,no_subtree_check,insecure) 时,它终于起作用了。

我认为*与域名通配符有关,0.0.0.0/0表示ip范围。为什么只有 * 适合我的情况?任何人都可以帮助我理解这一点吗?经过一些测试,我发现有几个 ip 或 ip ranges 也不起作用,例如 0.0.0.010.1.3.*10.1.0.0/16

ubuntu 上的手册页是这样描述导出的:

  IP networks
              You can also export directories to all hosts on an IP (sub-) network simultaneously. This is done by specifying an IP address and netmask pair  as  address/netmask
              where the netmask can be specified in dotted-decimal format, or as a contiguous mask length.  For example, either `/255.255.252.0' or `/22' appended to the network
              base IPv4 address results in identical subnetworks with 10 bits of host. IPv6 addresses must use a contiguous mask length and must not be inside square brackets to
              avoid  confusion  with  character-class  wildcards.  Wildcard  characters  generally do not work on IP addresses, though they may work by accident when reverse DNS
              lookups fail.

但我也有同样的想法,我无法使用 ip/netmask 并结束了使用通配符 *,我发现了更多有同样问题的帖子,也许这不能解决你的问题但是也许可以为您确认通配符或IP/netmask的工作方式具有相同的结果:

Serverfault topic

/etc/exports 文件中,我们可以配置NFS 服务器的共享。 典型条目具有以下结构:

export_directory host_designation(options)

其中:
export_directory - 正在导出 NFS 共享
host_designation - 可以访问此导出的一个或多个主机或网络

host_designation(NFS 客户端)可以通过多种方式指定:

  • 单主机
  • 网络组
  • 多个系统/通配符
  • IP 网络

在您的情况下,您使用的是 不应 与 IP 地址一起使用的通配符方法,因为它可能会导致意外行为(我不建议使用例如 10.1.3.*). *? 通配符可与 FQDNhostname.

一起使用

在我看来 0.0.0.0/0 不是 NFS 的有效语法。如果您需要将共享导出给所有人,您可以使用 * 甚至将 host_designation 留空,例如:

/mnt/node1nfsstorage  (rw,sync,no_subtree_check,insecure)

您可以找到更多信息和示例 here