NFS共享存储服务


1.NFS(网络文件服务)

NFS 是一种基于 TCP/IP 传输的网络文件系统协议

NFS 服务的实现依赖于 RPC(Remote Process Call,远端过程调用)机制,以完成远 程到本地的映射过程。在 CentOS 7 系统中,需要安装 nfs-utils、rpcbind 软件包来提供 NFS 共享服务,前者用于 NFS 共享发布和访问,后者用于 RPC 支持。

NFS端口号2049
RPC端口号111

但是,NFC没有用户认证机制,而且数据在网络上明文传输,所以安全性很差,一般只能在局域网内使用

特点
采用TCP/IP传输网络文件
安全性低
简单易操作
适合用于局域网环境

配置思路
安装nfs和rpcbind软件
修改配置文件设置共享
创建共享目录
开启服务
客户端验证共享目录可访问
在这里插入图片描述

2.NFS的配置

2.1 安装nfs-utils、rpcbind 软件包

nfs-utils、rpcbind 软件包来提供 NFS 共享服务,前者用于 NFS 共享发布和访问,后者用于 RPC 支持。(utils:小工具)

[root@nfs10 ~]# yum install -y nfs-utils rpcbind

2.2设置共享目录

NFS的配置文件为/etc/exports,文件内容默认为空(无任何共享)。在exports文件中的记录格式为:
<目录位置> <客户机地址>(权限选项)

[root@nfs10 ~]# cat /etc/exports
[root@nfs10 ~]# mkdir -p /opt/nfs_data
[root@nfs10 ~]# chmod 777 /opt/nfs_data/
[root@nfs10 ~]# ll /opt/
总用量 8
drwxrwxrwx. 2 root root   6 720 19:13 nfs_data
drwxr-xr-x. 2 root root   6 1031 2018 rh
-rw-r--r--. 1 root root 108 76 14:47 tar.1.txt.gzip
-rw-r--r--. 1 root root   6 720 11:29 txt

mkdir -p /opt/nfs_data //创建共享目录
chmod 777 /opt/nfs_data/ //赋予权限

进入NFS的配置文件为/etc/exports进行配置:
写的是如何将指定目录共享出去,以及其相关参数
共享出去的目录: /opt/nfs_data

允许使用挂载点的网段(定义:1、使用此共享目录的(其他主机)权限,2、同步数据,3、对root用户不进行降权处理):192.168.28.0/24(rw,sync,no_root_squash)

[root@nfs10 ~]# vim /etc/exports

在这里插入图片描述
(可配置多条)

2.3启动NFS服务程序

[root@nfs10 ~]# systemctl start rpcbind
[root@nfs10 ~]# systemctl enable rpcbind
[root@nfs10 ~]# systemctl start nfs
[root@nfs10 ~]# systemctl enable nfs

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

[root@nfs10 ~]# netstat -natp | grep rpcbind
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      11964/rpcbind       
tcp6       0      0 :::111                  :::*                    LISTEN      11964/rpcbind       

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

NFC主机

[root@nfs10 ~]# showmount -e
Export list for nfs10:
/opt/nfs_data 192.168.28.0/24
[root@nfs10 ~]# showmount -e 192.168.28.10
Export list for 192.168.28.10:
/opt/nfs_data 192.168.28.0/24


centos主机

[root@centos200 ~]# showmount -e
clnt_create: RPC: Program not registered
[root@centos200 ~]# showmount -e 192.168.28.10
Export list for 192.168.28.10:
/opt/nfs_data 192.168.28.0/24

2.5挂载

以网络挂载的方式将nfc主机配置的nfs服务挂载到centos主机本地

[root@centos200 /]# mount 192.168.28.10:/opt/nfs_data /data
[root@centos200 /]# df -hT
文件系统                    类型      容量  已用  可用 已用% 挂载点
/dev/sda3                   xfs        16G  4.1G   12G   26% /
devtmpfs                    devtmpfs  471M     0  471M    0% /dev
tmpfs                       tmpfs     487M     0  487M    0% /dev/shm
tmpfs                       tmpfs     487M  8.6M  478M    2% /run
tmpfs                       tmpfs     487M     0  487M    0% /sys/fs/cgroup
/dev/sda1                   xfs       473M  155M  318M   33% /boot
tmpfs                       tmpfs      98M  4.0K   98M    1% /run/user/42
tmpfs                       tmpfs      98M   28K   98M    1% /run/user/0
/dev/sr0                    iso9660   4.3G  4.3G     0  100% /run/media/root/CentOS 7 x86_64
192.168.28.10:/opt/nfs_data nfs4       37G  5.3G   32G   15% /data

使用df -hT查看磁盘,挂载成功
设置永久挂载
_netdev:表示挂载设备需要网络

[root@centos200 /]# vim /etc/fstab 

在这里插入图片描述

[root@centos200 /]# mount -a
[root@centos200 /]# df -hT
文件系统                    类型      容量  已用  可用 已用% 挂载点
/dev/sda3                   xfs        16G  4.1G   12G   26% /
devtmpfs                    devtmpfs  471M     0  471M    0% /dev
tmpfs                       tmpfs     487M     0  487M    0% /dev/shm
tmpfs                       tmpfs     487M  8.6M  478M    2% /run
tmpfs                       tmpfs     487M     0  487M    0% /sys/fs/cgroup
/dev/sda1                   xfs       473M  155M  318M   33% /boot
tmpfs                       tmpfs      98M  4.0K   98M    1% /run/user/42
tmpfs                       tmpfs      98M   28K   98M    1% /run/user/0
/dev/sr0                    iso9660   4.3G  4.3G     0  100% /run/media/root/CentOS 7 x86_64
192.168.28.10:/opt/nfs_data nfs4       37G  5.3G   32G   15% /data

2.6 客户机尝试创建文件

NFS共享储存服务搭建成功
在这里插入图片描述

2.7强制卸载NFS

如果服务器端NFS服务突然停掉,而客户端正在挂载使用时,在客户端会出现执行df-hT命令卡死现象。这个时候直接使用umount解挂载无法成功,需要加上-lf选项
umount -lf /data
也可以使用lsof查找进程号,然后使用kill -9杀死。

在这里插入图片描述
卡死

在这里插入图片描述

解挂载成功

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值