linux网络NFS共享存储服务

一.NFS 概述

       NFS(Network File System)网络文件系统是一种基于 TCP/IP 传输的网络文件系统协议。通过使用 NFS 协议,客户机可以像本地目录一样访问远程服务器中的共享资源。
       对于大多数负载均衡群集来说,使用 NFS 协议来共享数据存储是比较常见的做法,NFS 也是 NAS 存储设备必然支持的一种协议,但是由于 NFS 没有用户认证机制,而且数据在网络上明文传输,所以安全性很差,一般只能在局域网中使用。
       NFS 服务的实现依赖于 RPC(Remote Process Call,远端过程调用)机制,以完成远程到本地的映射过程。所以需要安装 nfs-utils、rpcbind 软件包来提供 NFS 共享服务,前者用于 NFS 共享发布和访问,后者用于 RPC 支持。

共享配置文件:

/etc/exports

二.服务端配置

1.安装 nfs-utils、rpcbind 软件包

yum -y install nfs-utils rpcbind

2.设置共享目录

mkdir -p /opt/share
chmod 777 /opt/share

3.编辑配置文件

[root@c7-1 ~]#vim /etc/exports

/opt/share 192.168.139.0/24(rw,sync,no_root_squash)

4.启动 NFS 共享服务程序

手动加载 NFS 共享服务时,应该先启动 rpcbind,再启动 nfs

systemctl start rpcbind && systemctl enable rpcbind
systemctl start nfs && systemctl enable nfs

查看 rpcbind 端口是否开启,rpcbind 服务默认使用 tcp 端口 111

netstat -anpt | grep rpcbind

5.查看本机发布的 NFS 共享目录

[root@c7-1 ~]#exportfs -rv
exporting 192.168.139.0/24:/opt/share
[root@c7-1 ~]#showmount -e
Export list for c7-1:
/opt/share 192.168.139.0/24

三.客户端配置

1.安装软件包并启动

yum -y install nfs-utils rpcbind
systemctl start rpcbind && systemctl enable rpcbind

2.查看 NFS 服务器端共享了哪些目录

[root@c7-2 ~]#showmount -e 192.168.139.10
Export list for 192.168.139.10:
/opt/share 192.168.139.0/24

3.手动挂载 NFS 共享目录
在客户机中创建一个资源共享的目录,然后把服务端共享的目录挂载在客户机创建的资源共享目录上

[root@c7-2 ~]#mkdir /testshare
[root@c7-2 ~]#mount 192.168.139.10:/opt/share /testshare
[root@c7-2 ~]#df -Th | grep share
192.168.139.10:/opt/share nfs4       50G  1.7G   49G   4% /testshare

4.设置自动挂载

# _netdev 表示挂载设备需要网络
[root@c7-2 ~]#echo "192.168.139.10:/opt/share /testshare nfs defaults,_netdev 0 0" >> /etc/fstab
[root@c7-2 ~]#mount -a
[root@c7-2 ~]#df -Th | grep share
192.168.139.10:/opt/share nfs4       50G  1.7G   49G   4% /testshare

5.测试是否可以共享文件
客户端:

[root@c7-2 ~]#cd /testshare/
[root@c7-2 /testshare]#touch 1.txt
[root@c7-2 /testshare]#ll
total 0
-rw-r--r-- 1 root root 0 Sep  1 14:58 1.txt

服务端:

[root@c7-1 ~]#ll /opt/share/
总用量 0
-rw-r--r-- 1 root root 0 9月   1 14:58 1.txt

6.强制卸载 NFS
       如果服务端 NFS 服务突然停掉了,而客户端正在挂载使用时,在客户端执行 df -h 命令会出现卡死的现象,这个时候直接使用 umount 命令是无法直接卸载的,需要加上 -lf 选项:

umount -lf /testshare
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值