NFS分为客户端,服务端。客户端要访问服务端,要写从RPC服务获得端口。

整个流程分为:

1,服务端rpc服务先启动
2,nfs服务把端口上报给rpc服务
3,rpc客户端通过服务端的rpcbind拿到访问端口
4,rpc客户端通过端口访问文件

rpc服务,在centos5.x下叫portmap,在centos6.x下叫rcpbind

客户端也要有rpc才能访问服务端

所以NFS的软件列表:

nfs-utils
rpcbind

安装NFS
yum install nfs-utils rpcbind
最好客户端也要安装

查看是否已安装
rpm -qa nfs-utils

lsof -i:111

查看状态
/etc/init.d/rpcbind status

查看rpc池的信息
rpcinfo -p localhost

注意:一定要先启动rpcbind,然后再启动nfs。因为nfs会把端口上报给rpc

[root@nfsServer init.d]# /etc/init.d/nfs status
rpc.svcgssd is stopped
rpc.mountd is stopped
nfsd is stopped
rpc.rquotad is stopped
[root@nfsServer init.d]#
[启动nfs服务
[root@nfsServer init.d]# /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 ]

再看rpc池的信息就有很多了

[root@nfsServer init.d]# rpcinfo -p localhost
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
100011 1 udp 875 rquotad
100011 2 udp 875 rquotad
100011 1 tcp 875 rquotad
100011 2 tcp 875 rquotad
100005 1 udp 36696 mountd
100005 1 tcp 59667 mountd
100005 2 udp 36644 mountd
100005 2 tcp 36430 mountd
100005 3 udp 49056 mountd
100005 3 tcp 55778 mountd
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 2 tcp 2049 nfs_acl
100227 3 tcp 2049 nfs_acl
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs

NFS的配置文件:

/etc/exports

格式:
nfs共享目录 nfs客户端地址(参数1,参数2)

把/image文件夹共享给103 104的机器

[root@nfsServer log]# cat /etc/exports
/image 192.168.1.103(rw,sync) 192.168.1.104(rw,sync)

共享给所有用户
/data *(rw,sync)

重启nfs
/etc/init.d/nfs reload

查看共享的文件夹
[root@nfsServer ~]# showmount -e 192.168.1.102
Export list for 192.168.1.102:
/image 192.168.1.104,192.168.1.103
挂在本机上试试
[root@nfsServer image]#
[root@nfsServer image]# mount -t nfs 192.168.1.102:/image /mnt
[root@nfsServer image]# cd /mnt/
[root@nfsServer mnt]# ls
baseImage.log

但是这时候通过/mnt 写入权限不足???

[root@nfsServer image]# cd /mnt/
[root@nfsServer mnt]# touch xc.log
touch: cannot touch `xc.log': Permission denied

因为有些权限没有配置,所以在服务端看来,所有有的访问都是65534(nfsnobody)的用户权限

[root@nfsServer mnt]# cat /var/lib/nfs/etab
/image 192.168.1.*(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,
no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,no_all_squash)

这时候如果客户端写的文件权限是nfsnobody,服务端的是root(服务端的用户)

[root@nfsServer mnt]# ls -l
total 0
-rwxrwxrwx 1 root root 0 Jul 23 03:09 baseImage.log
-rw-r--r-- 1 nfsnobody nfsnobody 0 Jul 23 03:44 vv.log

参数说明:
sync 写入到磁盘,同步写
async 异步写
root_squash 如果用户是root的话,回映射成匿名用户
no_root_squash 客户端访问共享文件夹,客户端用户如果是root的话,有root权限
all_squash 不管用户权限如何,都会压缩成匿名用户nfsnobody(anonuid=65534,anongid=65534),uid gid是可以改的

客户端:

要启动bind服务
[root@nfsClient01 etc]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]
客户端查看是不是能和服务端连上
[root@nfsClient01 etc]# showmount -e 192.168.1.102
Export list for 192.168.1.102:
/image 192.168.1.*

没有问题的话,客户端就可以mount挂载了

排查错误:
先ping 看能不能通
111是nfs的主端口
telnet 102.168.1.102 111

exportfs -rv 等价于 /etc/init.d/nfs reload

服务端的参数
cat /var/lib/nfs/etab
客户端的参数
cat /proc/mounts

linux学习笔记--NFS的更多相关文章

  1. Linux 学习笔记

    Linux学习笔记 请切换web视图查看,表格比较大,方法:视图>>web板式视图 博客园不能粘贴图片吗 http://wenku.baidu.com/view/bda1c3067fd53 ...

  2. Linux 学习笔记之超详细基础linux命令 Part 7

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 6----------------- ...

  3. Linux 学习笔记之超详细基础linux命令 Part 5

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 4----------------- ...

  4. linux学习笔记2-linux的常用命令

    第一篇博客:linux学习笔记1-ubuntu的安装与基本设置 之中,已经介绍了如何安装linux操作系统,以及一些基本的设置修改. 本篇博客主要介绍linux中的一些常用的终端命令 ======== ...

  5. Linux学习笔记(一)2015.4.13

    研究生由单片机转Linux学习 首先安装VMware虚拟机,用的是VMware 10.0 在VMware 10.0上安装视频上推荐的Red Hat Linux 5 安装后正式进入Linux学习 笔记1 ...

  6. 20160127 linux 学习笔记

    Linux学习笔记第一天 Linux基本介绍 Linux的起源和发展: 简单说linux是一种操作系统,可以安装在包括服务器.个人电脑,乃至PDA.手机.打印机等各类设备中. 起源: Linux起源于 ...

  7. linux —— 学习笔记(汇总)

    笔记目录:一.系统知识 和 基本概念                    二.常用操作                   三.系统管理(内存.设备.服务等管理)                   ...

  8. Linux学习笔记-林耐斯Notes-Linux就该这么学

    Linux学习笔记... 参考的优秀Linux网站: http://www.w3cschool.cn/linux/ http://www.linuxeye.com/ http://linux.vbir ...

  9. Linux~学习笔记目录索引

    回到占占推荐博客索引 本篇文章是对自己学习Linux及在它的环境下部署工具的一个总结,以方便自己查阅,也给他人一个帮助,本文章同时会不断的更新,欢迎大家订阅! 本目录包括的内容会包括linux基础命令 ...

随机推荐

  1. Python基础篇【第8篇】: Socket编程(二)SocketServer

    SocketServer 在上一篇文章中我们学习了利用socket模块创建socket通信服务,但细心学习后就会发现利用socket模块创建的服务无法进行多进程的处理,当需要进行大量请求处理时,请求就 ...

  2. [转]SQL Server 连接串关键字别名

    转自:http://stackoverflow.com/questions/3077412/what-is-the-difference-between-trusted-connection-and- ...

  3. (转)打印相关_C#图片处理Bitmap位图缩放和剪裁

    原文地址:http://blog.sina.com.cn/s/blog_6427a6b50101el9d.html 在GDI+中,缩放和剪裁可以看作同一个操作,无非就是原始区域的选择不同罢了. /// ...

  4. socket模块的getaddrinfo方法详解

    getaddrinfo方法用于通过url解析dns import sys,socket def dns_resolver(url): result = socket.getaddrinfo(url, ...

  5. (Hibernate进阶)Hibernate系列——总结篇(九)

    这篇博文是hibernate系列的最后一篇,既然是最后一篇,我们就应该进行一下从头到尾,整体上的总结,将这个系列的内容融会贯通. 概念 Hibernate是一个对象关系映射框架,当然从分层的角度看,我 ...

  6. HTML与CSS二三事

    概述 HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,他是一种制作万维网页面标准语言(标记).相当于定义统一的一套规则,大家都来遵守他,这样就可以让浏览器 ...

  7. ps基础知识

    一 1. ps常用快捷键:ctrl+d 结束选区    ctrl+alt+z  返回          ctrl+z 撤销           ctrl+x 剪切 ctrl+t 编辑图片    ctr ...

  8. jQuery on 绑定的事件触发多次

    jquery用on绑定事件,在代码执行过程中,可能会遇到多次执行的情况. 解决方案是在on的事件前面加上一个off,再on. $('#btnBind').off('click').on('click' ...

  9. Opencv配置问题_Error LNK2019

    终于配好opencv(Win7 64位+VS2013+opencv2.4.9),兴奋的写了第一个程序(当然是显示lena的玉照了): #include <opencv2\opencv.hpp&g ...

  10. TUniConnection连接

    ChangeFileExt RealTime_Server.ini: [Config]FromConStr=DBTYPE=0|SERVER=127.0.0.1|PORT=7788|DBNAME=jzx ...