挂载nfs文件系统

前面讲了

如何配置和挂载OCFS2文件系统

使用vmware共享磁盘配置和挂载OCFS2文件系统

使用DRBD配置和挂载OCFS2文件系统

但很多情况我们并不需要使用共享文件系统。 例如备份,我们知道本地保存是不稳妥的,一旦硬盘故障,数据和备份都会丢失,一般情况是要求异地保存,也就是将备份放到其他的地方或主机上, 这时本地主机只要能够挂载其他主机的目录并读写就可以了。

这种情况可以使用NFS, CIFS 共享给本机挂载。 SSHFS是这些协议的备选方案

今天来分享一下如何挂载 NFS

日期: 2023-05-23

1 测试环境说明

windows 2019: 192.168.55.169 提供 nfs 存储空间 win_nfs

almaliux 9.2: 192.168.55.156 提供 nfs 存储空间 linux_nfs

oracle linux 7.9 :192.168.55.144/185 客户端 ,挂载

windows 11: 192.168.55.146 客户端 挂载

2 安装设置 nfs 服务端

2.1 windows 设置 nfs

服务管理器 ->添加角色和功能 -> 服务器角色 -> 展开 "文件和存储服务" -> 展开 "文件和 iSCSI 服务" -> 选择 "文件服务器" 和 "NFS 服务器" -> 下一步 -> 安装

新建文件夹 win_nfs, 右键点击 win_nfs -> 属性 -> NFS共享 -> 选择"共享此文件夹" 选择"不要服务器验证" "允许未匹配用户访问" "允许未匹配用户unix访问(by UID/GID)" 其他默认 -> 权限 添加 客户端ip 默认为读写

2.2 linux 配置 nfs

#NFS启动时会随机启动多个端口并向RPC注册.如果要开启防火墙,就要固定NFS端口并加入白名单。此处为方便关闭防火墙
systemctl stop firewalld 
#关闭selinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config ; sed -i "s/SELINUX=permissive/SELINUX=disabled/g" /etc/selinux/config
setenforce 0

#安装必须的软件包
yum -y install nfs-utils
systemctl restart rpcbind ; systemctl enable nfs-server --now

#配置nfs服务
mkdir /linux_nfs
chown nobody:nobody /linux_nfs #linux 8 使用 nobody, linux 7 及之前是nfsnobody , chown nfsnobody:nfsnobody /u01/backup
cat > /etc/exports <<EOF
/linux_nfs 192.168.55.144(rw,sync,all_squash)
/linux_nfs 192.168.55.185(rw,sync,all_squash)
/linux_nfs 192.168.55.146(rw,sync,all_squash)
EOF
systemctl restart nfs-server

3 linux 客户端挂载

3.1 linux 客户端安装

yum -y install nfs-utils

3.2 linux 客户端挂载 win_nfs

showmount -e 192.168.55.169 #列出远程共享的目录
mkdir /local_win_nfs
mount -t nfs 192.168.55.169:win_nfs /local_win_nfs
#自动挂载 /etc/fstab 加入后, 重启可以生效, 但手动 mount -a 可以挂载但提示 "fuse: mountpoint is not empty" 未找到解决方法
192.168.55.169:win_nfs /local_win_nfs nfs defaults 0 0

3.3 linux 客户端挂载 linux_nfs

showmount -e 192.168.55.156
mkdir /local_linux_nfs
mount -t nfs 192.168.55.156:linux_nfs /local_linux_nfs
#自动挂载 /etc/fstab 加入后, 重启可以生效, 但手动 mount -a 可以挂载但提示 "fuse: mountpoint is not empty" 未找到解决方法
192.168.55.156:linux_nfs /local_linux_nfs nfs defaults 0 0

4 windows 客户端挂载

4.1 安装

打开或关闭windows特性, 安装 Service for NFS -> Administrative Tools 和 Client for NFS

4.2 windows 客户端挂载 win_nfs

mount \\192.168.55.169\win_nfs w:

4.3 windows 客户端挂载 linux_nfs

mount \\192.168.55.156\linux_nfs l:

说明

这种挂载类似于nfs的网络共享, 并不是共享文件系统。 多个节点同时挂载,写入同一个文件,会发生覆盖现象

如果要使用共享文件系统,例如 OCFS2, GFS2 ,GPFS 请参考我以前的文章。

关注防丢失。

猜你喜欢

转载自blog.csdn.net/weixin_44496870/article/details/131673870