1、是UNIX和linux所特有的,共享以后可将远程的文件目录共享到本地的磁盘,可以复制、写、西东删除,跟本地的文件是没什么区别的。

例如,ABC三台linux主机,需要访问同样的资源,就可以把资源放到A上,BC通过NFS访问A的资源。

建议在centos5上搭建NFS。

2、安装NFS

1
[root@localhost one.com]# yum install -y nfs-utils

3、编写配置文件/etc/exports

1
2
3
4
5
6
7
[root@client ~]# vim /etc/exports
/tmp/123192.168.0.0/24(rw,sync,all_squash,anonuid=501,anongid=501)
/*共分为三部分,第一部分就是本地要共享出去的目录,
第二部分为允许访问的主机(可以是一个IP也可以是一个IP段)
第三部分就是小括号里面的,为一些权限选项。它表示:共享的目录为/home,
信任的主机为192.168.0.0/24这个网段,权限为读写,同步,
限定所有使用者,并且限定的uid和gid都为501。*/

rw :读写;
ro :只读;
sync :同步模式,内存中数据时时写入磁盘;
async :不同步,把内存中数据定期写入磁盘中;
no_root_squash :加上这个选项后,root用户就会对共享的目录拥有至高的权限控制,就像是对本机的目录操作一样。不安全,不建议使用;
root_squash:和上面的选项对应,root用户对共享目录的权限不高,只有普通用户的权限,即限制了root
all_squash:不管使用NFS的用户是谁,他的身份都会被限定成为一个指定的普通用户身份;
anonuid/anongid :要和root_squash 以及all_squash一同使用,用于指定使用NFS的用户限定后的uidgid,前提是本机的/etc/passwd中存在这个uidgid

4、启动NFS

1
2
3
4
5
6
7
8
[root@localhost ~]# /etc/init.d/rpcbind start   //要先启动rpcbind
Starting rpcbind:                                          [  OK  ]
[root@localhost ~]# /etc/init.d/nfs start
Starting NFS services:  exportfs: Failed to stat /tmp/123: No such file or directory
[  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]

5、查看共享目录

1
2
3
[root@localhost 123]# showmount -e 192.168.0.104
Export list for192.168.0.104:
/tmp/123192.168.0.0/24

6、客户端挂载共享目录

1
2
3
4
5
6
7
8
9
10
11
[root@localhost one.com]# yum install -y nfs-utils //安装NFS
[root@client ~]# mount -t nfs 192.168.0.104:/tmp/123test
//挂载,-t指定文件系统类型,共享服务器IP地址和目录
[root@client ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
15G  2.0G   12G  15% /
tmpfs                 186M     0186M   0% /dev/shm
/dev/sda1             485M   30M  430M   7% /boot
192.168.0.104:/tmp/123
6.5G  2.0G  4.1G  33% /root/test

7、exportfs用法

1
2
[root@localhost tmp]# exportfs -arv   //查看共享目录
192.168.0.0/24:/tmp/123

-a :全部挂载或者卸载;
-r :重新挂载;
-u :卸载某一个目录;
-v :显示共享的目录