需求:

需要在k8s中使用到NFS,应该是在linux中配置nfs的,但是由于是在windows开发,所以有了在windwos配置nfs的需求

1.安装haneWIN

HaneWin NFS Server 是一个可以帮助快速搭建NFS服务器的软件

https://www.hanewin.net/nfs-e.htm

2.破解haneWIN

haneWIN NFS Server 1.2.10 注册机下载: haneWIN NFS Server Keygen.7z (8265) (解压密码:astray.cn)

运行注册机,输入Name,点击左边的按钮,生成Serial

image-20230510154915775

打开NFS Server,在注册界面输入注册机生成的License key和Your name,并点击Register

image-20230510155110169

点击help - About 查看是否注册成功

image-20230510155024015

3.配置exports文件

1
2
# exports example
E:\opengms-lab\container\nfs -public

上述配置的意思是将E:\opengms-lab\container\nfs目录共享出去

将该exports文件覆盖到软件的安装位置

image-20230510155212303

其他配置参考

image-20230510160807932

4.linux挂载设置

创建目录

1
[root@localhost ~]# mkdir /opt/windowsNFS

挂载

1
[root@localhost ~]# mount -t nfs 172.21.212.240:/e/opengms-lab/container/nfs /opt/windowsNFS

若无nfs功能

1
2
3
[root@localhost cdrom]# yum install -y nfs-utils
#安装nfs功能
#需要联网或者配置本地yum源

5.挂载不上的可能原因

1
2
[root@clustermaster opt]# mount -t nfs 172.21.212.240:/e/opengms-lab/container/nfs /opt/windowsNFS
mount.nfs: Connection timed out

防火墙惹得祸:需要禁用防火墙

设置windows防火墙的入栈规则(TCP,UDP) (另外对配置文件规则,就看你的网络连接是公用、专用、域的哪种了) <经验证,使用hanWinNFS或windows自带的NFS服务 都是仅开放111,1058,2049 就可以了>

img

到这里基本就ok了,但正式给某学校应用时发现还是不得,后来发现学校做了阻止策略中把端口全部禁止了,要把禁止策略中的 111,1058,2049给去掉就可以了。

img

6.检查挂载是否有问题

mount -a 可跳过, 直接用 df -h 查看

1
[root@localhost ~]# mount -a

重启检查目录是否挂载

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
[root@localhost ~]# df -h
文件系统                                     容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root                       47G  7.5G   40G   16% /
devtmpfs                                     895M     0  895M    0% /dev
tmpfs                                        911M     0  911M    0% /dev/shm
tmpfs                                        911M   28M  884M    4% /run
tmpfs                                        911M     0  911M    0% /sys/fs/cgroup
/dev/sda1                                   1014M  170M  845M   17% /boot
tmpfs                                        183M   12K  183M    1% /run/user/42
172.21.212.240:/e/opengms-lab/container/nfs  782G  684G   99G   88% /opt/windowsNFS

7.linux无法写入文件

具体做法:

1.在haneWIN NFS Server的exports文件中增加 -maproot:0

image-20230510163236222

2.重新挂载

1
[root@clustermaster /]# umount 172.21.212.240:/e/opengms-lab/container/nfs

取消挂载后原本挂载的文件夹可能会出现错误

1
2
3
4
5
6
7
8
[root@clustermaster opt]# ll
ls: 无法访问windowsNFS: 失效文件句柄
总用量 4
drwxr-xr-x  3 root root   17 2月   8 10:48 cni
drwx--x--x  4 root root   28 2月   7 20:14 containerd
drwxr-xr-x  5 root root 4096 4月  27 20:59 k8s
drwxr-xr-x. 2 root root    6 9月   7 2017 rh
d?????????? ? ?    ?       ?            ? windowsNFS

需执行以下操作修复文件夹

1
2
3
4
5
6
7
8
[root@clustermaster opt]# umount -l /opt/windowsNFS
[root@clustermaster opt]# ll
总用量 4
drwxr-xr-x  3 root root   17 2月   8 10:48 cni
drwx--x--x  4 root root   28 2月   7 20:14 containerd
drwxr-xr-x  5 root root 4096 4月  27 20:59 k8s
drwxr-xr-x. 2 root root    6 9月   7 2017 rh
drwxr-xr-x  2 root root    6 5月  10 15:36 windowsNFS

再次挂载nfs

1
[root@clustermaster opt]# mount -t nfs 172.21.212.240:/e/opengms-lab/container/nfs /opt/windowsNFS