- 安裝套件
nfs-utils-1.2.2-7.el6.x86_64
rpcbind-0.2.0-8.el6.x86_64
- 編輯設定檔 /etc/exports
[root@deyu ~]# vim /etc/exports
# 分享目錄 分享給主機(參數)
/home/guests 192.168.122.0/255.255.255.0(rw,sync)
# 參數
* rw:read-write,可讀寫的權限;
* ro:read-only,唯讀的權限;
* sync:資料同步寫入到記憶體與硬碟當中;
* async:資料會先暫存於記憶體當中,而非直接寫入硬碟。
* no_root_squash:
登入 NFS 主機使用分享目錄的使用者如果是 root,對於分享的目錄具有 root 的權限。
極不安全,不建議使用。
* root_squash:
登入 NFS 主機使用分享目錄的使用者如果是 root,權限將被壓縮成匿名使用者,
通常他的 UID 與 GID 都會變成 nobody(nfsnobody) 那個系統帳號的身份;
* all_squash:
不論登入 NFS 的使用者身份為何,都會被壓縮成為匿名使用者,通常是 nobody(nfsnobody) 。
* anonuid:
anon 意指 anonymous (匿名者),自訂匿名使用者的 UID。
* anongid:自訂匿名使用者的是變成 GID。
- 啟動 rpcbind 服務
[root@deyu ~]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]
- 啟動 nfs 服務
[root@deyu ~]# /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
- 設定開機即啟動 rpcbind 及 nfs 服務
[root@deyu ~]# chkconfig rpcbind on
[root@deyu ~]# chkconfig --list rpcbind
rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@deyu ~]# chkconfig nfs on
[root@deyu ~]# chkconfig --list nfs
nfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off
- 查看有沒有可以掛載的檔案系統
[root@deyu ~]# showmount [-ae] [hostname|IP]
參數:
-a :顯示目前主機與用戶端的 NFS 連線分享的狀態;
-e :顯示某部主機的 /etc/exports 所分享的目錄資料。
[root@deyu ~]# showmount -e deyu.wang
Export list for deyu.wang:
/home/guests 192.168.122.0/255.255.255.0
- 重新設定 /etc/exports 後,利用 exportfs 處理 nfs 的掛載,可不需重新啟動 nfs。
[root@deyu ~]# exportfs [-aruv]
參數:
-a :全部掛載(或卸載) /etc/exports 檔案內的設定
-r :重新掛載 /etc/exports 的設定,亦同步更新 /etc/exports
及 /var/lib/nfs/xtab 的內容。
-u :卸載某一目錄
-v :在 export 時將分享的目錄顯示到螢幕上。
[root@deyu ~]# vim /etc/exports
/home/guests 192.168.111.0/255.255.255.0(rw,sync)
[root@deyu ~]# exportfs -arv
exporting 192.168.111.0/255.255.255.0:/home/guests