我对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,我在node1(10.1.3.58)上运行nfs server。下面是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范围也不工作,例如,0.0.0.0
,10.1.3.*
,10.1.0.0/16
在/etc/exports
文件中我们可以配置NFS服务器的共享。典型的条目结构如下:
export_directory host_designation(options)
export_directory
—正在导出的NFS共享host_designation
—一个或多个可以访问此导出的主机或网络
host_designation
(NFS客户端)可以通过多种方式指定:
- netgroups
- 多系统/通配符
- IP网络
在你的情况下,你使用通配符方法不应该与IP地址一起使用,因为它可能导致意外行为(我不建议使用例如10.1.3.*
)。*
或?
通配符可以与FQDN
或hostname
一起使用。
在我看来,0.0.0.0/0
不是NFS的有效语法。如果你需要导出共享给每个人,你可以使用*
,甚至让host_designation
留空,例如:
/mnt/node1nfsstorage (rw,sync,no_subtree_check,insecure)
你可以在这里找到更多的信息和例子。
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话题