我的Linux生活日記 26.分享資料夾-autofs
#
昨天已經安裝完 nfs server 接下來就是其他主機安裝端點工具啦!有兩個處理方式:mount 以及 autofs。
mount
#
mount 指令如下:
1
2
|
madir -p /mnt/nfs/centos7
mount 192.168.56.173:/share /mnt/nfs/centos7
|
但是不建議這樣做,主要是網路不通無法掛載遠端目錄時會在成PRC服務逾時,間接拖垮系統效能。接下來是建議使用 autofs 掛載目錄。
安裝
#
1
|
sudo apt install autofs
|
1
|
sudo yum install autofs
|
編輯設定文件
#
這邊我直接新增文件,如果沒有 /etc/auto.master.d 這個目錄可以進入 /etc/auto.master 這份文件直接編輯
- /etc/auto.master.d/jc-share.autofs
1
2
|
# [掛載目錄] [遠端配置文件] [參數]
/mnt/nfs /etc/jc-share.nfs --timeout=10
|
上述文件中 /mnt/nfs 不需要特別新增,autofs會在掛載時自動處理。
1
2
|
# [資料夾名稱] [掛載參數] [遠端主機分享目錄]
centos7 -fstype=nfs,vers=4,rw 192.168.56.173:/share
|
測試
#
1
2
3
4
5
6
7
8
|
Starting automounter version 5.1.2, master map /etc/auto.master
using kernel protocol version 5.03
lookup(file): failed to read included master map auto.master
mounted indirect on /mnt/nfs with timeout 10, freq 3 seconds
attempting to mount entry /mnt/nfs/centos7 # >> 當有呼叫 /mnt/nfs/centos7 才會去掛載
mount(nfs): no hosts available
failed to mount /mnt/nfs/centos7 # 掛載失敗訊息
re-reading map for /mnt/nfs
|
1
2
3
4
5
6
7
8
|
Starting automounter version 5.1.2, master map /etc/auto.master
using kernel protocol version 5.03
lookup(file): failed to read included master map auto.master
mounted indirect on /mnt/nfs with timeout 10, freq 3 seconds
attempting to mount entry /mnt/nfs/centos7 # >> 當有呼叫 /mnt/nfs/centos7 才會去掛載
re-reading map for /mnt/nfs
mounted /mnt/nfs/centos7
1 remaining in /mnt/nfs # 掛載成功訊息
|
啟動 autofs 服務
#
測試麼有問題後就可以開啟服務啦!
1
2
3
|
sudo systemctl restart autofs
sudo systemctl start autofs
sudo systemctl enable autofs
|
1
2
3
|
/etc/init.d/autofs stop && /etc/init.d/autofs start
/etc/init.d/autofs status
chkconfig aufofs on
|
掛載 Cifs
#
- /etc/auto.master.d/bakerst.autofs
1
|
/bakerst /etc/auto.bakerst
|
1
|
cases -fstype=cifs,credentials=/secure/sherlock ://serverX/cases
|
- 新增檔案 /secure/sherlock,內容如下:(only root access, permission 600)
1
2
3
|
username=[UserName]
password=[Password]
domain=[DomainName]
|
Accessing Network Storage with SMB
錯誤訊息
#
- automount: program is already running.
代表 autofs 已經啟動
cifs mount works on 6.8, but not on 6.5
參考資料
#
使用 Autofs 按需掛接
鳥哥的 Linux 私房菜 - 第十三章、檔案伺服器之一:NFS 伺服器