当前位置: 首页 > news >正文

访问网络附加存储:nfs

文章目录

    • 访问网络附加存储
    • 一、网络附加存储
      • 1.1、存储类型
      • 1.3、通过NFS挂载NAS
      • 1.4、NFS挂载过程
        • 服务端
        • 客户端
    • 二、实验:搭建NFS服务端及挂载到nfs客户端
      • 服务端
      • 客户端
      • 测试
      • 命令合集
        • 服务端
        • 客户端

访问网络附加存储

一、网络附加存储

1.1、存储类型

  • DAS:Direct Attached Storage,直连附加存储,将存储设备通过总线(SCSI、PCI、
    IDE等)接口直接连接到一台服务器上使用。

  • NAS:Network Attached Storage,网络附加存储,将设备通过TCP/IP网络共享,
    提供文件存储

  • SAN:Storage Area Network,存储区域网络,将设备通过光纤通道或者TCP/IP网
    络共享出去,提供块设备。SAN存储可以进一步划分为FC-SAN和IP-SAN。

在这里插入图片描述

存储类型
### 1.2、RPC通信介绍

NFS 支持的功能相当的多,而不同的功能都会使用不同的程序来启动,每启动一个功能就会启用一些端口来传输数据,因此,NFS的功能所对应的端口没有固定住,而是随机取用一些未被使用的小于1024的端口提供服务。但如此一来客户端如何获得服务器端的相关端口呢?

此时我们就得需要远程过程调用(RPC)的服务!RPC最主要的功能是注册每个NFS功能所对应的端口,并且汇报给客户端,让客户端可以连结到正确的端口。

在这里插入图片描述

RPC通信原理

1.3、通过NFS挂载NAS

NFS是Network File System的缩写,即网络文件系统。最早由Sun公司开发,用来在UNIX&Linux系统间实现磁盘文件共享的一种方法。它的主要功能是通过网络让不同的主机系统之间可以共享文件或目录。NFS客户端(一般为应用服务器,例如web)可以通过挂载(mount)的方式将NFS服务端共享的数据目录挂载到NFS客户端本地系统中(就是某一个挂载点下)。从NFS客户端的机器本地看,NFS服务端共享的目录就好像是客户自己的磁盘分区或者目录一样,而实际上确是远端的NFS服务端的目录。

在企业集群架构的工作场景中,NFS网络文件系统一般被用来存储共享视频、图片、附件等静态资源文件。一般是把网站用户上传的文件都放在NFS共享里,例如,BBS产品的图片、附件、头像,特别是中小网站公司应用频率更高。

NFS服务器导出共享目录,NFS客户端将导出的共享挂载到本地。

挂载NFS共享方式:

  • 使用mount命令手动挂载。

  • 使用/etc/fstab条目在启动时自动挂载。

  • 按需挂载:使用autofs服务或systemd. automount功能。

1.4、NFS挂载过程

服务端
  1. 安装环境依赖包

    rpm -q rpcbind nfs-utils oryum -y install nfs-utils rpcbind
    
  2. 设置共享目录

    mkdir -p /opt/nfs
    chmod 777 /opt/nfsvim /etc/exports/opt/nfs *.*.*.*/*(rw,sync,no_root_squash)
    

    客户机地址可以是主机名、IP 地址、网段地址,允许使用“*”、“?”通配符。
    “rw” 表示允许读写,“ro” 表示为只读。
    sync :表示同步写入到内存与硬盘中。
    no_root_squash : 表示当客户机以root身份访问时赋予本地root权限(默认是root_squash)。
    root_squash :表示客户机用root用户访问该共享目录时,将root用户映射成匿名用户。

    all_squash :所有访问用户都映射为匿名用户或用户组。
    async :将数据先保存在内存缓冲区中,必要时才写入磁盘。
    subtree_check(默认):若输出目录是一个子目录,则nfs服务器将检查其父目录的权限。
    no_subtree_check :即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率。
    anonuid=xxx :指定NFS服务器/etc/passwd文件中匿名用户的UID 
    anongid=xxx :指定NFS服务器/etc/group文件中匿名用户的GID 
    
  3. 关闭防火墙,启动 NFS 服务程序

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

systemctl stop firewalld
systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfsnetstat -anptu | grep 111            ##rpcbind默认使用端口111
netstat -anptu | grep 2049             ##nfs默认使用端口2049
  1. 查看本机发布的 NFS 共享目录
exportfs -rv                            #发布共享
showmount -e
客户端
  1. 安装环境依赖包

    rpm -q rpcbind nfs-utils oryum -y install nfs-utils rpcbind
    
  2. 启动 NFS 服务程序

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

```bash
systemctl stop firewalld
systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfsnetstat -anptu | grep 111            ##rpcbind默认使用端口111
netstat -anptu | grep 2049             ##nfs默认使用端口2049
```
  1. 挂载点:使用 mkdir 在合适的位置创建挂载点。

    mkdir -p /opt/test
    
  2. 挂载:与分区上的文件系统一样,NFS共享必须先进行挂载才可用。

无论在哪种情况下,您都必须作为root用户登录,或使用sudo 命令,以超级用户身份运行这些命令。

  • 临时挂载

    mount -t nfs -o rw,sync "nfs-serverIP":/opt/nfs /opt/test-t nfs选项是NFS共享的文件系统类型(默认值)。-o sync选项使mount立即与NFS服务器同步写操作(默认值为async)。下一次系统启动时,此NFS共享将不可用 ,可用于在持久提供共享之前对挂载NFS共享进行测试。
    
  • 永久挂载

      vim /etc/fstab..."nfs-serverIP":/opt/nfs /opt/test nfs rw,sync 0 0
    
  1. 卸载

    umount "nfs-serverIP":/opt/nfsorumount mountpoint
    

二、实验:搭建NFS服务端及挂载到nfs客户端

服务端

  1. 安装环境依赖包

    在这里插入图片描述

  2. 设置共享目录

    在这里插入图片描述

    在这里插入图片描述

  3. 关闭防火墙,启动 NFS 服务程序

    在这里插入图片描述

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

    在这里插入图片描述

客户端

  1. 安装环境依赖包

在这里插入图片描述

  1. 启动 NFS 服务程序

    在这里插入图片描述

  2. 创建挂载点

    在这里插入图片描述

  3. 挂载

    在这里插入图片描述

在这里插入图片描述

测试

在nfs服务端/opt/nfs下创建“wl.txt”文件,内容为“wl love to bath point 88 technician”;在nfs客户端查看是否有“wl.txt”文件,并检查文件内容是否与服务端一致。

在这里插入图片描述

在这里插入图片描述

命令合集

服务端
[root@nfs-server ~]#yum -y install nfs-utils rpcbind
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
local                                                                                                              | 3.6 kB  00:00:00     
软件包 1:nfs-utils-1.3.0-0.68.el7.2.x86_64 已安装并且是最新版本
软件包 rpcbind-0.2.0-49.el7.x86_64 已安装并且是最新版本
无须任何处理[root@nfs-server ~]#mkdir -p /opt/nfs[root@nfs-server ~]#chmod 777 /opt/nfs[root@nfs-server ~]#vim /etc/exports/opt/nfs 10.190.33.0/24(rw,sync,no_root_squash)[root@nfs-server ~]#systemctl stop firewalld[root@nfs-server ~]#systemctl start rpcbind[root@nfs-server ~]#systemctl start nfs[root@nfs-server ~]#systemctl enable rpcbind[root@nfs-server ~]#systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.[root@nfs-server ~]#netstat -anptu | grep 111
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      713/rpcbind         
tcp6       0      0 :::111                  :::*                    LISTEN      713/rpcbind         
udp        0      0 0.0.0.0:111             0.0.0.0:*                           713/rpcbind         
udp6       0      0 :::111                  :::*                                713/rpcbind         [root@nfs-server ~]#netstat -anptu | grep 2049
tcp        0      0 0.0.0.0:2049            0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::2049                 :::*                    LISTEN      -                   
udp        0      0 0.0.0.0:2049            0.0.0.0:*                           -                   
udp6       0      0 :::2049                 :::*                                -                   [root@nfs-server ~]#exportfs -rv 
exporting 10.190.33.0/24:/opt/nfs[root@nfs-server ~]#showmount -e
Export list for nfs-server:
/opt/nfs 10.190.33.0/24[root@nfs-server ~]#echo wl love to bath point 88 technician > /opt/nfs/wl.txt[root@nfs-server ~]#cat /opt/nfs/wl.txt 
wl love to bath point 88 technician
客户端
[root@nfs-client- ~]#yum -y install nfs-utils rpcbind
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
local                                                                                                              | 3.6 kB  00:00:00     
软件包 1:nfs-utils-1.3.0-0.68.el7.2.x86_64 已安装并且是最新版本
软件包 rpcbind-0.2.0-49.el7.x86_64 已安装并且是最新版本
无须任何处理[root@nfs-client- ~]# systemctl start rpcbind[root@nfs-client- ~]# systemctl stop firewalld[root@nfs-client- ~]# systemctl start rpcbind[root@nfs-client- ~]# systemctl start nfs[root@nfs-client- ~]# systemctl enable rpcbind[root@nfs-client- ~]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.[root@nfs-client- ~]# mkdir -p /opt/test[root@nfs-client- ~]# mount -t nfs -o rw,sync 10.190.33.10:/opt/nfs /opt/test[root@nfs-client- ~]# mount -a[root@nfs-client- ~]# df
文件系统                   1K-块    已用     可用 已用% 挂载点
devtmpfs                  480736       0   480736    0% /dev
tmpfs                     497816       0   497816    0% /dev/shm
tmpfs                     497816    8508   489308    2% /run
tmpfs                     497816       0   497816    0% /sys/fs/cgroup
/dev/mapper/centos-root 38770180 4585544 34184636   12% /
/dev/sda1                1038336  177468   860868   18% /boot
/dev/sr0                 4635056 4635056        0  100% /mnt/sr
tmpfs                      99564      12    99552    1% /run/user/42
tmpfs                      99564       0    99564    0% /run/user/0
10.190.33.10:/opt/nfs   38770304 4584960 34185344   12% /opt/test[root@nfs-client- ~]# vim /etc/fstab...10.190.33.10:/opt/nfs /opt/test nfs rw,sync 0 0[root@nfs-client- ~]# mount -a[root@nfs-client- ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 470M     0  470M    0% /dev
tmpfs                    487M     0  487M    0% /dev/shm
tmpfs                    487M  8.4M  478M    2% /run
tmpfs                    487M     0  487M    0% /sys/fs/cgroup
/dev/mapper/centos-root   37G  4.4G   33G   12% /
/dev/sda1               1014M  174M  841M   18% /boot
/dev/sr0                 4.5G  4.5G     0  100% /mnt/sr
tmpfs                     98M   12K   98M    1% /run/user/42
tmpfs                     98M     0   98M    0% /run/user/0
10.190.33.10:/opt/nfs     37G  4.4G   33G   12% /opt/test[root@nfs-client- ~]# ll /opt/test/
总用量 4
-rw-r--r--. 1 root root 36 56 01:44 wl.txt[root@nfs-client- ~]# cat /opt/test/wl.txt 
wl love to bath point 88 technician
http://www.lryc.cn/news/344220.html

相关文章:

  • jsp 实验12 servlet
  • 「 网络安全常用术语解读 」通用配置枚举CCE详解
  • 一机游领航旅游智慧化浪潮:借助前沿智能设备,革新旅游服务效率,构建高效便捷、生态友好的旅游服务新纪元,开启智慧旅游新时代
  • 设计模式学习笔记 - 项目实战三:设计实现一个支持自定义规则的灰度发布组件(实现)
  • BJFUOJ-C++程序设计-实验2-类与对象
  • 数据库语法复习
  • Tomcat、MySQL、Redis最大支持说明
  • MATLAB数值计算工具箱介绍
  • 2023 广东省大学生程序设计竞赛(部分题解)
  • ROS2学习——Docker环境下安装于使用(1)
  • 数据仓库之Hologres
  • MacOS搭建docker本地私有镜像库
  • Unity Material(材质)、Texture(纹理)、Shader(着色器)简介
  • 《视觉十四讲》例程运行记录(1)—— 课本源码下载和3rdparty文件夹是空的解决办法
  • VLM与基础分割模型的联合使用
  • JS数组去重的方法
  • Go实战训练之Web Server 与路由树
  • C#中接口设计相关原则
  • Pytorch学习笔记——卷积操作
  • 探索鸿蒙开发:鸿蒙系统如何引领嵌入式技术革新
  • chrome extension插件替换网络请求中的useragent
  • PHP基础【介绍,注释,更改编码,赋值,数据类型】
  • ASP.NET小型证券术语解释及翻译系统的设计与开发
  • 硬件知识积累 音频插座的了解,看音频插座的原理图来了解音频插座的引脚。
  • error LNK2001: 无法解析的外部符号 “__declspec(dllimport) public: __cdecl ......
  • 邮箱Webhook API发送邮件的性能怎么优化?
  • 并发编程实现
  • 基于EBAZ4205矿板的图像处理:12图像二值化(阈值可调)
  • 人大金仓数据库报com.kingbase8.util.KSQLException: 致命错误: 用户 “SYSTEM“ Password 认证失败
  • 文件加密软件哪个好?文件加密软件排行榜前十名(好用软件推荐)