一、简介

1. 定义

NFS (Network File System),最初由 Sun Microsystems 于1984年开发的分布式系统协议,允许客户端上的用户通过网络访问文件,其方式与访问本地存储的方式类似。基于 Open Network Computing Remote Procedure Call (ONC RPC) 协议,NFS 是通过 Request for Comments(RFC) 定义的开放标准,允许任何人实现该协议。

2. 版本和变化

Version RFC Date Variations
NFSv2 RFC 1094 March 1989 UDP,无状态;32位,仅允许读取文件的前2GB
NFSv3 RFC 1813 June 1995 支持TCP;64位,突破2GB;异步写入;在许多响应报文中额外增加文件属性
NFSv4 RFC 3010 December 2000 集成了对文件锁定和挂载协议的支持;增加了对强安全性(及其协商)、复合操作、客户端缓存和国际化的支持
NFS 4.1 RFC 5661 January 2010 会话、目录委托、并行NFS (pNFS)
NFS 4.2 RFC 7862 November 2016

3. 部署说明

本文描述如何在 CentOS 7 上安装 NFS,并在 Linux 和 Windows 下使用 NFS 客户端进行连接。

hostname ip role 描述
nfs-server 192.168.0.135 server Linux nfs server
nfs-client 192.168.0.136 client Linux client
Windows 192.168.0.120 client Windows client

 

二、服务端

1. 关闭防火墙

  1. # systemctl stop firewalld
  2. # systemctl disable firewalld

2. 安装 nfs

  1. # yum -y install nfs-utils

3. 配置说明

通过文件 /etc/exports 来对 NFS 进行配置。

It follows the following syntax rules:

  • Comments start with the hash mark (#).
  • Blank lines are ignored by default.
  • Each host’s options must be placed in parentheses directly after the host identifier, without any spaces separating the host and the first parenthesis.
  • Each exported file system should be on its own individual line.
  • A list of authorized hosts needs to be separated by space characters.
  • Long lines can be wrapped with a backslash ().

NFS export default options are:

  • ro: The exported file system is read-only and remote hosts cannot make any changes to the files shared on the file system. To allow hosts to make both reads and writes, specify the rw option instead.
  • sync: Aith this option, NFS server does not reply to requests before changes made by previous requests are written to disk. To enable asynchronous writes instead, specify the option async.
  • root_squash: This prevents root users that connect remotely from having root privileges. Instead, the NFS server will assign them the user ID nfsnobody. This effectively “squashes” the power of the remote root user to the lowest local user, preventing possible unauthorized writes on the remote server. To disable root squashing, specify no_root_squash.
  • To squash every remote user (including root), use all_squash. To specify the user and group IDs that the NFS server should assign to remote users from a particular host, use the anonuid and anongid options.
  • wdelay: This reduces disk write overhead by delaying writing to the disk if it suspects another write request is imminent. This can be disabled using no_wdelay, when default sync is on.
  • subtree_check: This option enables subtree checking. It can be disabled using no_subtree_check.

4. 配置共享目录

(1)修改 exports

这里将 /mnt/data 作为共享目录,开放读写权限

  1. # vi /etc/exports
  2. /mnt/data 192.168.0.0/24(rw,no_root_squash)

注:这里的共享目录可以使用 Ceph 块设备挂载的文件夹,关于如何使用块设备,请参考 块设备快速入门

(2)使配置生效

  1. # exportfs -r

(3)查看 exports

  1. # exportfs -v
  2. /mnt/data 192.168.0.0/24(rw,sync,wdelay,hide,no_subtree_check,sec=sys,secure,no_root_squash,no_all_squash)

5. 启动服务

(1)启动 rpcbind

  1. //开机启动
  2. # systemctl enable rpcbind
  3. //启动
  4. # systemctl start rpcbind
  5. //重启
  6. # systemctl restart rpcbind

(2)启动 nfs-server

  1. //开机启动
  2. # systemctl enable nfs-server
  3. //启动
  4. # systemctl start nfs-server
  5. //重启
  6. # systemctl restart nfs-server

6. 确认启动成功

  1. # rpcinfo -p
  1. # exportfs
  2. /mnt/data 192.168.0.0/24

 

三、Linux 客户端

1. 安装 nfs

  1. # yum -y install nfs-utils

2. 启动 rpcbind

  1. //开机启动
  2. # systemctl enable rpcbind
  3. //启动
  4. # systemctl start rpcbind
  5. //重启
  6. # systemctl restart rpcbind

3. 挂载

创建目录

  1. # mkdir /data

挂载 nfs,-o 指定版本

  1. # mount -t nfs -o vers=3 192.168.0.135:/mnt/data /data
  2. or
  3. # mount -t nfs -o vers=4 192.168.0.135:/mnt/data /data

查看挂载结果

  1. # df -hT | grep /data
  2. 192.168.0.135:/mnt/data nfs 17G 985M 17G 6% /data
  3. or
  4. 192.168.0.135:/mnt/data nfs4 17G 985M 17G 6% /data
  1. # dh -h
  2. 文件系统 容量 已用 可用 已用% 挂载点
  3. 192.168.0.135:/mnt/data 17G 982M 17G 6% /data

4. 自动挂载

磁盘被手动挂载之后,需要把挂载信息写入 /etc/fstab 这个文件中,否则下次开机启动时仍然需要重新挂载。

例如对于 NFSv3,修改 /etc/fstab

  1. 192.168.0.135:/mnt/data /data nfs defaults,vers=3 0 0
  2. or
  3. 192.168.0.135:/mnt/data /data nfs vers=3,proto=tcp,hard,intr,rsize=32768,wsize=32768,noatime 0 0

执行挂载命令

  1. # mount -a

查看挂载结果

  1. # df -hT | grep /data
  2. 192.168.0.135:/mnt/data nfs 17G 985M 17G 6% /data

5. 解挂

  1. # umount /data

 

四、Windows 客户端

1. 打开NFS服务

(1)Windows 功能 - 启用或关闭 Windows 功能

(2)通过命令提示符显示 NFS 服务器

  1. showmount -e 192.168.0.135
  2. /mnt/data 192.168.0.0/24

2. 挂载

方法1:映射网络驱动器

方法2:通过命令挂载

  1. mount 192.168.0.135:/mnt/data Z:

3. 查看

方式1:打开我的点脑,就可以在网络位置看到 Z:盘了

方式2:通过命令查看

  1. mount
  2. 本地 远程 属性
  3. -------------------------------------------------------------------------------
  4. Z: \\192.168.0.135\mnt\data UID=-2, GID=-2
  5. rsize=262144, wsize=262144
  6. mount=soft, timeout=3.2
  7. retry=1, locking=yes
  8. fileaccess=755, lang=GB2312-80
  9. casesensitive=no
  10. sec=sys

4. 修改权限

对挂载盘进行写操作时,提示权限不足!

如果出现这种情况,解决办法:

(1)在运行中输入regedit,打开注册表编辑器。

(2)进入 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default 条目。

(3)选择新建 QWORD,新建 AnonymousUid,AnonymousGid 两个值,值为0。

(4)重启 NFS 服务 或 电脑。

5. 解挂

  1. umount Z:

 

参考链接

https://wiki.archlinux.org/index.php/NFS

https://en.wikipedia.org/wiki/Network_File_System

https://computingforgeeks.com/configure-nfsv3-and-nfsv4-on-centos-7/

CentOS7 下安装 NFS,Linux/Windows 作为客户端的更多相关文章

  1. Ubuntu下安装nfs,Windows下访问

    Linux 下: 1. 在终端输入  sudo apt-get install portmap nfs-common nfs-kernel-server 2.建立客户机访问目录  sudo mkdir ...

  2. Windows和Linux(Centos7)下安装Nginx

    安装Nginx 这篇记录只不过做了一个简单总结,如果对这块没什么概念的话可以看一下知乎的这篇文章 https://zhuanlan.zhihu.com/p/83890573 window下安装 win ...

  3. Linux CentOs7 下安装 redis

    Linux CentOs7 下安装 redis 请将以下命令放入linux命令行中运行 如果安装过程前没有安装GCC请先安装  命令如下 $ yum install gcc-c++ $ wget ht ...

  4. Linux CentOS7下安装Zookeeper-3.4.10服务(最新)

    Linux CentOS7下安装Zookeeper-3.4.10服务(最新) 2017年10月27日 01:25:26 极速-蜗牛 阅读数:1933   版权声明:本文为博主原创文章,未经博主允许不得 ...

  5. (转)LINUX CENTOS7下安装PYTHON

    LINUX CENTOS7下安装PYTHON 原文:http://www.cnblogs.com/lclq/p/5620196.html Posted on 2016-06-27 14:58 南宫羽香 ...

  6. Linux(CentOS7)下安装jdk1.8

    Linux(CentOS7) 下安装 jdk1.8 操作过程. 一.检查是否自带jdk rpm -qa|grep java 如果存在则用下面命令删除,xxx yyy zzz代表查询出来的自带jdk名称 ...

  7. CentOS7 下安装 iSCSI Target(tgt) ,使用 Ceph rbd

    目录 一.iSCSI 介绍 1. iSCSI 定义 2. 几种常见的 iSCSI Target 3. 优缺点比较 二.安装步骤 1. 关闭防火墙 2. 关闭selinux 3. 通过 yum 安装 t ...

  8. CentOS7下使用NFS文件共享给Window server 2012

    CentOS7下使用NFS文件共享给Window server 2012 2018年08月24日 23:15:54 疼迅扣扣 阅读数:443  出自https://blog.csdn.net/u013 ...

  9. docker(一) Centos7下安装docker

    docker(一) Centos7下安装dockerdocker(二) windows10下安装dockerdocker(三) 镜像和容器常用命令 docker(四) 使用Dockerfile构建镜像 ...

随机推荐

  1. jpa命名规范

      Keyword Sample JPQL snippet And findByLastnameAndFirstname … where x.lastname = ?1 and x.firstname ...

  2. 周鸿祎与85后的座谈(一):人人需要Mentor,世界没有奇迹

    我们公司现在有将近 4000 人,我觉得里面肯定是卧虎藏龙.百里挑一的话,也有 40 个伟大的人才.但是,即使是天才,如果没有前辈的帮助,最后也会变成庸才,是做不出什么大事的.举例来说,每一个跳水冠军 ...

  3. android testview + listview 整体滚动刷新

    listview滚动刷新不再讲述怎么实现 因为想实现整体滚动的效果,初始计划scrollView嵌套listview实现. 问题一:scrollview嵌套listview时,listview只能显示 ...

  4. 04:第一个OC类

    1.类与对象的关系 面向对象的核心就是对象,那怎么创建对象? OC中创建对象比较复杂, 首先要理解一个概念叫做类. 现实生活中是根据一份描述,一份模板创建对象,编程语言也一样,也必须先有一份描述,在这 ...

  5. 三种初步简易的方法求解数值问题 of C++

    1. “二分法解方程” 在二分法中,从区间[a,b]开始,用函数值f(a)与f(b)拥有相反的符号.如果f在这个区间连续,则f的图像至少在x=a,x=b之间穿越x轴一次,因此方程f(x)=0在[a,b ...

  6. js-数组面试题

      <!DOCTYPE html>   <html>   <head>   <meta charset="utf-8" />   & ...

  7. sql一些基本的语法

    1.if语句: 语法:IF(expr1,expr2,expr3) 其中,expr1是判断条件,expr2和expr3是符合expr1的自定义的返回结果. 用处:当从数据库中查询出来的结果需要转换成中文 ...

  8. iOS笔记之UIKit_UINavigationController

    //设置导航条的样式 self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent; //默认是白色  B ...

  9. cudnn 安装步骤

    上官网下载对应的cudnn https://developer.nvidia.com/cudnn 下载完cudnn后,命令行输入文件所在的文件夹 (ubuntu为本机用户名) cd home/ubun ...

  10. spark-mllib 密集向量和稀疏向量

    spark-mllib 密集向量和稀疏向量 MLlib支持局部向量和矩阵存储在单台服务器,也支持存储于一个或者多个rdd的分布式矩阵 . 局部向量和局部矩阵是用作公共接口的最简单的数据模型. 基本的线 ...