一.介绍

    NFS 是Network File System的缩写,即网络文件系统。一种使用于分散式文件系统的协定,功能是让客户端通过网络访问不同主机上磁盘里的数据,主要用在类Unix系统上实现文件共享的一种方法。
NFS在文件传送或信息传送过程中依赖于RPC协议。RPC,远程过程调用 (Remote Procedure Call) 是能使客户端执行其

二.服务端配置

1.关闭系统防火墙和selinux

#查看系统防火墙的状态,可以看到防火墙是开着的
[root@linuxidc ~]#systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: active (running) since Sat 2017-06-03 09:38:00 CST; 8s ago
Docs: man:firewalld(1)
Main PID: 24067 (firewalld)
CGroup: /system.slice/firewalld.service
└─24067 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid Jun 03 09:37:58 linuxidc systemd[1]: Starting firewalld - dynamic firewall daemon...
Jun 03 09:38:00 linuxidc systemd[1]: Started firewalld - dynamic firewall daemon.
#关闭防火墙
[root@linuxidc ~]#systemctl stop firewalld
#再次查看防火墙,可以看到已经关闭了
[root@linuxidc ~]#systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1) Jun 01 11:33:35 localhost systemd[1]: Starting firewalld - dynamic firewall daemon...
Jun 01 11:33:44 localhost systemd[1]: Started firewalld - dynamic firewall daemon.
Jun 03 09:11:32 linuxidc systemd[1]: Stopping firewalld - dynamic firewall daemon...
Jun 03 09:11:34 linuxidc systemd[1]: Stopped firewalld - dynamic firewall daemon.
Jun 03 09:37:58 linuxidc systemd[1]: Starting firewalld - dynamic firewall daemon...
Jun 03 09:38:00 linuxidc systemd[1]: Started firewalld - dynamic firewall daemon.
Jun 03 09:38:34 linuxidc systemd[1]: Stopping firewalld - dynamic firewall daemon...
Jun 03 09:38:36 linuxidc systemd[1]: Stopped firewalld - dynamic firewall daemon.
#查看selinux的运行模式,现在为强制模式
[root@linuxidc share]#getenforce
Enforcing
#把selinux设为许可模式
[root@linuxidc share]#setenforce 0
#再次查看selinux的运行模式,已经变为许可模式
[root@linuxidc share]#getenforce
Permissive
#要想禁用selinux,则需要编辑selinux的配置文件,把SELINUX设置成disabled,然后重启生效
[root@linuxidc share]#vi /etc/sysconfig/selinux
[root@linuxidc share]#cat /etc/sysconfig/selinux # This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

2.安装所需的软件包

[root@linuxidc ~]#yum install -y rpc-bind nfs-utils

3.服务端配置


NFS服务的主要配置文件为 /etc/exports.
/etc/exports文件内容格式:
<输出目录> 客户端(选项:访问权限,用户映射,其他]
输出目录是指NFS系统中所定义的共享给客户端使用的文件系统
客户端是定义网络中可以访问这个NFS共享目录的IP地址或网段或域名等
客户端常用的指定方式
指定ip地址的主机:192.168.100.1
指定一个子网:192.168.100.0/24 也可以写成:192.168.100.0/255.255.255.0
指定域名的主机:david.bsmart.cn
指定域中的所有主机:*.bsmart.cn
所有主机:*
选项用来设置输出目录的访问权限、用户映射等。
NFS主要有3类选项:
设置输出目录只读:ro
设置输出目录读写:rw
用户映射选项
all_squash:将远程访问的所有普通用户及所属组都映射为匿名用户或用户组(nfsnobody);
no_all_squash:与all_squash取反(默认设置);
root_squash:将root用户及所属组都映射为匿名用户或用户组(默认设置);
no_root_squash:与rootsquash取反;
anonuid=xxx:将远程访问的所有用户都映射为匿名用户,并指定该用户为本地用户(UID=xxx);
anongid=xxx:将远程访问的所有用户组都映射为匿名用户组账户,并指定该匿名用户组账户为本地用户组账户(GID=xxx);
其它选项
secure:限制客户端只能从小于1024的tcp/ip端口连接nfs服务器(默认设置);
insecure:允许客户端从大于1024的tcp/ip端口连接服务器;
sync:将数据同步写入内存缓冲区与磁盘中,效率低,但可以保证数据的一致性;
async:将数据先保存在内存缓冲区中,必要时才写入磁盘;
wdelay:检查是否有相关的写操作,如果有则将这些写操作一起执行,这样可以提高效率(默认设置);
no_wdelay:若有写操作则立即执行,应与sync配合使用;
subtree:若输��目录是一个子目录,则nfs服务器将检查其父目录的权限(默认设置);
no_subtree:即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率;

修改/etc/exports文件,定义NFS共享

#修改NFS配置文件,定义共享
[root@linuxidc ~]#vi /etc/exports
#定义向所有客户端共享/share目录,共享方式为可读可写
[root@linuxidc ~]#cat /etc/exports
/share *(rw,sync)
#创建/share这个共享目录
[root@linuxidc ~]#mkdir /share
#把共享目录的权限设定为所有用户都可读可写权限
[root@linuxidc ~]#chmod 766 /share
#把NFS加入到开机自启动选项中
[root@linuxidc ~]#systemctl enable nfs-server.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
#开启NFS服务
[root@linuxidc ~]#systemctl start nfs
#把RPCbind加入开机处启动选项中
[root@linuxidc ~]#systemctl enable rpcbind
#启动RPCbind
[root@linuxidc ~]#systemctl start rpcbind
#查看NFS服务的状态 ,可以看到NFS服务已经在运行中
[root@linuxidc ~]#systemctl status nfs
● nfs-server.service - NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
Active: active (exited) since Sat 2017-06-03 09:22:02 CST; 37min ago
Main PID: 23967 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/nfs-server.service Jun 03 09:22:02 linuxidc systemd[1]: Starting NFS server and services...
Jun 03 09:22:02 linuxidc systemd[1]: Started NFS server and services.
#查看本机共享的文件系统
[root@linuxidc ~]#exportfs
/share <world>

三.客户端配置:

1.客户端关闭防火墙和selinux,方法同上.

2.客户端安装NFS软件包,并把NFS服务设为开机自启动,方法同上.

3.挂载共享的NFS文件系统

#把192.168.16.29这个主机上的共享目录挂载到本机的/media上
[root@linuxidc ~]#mount 192.168.16.29:/share /media
#查看是否已经挂载成功
[root@linuxidc ~]#mount | grep media
192.168.16.29:/share on /media type nfs4 (rw,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.16.177,local_lock=none,addr=192.168.16.29)
#把共享目录写入系统挂载文件系统
[root@linuxidc ~]#vi /etc/fstab
[root@linuxidc ~]#cat /etc/fstab | grep media
192.168.16.29:/share /media nfs4 defaults 0 0

四.测试:

1.在服务端共享目录中新建一个10M大小的文件

[root@linuxidc media]#cd /share
[root@linuxidc share]#ls
#在NFS共享目录上新建一个10M大小的文件,提示成功
[root@linuxidc share]#dd if=/dev/zero of=/share/f1 bs=1M count=10
10+0 records in
10+0 records out
10485760 bytes (10 MB) copied, 0.0351504 s, 298 MB/s
[root@linuxidc share]#ll -h
total 10M
-rw-r--r--. 1 root root 10M Jun 3 10:14 f1

2.在客户端新建另一个文件f2,同时尝试删除另一个文件f1

[root@linuxidc ~]#cd /media
[root@linuxidc media]#ls
f1
#在共享目录上新建一个文件f2,未报错
[root@linuxidc media]#touch f2
#删除存在的文件f1,未报错
[root@linuxidc media]#rm -f f1

3.在服务端查看共享目录中的文件

[root@linuxidc share]#ls
f2

CentOs7 配置nfs 系统的更多相关文章

  1. Centos7配置NFS

    centos7配置nfs yum -y install nfs-utils rpcbind 设置服务开机启动: systemctl enable rpcbind systemctl enable nf ...

  2. CentOS7 配置NFS(Network File System)及其使用

    1.       服务端配置 1.1.    安装NFS yum -y install nfs* 1.2.    查看是否安装了NFS与RPCBIND rpm -qa | grep nfs rpm - ...

  3. CentOS7配置NFS网络文件系统

    NFS,是Network File System的简写,即网络文件系统.网络文件系统是FreeBSD支持的文件系统中的一种,也被称为NFS. NFS允许一个系统在网络上与他人共享目录和文件.通过使用N ...

  4. centos7 配置 NFS mount挂载服务器

    1. NFS服务端 安装NFS服务 yum install nfs_utils yum install rpcbind (系统默认已经有了,可查看下) 配置共享文件夹 1.    创建文件夹: mkd ...

  5. centos7配置nfs共享存储服务

    nfs 是一种网络文件系统,需要依赖rpc进行过程调度 注意nfs只验证id,验证用户名,并且只能在类unix os上进行文件共享服务,由于它的脆弱的验证机制,所以不适宜在internet上工作,在内 ...

  6. CentOS7系列--3.1CentOS7中配置NFS服务

    CentOS7配置NFS服务 1. 配置NFS服务器端 1.1. 安装nfs-utils软件 [root@server1 ~]# yum install -y nfs-utils Loaded plu ...

  7. CentOS7安装配置 NFS

    一.NFS 简介 NFS(Network File System)即网络文件系统,它允许网络中的计算机之间通过TCP/IP网络共享资源.在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端N ...

  8. LINUX下NFS系统的安装配置

    准备:NFS系统服务器IP 192.168.135.1 ,NFS共享目录/mnt/NFS 一.安装NFS 查看nfs是否安装 #rpm -qa | grep nfs 若没有则安装nfs包 #yum i ...

  9. win10与centos7的双系统U盘安装(二:安装以及配置centos系统)

    继续第一篇的讲解,接着就是要进入第二部分——安装以及配置centos系统 特别提醒在安装centos之间,注意自己的win10系统进行备份,便于回复安装失败后的系统 1:安装前准备 安装前准备主要是两 ...

随机推荐

  1. Java中对象、对象引用、堆、栈、值传递以及引用传递的详解

    Java中对象.对象引用.堆.栈.值传递以及引用传递的详解 1.对象和对象引用的差别: (1).对象: 万物皆对象.对象是类的实例. 在Java中new是用来在堆上创建对象用的. 一个对象能够被多个引 ...

  2. mycat 分页慢原理解析、mycat跨事务解惑、mycat注解调用存储过程分析

    1结合Mycat日志,分析select * from travelrecord order by id limit100000,100 的运行过程,解释下当limit M,N中的M非常大的情况下.为什 ...

  3. TP5结合聚合数据API查询天气

    php根据城市查询天气情况看到有人分享java的查询全国天气情况的代码,于是我想分享一个php版本的查询天气接口.免费查询天气的接口有很多,比如百度的apistore的天气api接口,我本来想采用这个 ...

  4. js:我们应该如何去了解JavaScript引擎的工作原理(转)

    http://www.nowamagic.net/librarys/veda/detail/1579 昨天收到一封来自深圳的一位前端童鞋的邮件,邮件内容如下(很抱歉,未经过他的允许,公开邮件内容,不过 ...

  5. Spring2.5学习3.2_编码剖析@Resource注解的实现原理

    首先看一下J2EE提供的@Resource注解:该注解默认安照名称进行装配,名称能够通过name属性进行指定, 假设没有指定name属性,当注解写在字段上时,默认取字段名进行依照名称查找,假设注解写在 ...

  6. Oracle中Hint深入理解(原创)

    http://czmmiao.iteye.com/blog/1478465 Hint概述  基于代价的优化器是很聪明的,在绝大多数情况下它会选择正确的优化器,减轻了DBA的负担.但有时它也聪明反被聪明 ...

  7. Runtime.getRuntime().exec()----记录日志案例

    Runtime.getRuntime().exec()方法主要用于运行外部的程序或命令. Runtime.getRuntime().exec共同拥有六个重载方法: 1.public Process e ...

  8. cocos2dx中使用iconv转码(win32,iOS,Android)

    首先贴下环境:Win7 64, NDK r8e, libiconv-1.14, cygwin 一 Win32环境配置 Cocos2D-X自带有win32上的iconv库.仅仅须要配置一下就可以使用. ...

  9. gitlab多人协同工作

    gitlab多人协同工作 本文为亨利向<Git权威指南>的作者蒋鑫老师的答疑邮件写成. 这里特别感谢蒋鑫老师对我询问gitlab的协同工作流程问题的详细解答. 蒋鑫老师的细致专业的解答让我 ...

  10. 安卓ADT离线安装

    http://jingyan.baidu.com/article/3aed632e66858770108091bf.html