环境说明:
配置 NFS 容器内部配置 NFS 特殊说明
在 docker 中开启 NFS 服务需要挂载主机的目录,才能通过 NFS 共享。exp: docker run -dit -v /mnt:/data xxxx, 只有容器内的 nfs_data 才可以进行 nfs 共享 环境说明
Docker 容器 服务器IP 172.21.0.111 容器内目录 /data Docker 容器 客户端IP 172.21.0.150 容器内目录 /nfs_data 注意事项:
服务器关机时,先关闭 NFS 客户端,最后关闭 NFS 服务端。 服务器开机时,先开启 NFS 服务端,最后开启 NFS 客户端。 服务器配置 因为 centos7 自带了 rpcbind,所以不用安装 rpc 服务,rpc 监听在 111 端口,可以使用 ss -tnulp | grep 111 查看 rpc 服务是否自动启动,如果没有启动,就 systemctl start rpcbind 启动 rpc 服务。rpc 在 nfs 服务器搭建过程中至关重要,因为 rpc 能够获得 nfs 服务器端的端口号等信息,nfs 服务器端通过 rpc 获得这些信息后才能连接 nfs 服务器端
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 yum -y install nfs-utils [root@b9fed615b76b ~] nfs-utils-2.3.3-31.el8.x86_64 /data 172.21.0.0/24(rw,sync,no_root_squash,insecure) systemctl restart nfs-server [root@b9fed615b76b ~] program vers proto port service 100000 4 tcp 111 portmapper 100000 3 tcp 111 portmapper 100000 2 tcp 111 portmapper 100000 4 udp 111 portmapper 100000 3 udp 111 portmapper 100000 2 udp 111 portmapper 100005 1 udp 20048 mountd 100005 1 tcp 20048 mountd 100005 2 udp 20048 mountd 100005 2 tcp 20048 mountd 100005 3 udp 20048 mountd 100005 3 tcp 20048 mountd 100003 3 tcp 2049 nfs 100003 4 tcp 2049 nfs 100227 3 tcp 2049 nfs_acl 100021 1 udp 43144 nlockmgr 100021 3 udp 43144 nlockmgr 100021 4 udp 43144 nlockmgr 100021 1 tcp 44159 nlockmgr 100021 3 tcp 44159 nlockmgr 100021 4 tcp 44159 nlockmgr [root@b9fed615b76b ~] Export list for localhost: /data 172.21.0.0/24 chown -R 777 /data systemctl enable nfs-server systemctl enable rpcbind
客户端配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 yum -y install nfs-utils rpcinfo -p [root@85d31196f0c6 neo4j-community-3.3.5] Export list for 172.21.0.111: /data 172.21.0.0/24 mount -t nfs 172.21.0.111:/data /nfs_data
必选配置 Linux 关机或重启时提示 A stop job is running for Linux 关机或重启时提示 A stop job is running for .. 导致关机慢。
修改方法
1 2 3 4 5 6 7 vim /etc/systemd/system.conf 修改下面两个变量为: 生产服务器60s,开发服务器10s DefaultTimeoutStartSec=60s DefaultTimeoutStopSec=60s DefaultRestartSec=100ms systemctl daemon-reload
可选配置 挂载优化 在企业工作场景,一般来说,NFS 服务器共享的只是普通静态数据(图片、附件、视频),不需要执行 suid、exec 等权限,挂载的这个文件系统只能作为数据存取之用,无法执行程序,对于客户端来讲增加了安全性,例如:很多木马篡改站点文件都是由上传入口上传的程序到存储目录,然后执行的。 因此在挂载的时候,用下面的命令很有必要:
1 2 mount -t nfs -o nosuid,noexec,nodev,rw 172.21.0.111:/data /nfs_data
附件 问题记录 reason given by server: No such file or directory 1 2 3 4 5 6 7 8 9 10 11 [root@f3a3540cb8e5 ~] mount.nfs: mounting 192.168.101.74:/data_storage/fdm_neo4j/import failed, reason given by server: No such file or directory /data_storage/fdm_neo4j/import 172.16.2.0/24(rw,sync,no_root_squash,insecure) 增加 fsid=0 参数后,重启服务 /data_storage/fdm_neo4j/import 172.16.2.0/24(rw,sync,no_root_squash,insecure,fsid=0) systemctl restart nfs-server
参考资源