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. EA使用

    类逻辑图 关系1:泛化(继承),Driver和Northeastermer继承了Person类 关系2:实现,Northeastermer实现了LivingLeiFeng类 关系3:  关联,两个对象 ...

  2. Linux系统挂载数据盘

    参考:http://help.aliyun.com/knowledge_detail/5974154.html?spm=5176.788314850.3.2.hUqwXo 1.在阿里云上购买了服务器, ...

  3. JavaScript能干什么?

    真的是长见识了,JavaScript居然能做除了WEB界面外运行于任何平台的APP,而且可以做服务器端,还有天理和王法吗?JavaScript到底有多神奇,要不要重新上路,老程序员何去何从,自然要先网 ...

  4. Ping出现TTL expired in transit的原因

    今天上班检查服务器时发现出现TTL expired in transit的提示,这种提示还是第一次见,如图: ping 和 tracert 的结果 用tracert来看路由状况,原来是出现路由环路导致 ...

  5. linux命令之chmod 2011.11.24转载于网络

    使用权限 : 所有使用者 使用方式 : chmod [-cfvR] [--help] [--version] mode file... 说明 : Linux/Unix 的档案调用权限分为三级 : 档案 ...

  6. 转@ManyToMany- annotation关系映射篇(下)

    原文:http://blog.sina.com.cn/s/blog_6fef491d0100obdd.html 终于要说ManyToMany了 场景:Product和Customer. 先看TestP ...

  7. arcgis_engine_c++_runtime_r6034_error

    在启动项目中添加app.manifest文件 <?xml version="1.0" encoding="utf-8"?> <asmv1:as ...

  8. Take advantage of “Integrated Calling” to know whom suspect talked to

    A new feature in iOS 10 is "Integrated Calling". An integrated call from Chat App like Nav ...

  9. Android启动标记

    1. Task是包含一系列Activity的堆栈, 遵循先进后出原则. 2. Task默认行为: (1) 前提: Activity A和Activity B在同一个应用中. 操作: Activity ...

  10. Maximo子表中增加附件功能

    附件功能的实现(详见ewell.webclient.beans.warranty.WarrantysDateBean ,ewell.webclient.beans.doclinks.custom.Ad ...