NFS 主要用於 Linux 與 Linux、Linux 與 Unix 之間共享文件,底層依賴 RPC(遠程進程調度)協議完成掛載。
[root@localhost ~]# rpm -qa | grep nfs nfs-utils-lib-1.0.8-7.6.el5 nfs-utils-1.0.9-42.el5 [root@localhost ~]# service nfs start
查看啟動後的進程:
[root@localhost ~]# mkdir /public [root@localhost ~]# cd /public [root@localhost public]# touch fi.txt [root@localhost ~]# vi /etc/exports
[root@localhost ~]# service nfs restart
另開一台 Linux(192.168.145.200):
[root@localhost ~]# rpcinfo -p 192.168.145.100 [root@localhost ~]# showmount -e 192.168.145.100 Export list for 192.168.145.100: /public * [root@localhost ~]# mount 192.168.145.100:/public /mnt/public
[root@localhost ~]# vi /etc/fstab 192.168.145.100:/public /mnt/public nfs defaults,soft,intr 0 0
此時若人正好站在掛載目錄裡,umount 會提示設備忙:
[root@localhost public]# fuser -v /mnt/public
USER PID ACCESS COMMAND
/mnt/public: root 4602 ..c.. bash
[root@localhost public]# fuser -kv /mnt/public
執行後會被踢出該目錄,再執行 umount 即可卸載。
先卸掉並把 fstab 裡新增的那行刪除,接著編輯 /etc/auto.master(可用 chkconfig --list | grep auto 查看相關服務):
[root@localhost ~]# cd /etc [root@localhost etc]# ls auto* autofs_ldap_auth.conf auto.master auto.misc auto.net auto.smb [root@localhost etc]# cp auto.misc auto.nfs [root@localhost etc]# vi auto.nfs
添加掛載映射:
[root@localhost etc]# service autofs restart Stopping automount: [ OK ] Starting automount: [ OK ]
此時訪問掛載點即可看到內容:
等一分鐘後再查,掛載已自動消失:
這正是 autofs 的價值:只有在真正訪問時才掛載,閒置超時後自動卸載,既省資源也避免大量僵死掛載點。