Try   HackMD

Autofs自動掛載

autofs是一個程式,實際由automount執行自動掛載。
可根據需要自動掛載指定的目錄,一段時間不用後會自動卸載。

rpcbind服務啟動在port 111
nfs服務啟動在port 2049

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
在掛載前需要有NFS連線,可使用showmount -e <IP>查看可掛載目錄

在NFS的 Client端有關autofs的設定檔共有2個:/etc/auto.master、/etc/auto.nfs(此名稱可自訂)

  • autofs的主要設定檔為/etc/auto.master
    ​​​​/etc/auto.master內容
    ​​​​/home/nfsfile /etc/auto.nfs
    ​​​​
    ​​​​#第一個/home/nfsfile為NFS的server端要被掛載的目錄,即為autofs會持續偵測的目錄
    ​​​​#第二個/etc/auto.nfs為在NFS的client端,定義每次掛載時的目錄資源,這個檔案的名稱可自訂
    
    ​​​​/etc/auto.nfs內容
    ​​​​public    192.168.200.139:/home/public
    ​​​​test      192.168.200.139:/home/test
    ​​​​tmp       192.168.200.139:/tmp
    ​​​​
    ​​​​#以public這項為例,來源為.139的/home/public,會掛載在client端的/home/nfsfile目錄底下
    
$ showmount -e <IP>                #查看<IP>可掛載目錄
$ vi /etc/auto.master
/home/nfsfile /etc/auto.nfs        #這個主要設定檔要有"被持續偵測的目錄",和"資料對應檔"
$ vi /etc/auto.nfs
autofstest -rw,bg,soft,rsize=32768,wsize=32768 192.168.200.139:/home/bensonchang
$ sudo systemctl restart autofs    #重新啟動autofs服務
$ ll /home/nfsfile                 #列出nfsfile下的目錄發現是空的,這是正常的,因為還未掛載任何目錄
total 4
drwxr-xr-x 2 root root    0 Mar 23 10:12 ./
drwxr-xr-x 5 root root 4096 Mar 23 10:06 ../
$ cd /home/nfsfile/autofstest      #進入掛載的目錄中

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
注意事項

  1. /home/nfsfile 是由autofs所自動建立,因此原本系統中"不應"存在這個目錄
  2. /home/nfsfile 可掛載的目錄會寫在/etc/auto.nfs

範例

NFS伺服器:redhattest 192.168.200.139
NFS客戶端:ub1 192.168.200.140

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

伺服器端提供2個掛載點

$ vi /etc/auto.master
/home/nfsfile /etc/auto.nfs

設定主要設定檔

$ vi /etc/auto.nfs
autofstest -rw,bg,soft,rsize=32768,wsize=32768 192.168.200.139:/home/bensonchang

設定資料對應檔

$ sudo systemctl restart autofs

重新啟動autofs服務

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

列出nfsfile下的目錄發現是空的,這是正常的,因為還未掛載任何目錄

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

進入目錄後可發現已被成功掛載

參考連結

鳥哥:NFS伺服器

tags RHCSA