NFS 網路檔案系統 自動掛載
NFS:網路檔案系統
用於linux 和linux 之間或者linux和unix之間
將nfs伺服器的共享資料夾掛載到客戶端,使用協議RPC(遠端程序排程)
NFS使用rpc
1.當伺服器端的nfs和rpc 服務 啟動後會形成很多程序:mountd ,nfs,nlockmgr,status程序。
2. 客戶端有rpc.mountd ,rpciod , nlockmgr,status程序。
3.客戶端需要掛載伺服器端的檔案,使用rpc.mountd程序項伺服器的portmapper 傳送請求連線。
4.伺服器端的portmapper 收到請求後,向客戶端迴應,同時告訴客戶端使用哪個埠與伺服器相連。
5.客戶端使用rpc.mountd 請求伺服器端程序mountd,進行掛載。
6.掛載完畢後,客戶端使用程序rpciod 呼叫服務端的nfs程序,進行磁碟io操作。
7.兩端都呼叫nlockmgr鎖機制,當伺服器端在編寫文件時,禁止客戶端的訪問。
8. 為了維持連線,兩端都使用status程序。
配置NFS服務:
1.檢視是否安裝nfs伺服器
[[email protected] ~]# rpm -qa |grep nfs
2.啟動nfs服務,設定為開機自啟動,chkconfig nfs on
3.檢視自己的rpc程序,若檢視其他主機上的rpc程序可使用rpc -p ip
4.
若要共享一個資料夾,需要在共享清單中指明該檔案,檔名和共享名要一致,不可更改。
[[email protected] ~]# vim /etc/exports ,可以使用 man 5 exports 檢視語法結構如下:
物理資料夾 來源(許可權,引數)
/public 192.168.101.0/24(ro,sync)
5.匯出共享清單
[[email protected] ~]# exportfs -rv r:匯出 v:詳細資訊
6.客戶端檢視是否能夠訪問:
檢視自己的rpc程序是否開啟
[[email protected] ~]# rpcinfo -p
檢視對方的exports檔案是否可以訪問:
[[email protected] ~]# showmount -e 192.168.101.250
7.建立掛載點,掛載伺服器端共享檔案
[[email protected] ~]# mkdir /mnt/nfs
[[email protected] ~]# mount 192.168.101.250:/public /mnt/nfs/
8.開機自動掛載
編輯檔案系統表/etc/fstab
192.168.101.250:/public /mnt/nfs nfs ro,soft,intr 0 0
soft:掛載出錯時,發出警告。intr:掛載失敗時,立即中斷掛載。否則系統將無法啟動
9.先解除安裝掉已經掛載的,使用命令:umount /mnt/nfs
使用命令mount -a ,掛掛載成功
10.
這種方式的掛載需要消耗大量的資源來維持連線,可以使用自動掛載當切換到該目錄時進行掛載,退出時,取消掛載
安裝autofs軟體包
11.編輯autofs的配置檔案 /etc/auto.master
/mnt/nfs /etc/auto.nfs --timeout=60
當訪問/mnt/nfs下的資料夾時,檢視/etc/auto.nfs 的配置,當退出/mnt/nfs後60 秒,自動取消連線
12.產生並編輯/etc/auto.nfs檔案。(server1目錄不用建立)
[[email protected] ~]# vim /etc/auto.nfs
server1 -ro,soft,intr 192.168.101.250:/public
13. 重啟autofs 服務
[[email protected] ~]# service autofs restart
14.當切換到/mnt/nfs/server1時,自動掛載。退出server1後60秒後將 自動取消掛載
15. 建立一個可讀寫的共享檔案/abc
在伺服器端建立目錄/abc
16.將該目錄寫入共享清單
[[email protected] ~]# vim /etc/exports
17.匯出共享清單
18.在客戶端
仍監控/mnt/nfs掛載點
[[email protected] ~]# vim /etc/auto.master
[[email protected] ~]# vim /etc/auto.nfs
server2 -rw,soft,intr 192.168.101.250:/abc
19.重啟autofs服務
20.無法建立檔案,許可權不足
21修改伺服器端的許可權
[[email protected] /]# chmod o+wt /abc
轉載於:https://blog.51cto.com/jialiang10086/998931