autofs自動掛載服務


大部分情況下,我們都需要將掛載信息寫入到/etc/fstab文件中,使其能隨機器開機時自動掛載。

但是對於像Samba、NFS等遠程資源,建議還是使用autofs自動掛載服務,因為如果掛載的遠程資源太多,則會給網絡帶寬和服務器的硬件資源帶來很大負載。

與mount命令不同,autofs服務程序是一種Linux系統守護進程,當檢測到用戶試圖訪問一個尚未掛載的文件系統時,將自動掛載該文件系統。換句話說,將掛載信息填入/etc/fstab文件后,系統在每次開機時都自動將其掛載,而autofs服務程序則是在用戶需要使用該文件系統時才去動態掛載,從而節約了網絡資源和服務器的硬件資源。

安裝autofs服務程序:

[root@wu ~]# dnf install autofs

 /etc/auto.master是antofs的主配置文件,在autofs服務程序的主配置文件中需要按照“掛載目錄 子配置文件”的格式進行填寫,掛載目錄是設備掛載位置的上一級目錄。

在子配置文件中,應按照“掛載目錄 掛載文件類型及權限 :設備名稱”的格式進行填寫。

示例1:

將遠程主機172.25.250.10的NFS文件系統/rhome/file1掛載到本地/haha/hehe目錄下

主配置文件

[rootwu ~]# vim /etc/auto.master
#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/haha  /etc/ceshi.misc   #/haha是本地掛載路徑,/etc/ceshi.misc是子配置文件(子配置文件名稱需要以.misc結尾)
/misc   /etc/auto.misc   #參考文件,默認存在
#

子配置文件

[rootwu ~]# vim /etc/ceshi.misc
hehe  -fstype=nfs,rw  172.25.250.10:/rhome/file1  #-fstype指定文件系統的類型,rw定義文件的權限,172.25.250.10:/rhome/file1是待掛載的文件設備

重啟服務

[root@wu ~]# systemctl start autofs 
[root@wu ~]# systemctl enable autofs 

使用

[root@wu ~]#cd /haha/hehe  #當切換到hehe目錄中的時候,會將設備信息自動掛載

示例2:

將光盤設備/dev/cdrom掛載到/media/cdrom目錄中。

主配置文件

[rootwu ~]# vim /etc/auto.master
#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/media  /etc/iso.misc
/haha   /etc/ceshi.misc   
/misc   /etc/auto.misc   #參考文件,默認存在
#

子配置文件

[rootwu ~]# vim /etc/iso.misc
cdrom   -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom

重啟服務

[root@wu ~]# systemctl start autofs 
[root@wu ~]# systemctl enable autofs 

  

 

  

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM