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/ 123 192.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的用戶限定後的uid和gid,前提是本機的/etc/passwd中存在這個uid和gid。
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 for 192.168 . 0.104 : /tmp/ 123 192.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/ 123 test //掛載,-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 0 186M 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 :顯示共享的目錄