Linux系统NFS网络文件系统
Linux系统NFS网络文件系统
NFS(network file system)网络文件系统,就是通过网络让不同的主机系统之间可以共享文件或目录,此种方法NFS客户端使用挂载的方式让共享文件或目录到本地系统可挂载的目录下
NFS实现是通过RPC服务来实现的
实现过程:
1、NFS RPC主要的功能是记录每个NFS功能所对应的端口号,并将信息传递给请求数据的NFS客户端,从而实现数据的传输
2、NFS服务启动时会随机取用数个端口,并主动向RPC服务注册取用的相关端口信息,RPC服务就知道每个端口对应的NFS功能了,然后RPC会用固定的端口(111)来监听NFS客户端的请求,将正确的NFS端口传给NFS的客户端
服务端启动顺序:
事先RPC服务,后启动NFS服务,否则NFS服务无法向RPC服务进行注册,Centos 5.x 系统下RPC服务为portmap,Centos 6.x系统为rpcbind
NFS软件:nfs-utils 是NFS的主程序
NFS配置文件格式如下:
NFS共享目录 NFS客户端地址(参数1.参数2)
1、NFS共享目录的实际目录必须是绝对路径
2、NFS客户端为服务端授权可以访问共享目录的NFS客户端地址,可以是IP、域名、主机名、整个网段,或者用*来匹配所有主机
3、参数是对授权访问NFS共享目录的权限(客户端的访问权限集合)
安装布署过程
服务器端配置如下
1、查看操作系统版本与内核
[root@Centos ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[root@Centos ~]# uname -r
2.6.32-431.el6.x86_64
2、检查是否安装NFS RPC服务
[root@Centos ~]# rpm -aq nfs-utils rpcbind
rpcbind-0.2.0-12.el6.x86_64
nfs-utils-1.2.3-39.el6.x86_64
3、如果没安装相关服务请使用如下命令进行安装
yum install nfs-utils -y
yum install rpcbind -y
启动
按启动的先后顺序来启动服务
[root@Centos ~]# /etc/init.d/rpcbind status
rpcbind is stopped
[root@Centos ~]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]
[root@Centos ~]# /etc/init.d/nfs status
rpc.svcgssd is stopped
rpc.mountd is stopped
nfsd is stopped
rpc.rquotad is stopped
[root@Centos ~]# rpcinfo -p localhost 查看rpc的注册信息情况
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
[root@Centos ~]# /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
相关服务启动后,我们再来查看NFS向RPC的注册情况
如果想让NFS、RPC服务开机自启动,实际生产环境中一般都会将配置放在/etc/rc.local下面
[root@Centos ~]# cat /etc/rc.local
####start up by 2016-08-21
/etc/init.d/rpcbind start
/etc/init.d/nfs start
检查配置情况
[root@Centos /]# tail -2 /etc/rc.local
/etc/init.d/rpcbind start
/etc/init.d/nfs start
5、配置服务端NFS配置文件/etc/exports
[root@Centos ~]# vi /etc/exports
#####config for nfs-server 2016-8-21
/data/bbs 192.168.1.3(rw,sync)
检查配置情况
[root@Centos /]# tail -2 /etc/exports
#####config for nfs-server 2016-8-21
/data/bbs 192.168.1.3(rw,sync)
6、配置完成后重启NFS服务
/etc/init.d/nfs reload (/usr/bin/exprots -r) 两者功能相同
[root@Centos /]# /etc/init.d/nfs reload
客户端配置如下
1、查看服务器操作系统版本与内核
[root@localhost ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[root@localhost ~]# uname -r
2.6.32-431.el6.x86_64
2、启动RPC服务
[root@localhost ~]# /etc/init.d/rpcbind status
rpcbind is stopped
[root@localhost ~]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]
[root@localhost ~]# /etc/init.d/rpcbind status
rpcbind (pid 25679) is running...
3、查看挂载情况
[root@localhost ~]# showmount -e 192.168.1.2
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
[root@localhost ~]# ping 192.168.1.2
PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data.
64 bytes from 192.168.1.2: icmp_seq=1 ttl=64 time=0.745 ms
64 bytes from 192.168.1.2: icmp_seq=2 ttl=64 time=0.532 ms
64 bytes from 192.168.1.2: icmp_seq=3 ttl=64 time=0.470 ms
64 bytes from 192.168.1.2: icmp_seq=4 ttl=64 time=0.522 ms
^C
--- 192.168.1.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3060ms
rtt min/avg/max/mdev = 0.470/0.567/0.745/0.106 ms
[root@localhost ~]# iptables -F 关闭服务与客户端防火墙
[root@localhost ~]# showmount -e 192.168.1.2
Export list for 192.168.1.2:
/data/bbs 192.168.1.3
4、客户端进行NFS挂载
[root@localhost ~]# mount -t nfs 192.168.1.2:/data/bbs /mnt
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 3.3G 14G 20% /
tmpfs 491M 72K 491M 1% /dev/shm
/dev/sda1 485M 35M 426M 8% /boot
192.168.1.2:/data/bbs 50G 3.5G 44G 8% /mnt
5、测试共享
服务端查看具体目录权限
[root@Centos /]# ls -ld data/bbs/
drwxr-xr-x. 2 root root 4096 Aug 21 10:07 data/bbs/
表明其它用户具有读与执行权限
[root@Centos /]# cd data/bbs/
[root@Centos bbs]# touch text.txt
[root@Centos bbs]# mkdir textdir
[root@Centos bbs]# ls
textdir text.txt
客户端测试
[root@localhost ~]# cd /mnt
[root@localhost mnt]# ls -ll
total 4
drwxr-xr-x. 2 root root 4096 Aug 21 05:39 textdir
-rw-r--r--. 1 root root 0 Aug 21 05:39 text.txt
[root@localhost mnt]# touch 123.txt
touch: cannot touch `123.txt': Permission denied ----> 权限不足
所以需要在服务端改变其它用户的访问权限才可以
[root@Centos /]# chmod 777 data/bbs/
[root@Centos /]# ls -ld data/bbs/
drwxrwxrwx. 3 root root 4096 Aug 21 10:39 /data/bbs/
然后在客户端测试
[root@localhost mnt]# pwd
/mnt
[root@localhost mnt]# touch 123.txt
[root@localhost mnt]# ls -ll
total 4
-rw-r--r--. 1 nfsnobody nfsnobody 0 Aug 21 05:44 123.txt
drwxr-xr-x. 2 root root 4096 Aug 21 05:39 textdir
-rw-r--r--. 1 root root 0 Aug 21 05:39 text.txt
[root@localhost mnt]# echo "123">>123.txt
[root@localhost mnt]# cat 123.txt
123
经过测试表明,客户端也可以正常访问共享目录与文件,同时也具有读写权限,那么问题又来了,客户端是通过什么用户名来访问服务器端的呢,刚刚修改的权限是征对其它用户(除了文件、目录的所有者与所属组外的用户),如果需要限制访问共享目录,其实这个权限是具有很大安全隐患的
那么我们来服务端看看到底是授权什么用户来访问共享目录呢???
[root@Centos /]# cat /var/lib/nfs/etab
/data/bbs 192.168.1.3(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534)
这里我们查看这个uid/gid都为65534的用户是哪个???
[root@Centos /]# grep 65534 /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
所以服务端我们将权限重新修改如下
[root@Centos /]# chown -R nfsnobody:nfsnobody data/bbs/
[root@Centos /]# ls -ld data/bbs/
drwxrwxrwx. 3 nfsnobody nfsnobody 4096 Aug 21 10:44 data/bbs/
客户端查看配置生效情况如下
[root@localhost mnt]# ls -ll
total 8
-rw-r--r--. 1 nfsnobody nfsnobody 4 Aug 21 05:44 123.txt
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Aug 21 05:39 textdir
-rw-r--r--. 1 nfsnobody nfsnobody 0 Aug 21 05:39 text.txt
但是细心的朋友们肯定也发现了,这样还是不安全,因为所有相同的版本的系统都会默认存在这一个用户nfsnobody,那么对限制访问还是没有做到万无一失,因此这里就出现了更改默认用户的做法,将默认用户更改成其它用户
其服务端配置如下
首先得添加用户并禁止登陆指定它的UID
[root@Centos /]# useradd -s /sbin/nologin -M -u 3000 nfsuser
[root@Centos /]# tail -1 /etc/passwd
nfsuser:x:3000:3000::/home/nfsuser:/sbin/nologin
修改NFS配置
[root@Centos /]# echo "#####config for nfs-server 2016-8-21">/etc/exports
清空配置并加上一行注释信息
[root@Centos /]# echo "/data/bbs 192.168.1.3(rw,sync,all_squash,anonuid=3000,anongid=3000)">>/etc/exports 添加相关配置
[root@Centos /]# tail -2 /etc/exports 检查配置情况
#####config for nfs-server 2016-8-21
/data/bbs 192.168.1.3(rw,sync,all_squash,anonuid=3000,anongid=3000)
因此客户端同样也需要添加用户
[root@localhost mnt]# useradd -s /sbin/nologin -M -u 3000 nfsuser
[root@localhost mnt]# ls -ll
total 8
-rw-r--r--. 1 nfsnobody nfsnobody 4 Aug 21 05:44 123.txt
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Aug 21 05:39 textdir
-rw-r--r--. 1 nfsnobody nfsnobody 0 Aug 21 05:39 text.txt
测试发现还是原来默认的用户,这是因为服务端虽然改了NFS的配置,但是共享目录与文件的相关配置仍然是默认的所以上服务端查看下目录权限如下
[root@Centos bbs]# ls -ll
total 8
-rw-r--r--. 1 nfsnobody nfsnobody 4 Aug 21 10:44 123.txt
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Aug 21 10:39 textdir
-rw-r--r--. 1 nfsnobody nfsnobody 0 Aug 21 10:39 text.txt
因此需要对/data/bbs/这个共享目录进行更改
[root@Centos bbs]# chown -R nfsuser.nfsuser /data/bbs/
[root@Centos bbs]# ls -ll
total 8
-rw-r--r--. 1 nfsuser nfsuser 4 Aug 21 10:44 123.txt
drwxr-xr-x. 2 nfsuser nfsuser 4096 Aug 21 10:39 textdir
-rw-r--r--. 1 nfsuser nfsuser 0 Aug 21 10:39 text.txt
最后登陆到客户查看配置生效情况如下
[root@localhost mnt]# ls -ll
total 8
-rw-r--r--. 1 nfsuser nfsuser 4 Aug 21 05:44 123.txt
drwxr-xr-x. 2 nfsuser nfsuser 4096 Aug 21 05:39 textdir
-rw-r--r--. 1 nfsuser nfsuser 0 Aug 21 05:39 text.txt
[root@localhost mnt]# touch 234.txt
[root@localhost mnt]# ls -ll
total 8
-rw-r--r--. 1 nfsuser nfsuser 4 Aug 21 05:44 123.txt
-rw-r--r--. 1 nfsuser nfsuser 0 Aug 21 06:27 234.txt
-rw-r--r--. 1 nfsuser nfsuser 0 Aug 21 06:17 23.txt
drwxr-xr-x. 2 nfsuser nfsuser 4096 Aug 21 05:39 textdir
-rw-r--r--. 1 nfsuser nfsuser 0 Aug 21 05:39 text.txt
表明配置正确,且达到需求,此时访问共享目录的权限就更改为nfsuser,其它主机如果没有添加此用户是无法正常访问NFS的共享目录与文件的,安全性比较高。至此整个安装与布署过和结束。
Linux系统NFS网络文件系统的更多相关文章
- Linux系统——NFS网络文件系统
在企业集群架构的工作场景中,NFS网络文件系统一般被用来存储共享视频,图片,附件等静态资源文件,通常网站用户上传的文件都会放到NFS共享里,然后前端所有的节点访问这些静态资源时都会读取NFS存储上的资 ...
- linux初学者-NFS网络文件系统篇
linux初学者-NFS网络文件系统篇 在上一篇的SAMBA篇中介绍了linux系统和windows系统之间共用的网络文件系统CIFS,主要用于客户端是windows的情况.在linux系统之间,所用 ...
- Linux之NFS网络文件系统
NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络资源共享.在NFS的应用中,本地NFS的客户端应用可 ...
- tiny4412 linux+qtopia nfs网络文件系统的挂载
1,首先确定uboot启动内核的bootargs参数 Linux-CommandLine = root=/dev/nfs nfsroot=192.168.1.131:/home/tiny4412/ro ...
- Linux基础学习-NFS网络文件系统实时文件共享
NFS网络文件系统 如果大家觉得Samba服务程序的配置太麻烦了,那么你共享文件的主机都是Linux系统,那么推荐大家在客户端部署nfs服务来共享文件.nfs(网络文件系统)服务可以将远程Linux系 ...
- [学习嵌入式开发板]iTOP-4412实现NFS网络文件系统
本文转自迅为:http://www.topeetboard.com 学习平台:iTOP-4412开发板 本文讲解如何在 iTOP-4412 开发板上实现 NFS 网络文件系统. 我们使用的软硬件环境是 ...
- linux初学者-CIFS网络文件系统篇
linux初学者-CIFS网络文件系统篇 CIFS是一种通用网络文件系统,主要用于网络设备之间的文件共享.CIFS可以在linux系统和windows系统之间共享文件,因此这种文件系统主要用于客户端是 ...
- NFS(网络文件系统)
NFS(网络文件系统) 1.关于NFS介绍 1.1NFS在企业中的应用场景 在企业集群架构的工作场景中,NFS网络文件系统一般被用来存储共享视频,图片,附件等静态资源文件,通常网站用户上传的文件都会放 ...
- NFS 网络文件系统挂载在A8板子上
我承认自己是菜鸟,没什么网络知识就来搞挂载nfs网络文件系统,花费了5天的时间才把nfs网络文件系统成功挂载在A8板子上,实现了A8板子和虚拟机的文件共享.分享一下个人经验: 以下是基于nfs已经完成 ...
随机推荐
- ConcurrentDictionary线程不安全么,你难道没疑惑,你难道弄懂了么?
前言 事情不太多时,会时不时去看项目中同事写的代码可以作个参考或者学习,个人觉得只有这样才能走的更远,抱着一副老子天下第一的态度最终只能是井底之蛙.前两篇写到关于断点传续的文章,还有一篇还未写出,后续 ...
- 优化javaScript代码,提高执行效率
今天看完书,总结了一下可以如何优化 JavaScript . 1.合并js文件 为优化性能,可以把多个js文件(css文件也可以)合并成极少数大文件.跟十个5k的js文件相比,合并成一个50k的文件更 ...
- 精彩 .NET 2015
英文原文:Understanding .NET 2015 Understanding 翻译为了解或理解,对于 .NET 来说,2015 年注定会更加精彩,所以标题就用了"精彩"这个 ...
- C算法编程题(五)“E”的变换
前言 上一篇<C算法编程题(四)上三角> 插几句话,说说最近自己的状态,人家都说程序员经常失眠什么的,但是这几个月来,我从没有失眠过,当然是过了分手那段时期.每天的工作很忙,一个任务接一个 ...
- 【SQLServer】DBHelper即C#数据库底层封装
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.C ...
- hibernate笔记--通过SchemaExport生成数据库表
方法比较简单,项目中只需要两个java类(一个实体类,如User,一个工具类),两个配置文件(hibernate必须的两个配置文件hibernate.cfg.xml,与User.hbm.xml),即可 ...
- 细说Cookie
阅读目录 开始 Cookie 概述 Cookie的写.读过程 使用Cookie保存复杂对象 Js中读写Cookie Cookie在Session中的应用 Cookie在身份验证中的应用 Cookie的 ...
- 基于OpenSLL的RSA加密应用(非算法)
基于OpenSLL的RSA加密应用(非算法) iOS开发中的小伙伴应该是经常用der和p12进行加密解密,而且在通常加密不止一种加密算法,还可以加点儿盐吧~本文章主要阐述的是在iOS中基于openSL ...
- [Web API] Web API 2 深入系列(5) 特性路由
目录 1. 特性路由注册 2. 路由解析 - 生成DataTokens - 选择HttpController - 选择Action 特性路由的目的在于更好的提供restful架构的接口,最近好忙(懒) ...
- WPF DataGrid 鼠标双击选中的DataGridRow及Row数据
设置DataGrid的MouseDoubleClick事件 代码 //DataGrid鼠标双击事件 Private void dataGrid_MouseDoubleClick(object send ...