NFS共享协议

一、NFS工作原理:

1、依赖于RPC(远程过程调用)映射机制

2、存取位于远程磁盘中的文档数据,对应用程序是透明的,和访问本地文件夹一样

二、配置及参数说明

1、主要的软件包:

nfs-utils-----

portmap----

2、主配置文件:

/etc/export

3、配置文件格式为:

共享目录  客户机地址 //IP、网段、*、单个域、主机名 (参数,参数)

配置文件参数说明:

rw(可读可写)、ro(可读)

sync(同步写入) 、rsync(异步写入)

no_root_squash(保留来及客户机端的root权限)、all_sqush(客户端权限都降为nfsnobody)

三、NFS服务搭建

1、安装软件包

[root@localhost ~]# rpm -q nfs-utils portmap //查看软件包是否安装

nfs-utils-1.0.9-66.el5

portmap-4.0-65.2.2.1

2、修改主配置文件

[root@localhost ~]# vim /etc/exports  

/root   192.168.10.0/24(rw,sync,no_root_squash)

//将/root、目录共享给192.168.10.0/24的网段,权限为可读可写、同步写入、保留客户端root权限

3、启动服务

[root@localhost ~]# service portmap restart

[root@localhost ~]# service nfs restart

[root@localhost ~]# chkconfig portmap on

[root@localhost ~]# chkconfig nfs on

4、客户端测试

[root@localhost ~]# service portmap restart

[root@localhost ~]# chkconfig portmap on

[root@localhost ~]# netstat -tulnp | grep -E '(nfs|rpc)'

[root@localhost ~]# showmount -e 192.168.10.10 //检测服务端共享的目录

Export list for 192.168.10.10:

/root 192.168.10.0/24

[root@localhost ~]# mkdir -p /nfs/root

[root@localhost ~]# mount -t nfs 192.168.10.10:/root /nfs/root/  //挂载网络共享到本地目录

[root@localhost ~]# df -h | grep nfs

192.168.10.10:/root    19G  2.6G   16G  15% /nfs/root

[root@localhost ~]# cd /nfs/root/

[root@localhost root]# touch file1.txt  

[root@localhost root]# ls -l file1.txt   //测试客户机的可读可写权限

-rw-r--r-- 1 root root 0 04-15 10:03 file1.txt