溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Linux中怎么安裝autofs自動(dòng)掛載服務(wù)

發(fā)布時(shí)間:2022-02-11 09:34:07 來(lái)源:億速云 閱讀:142 作者:iii 欄目:開(kāi)發(fā)技術(shù)

這篇文章主要介紹“Linux中怎么安裝autofs自動(dòng)掛載服務(wù)”的相關(guān)知識(shí),小編通過(guò)實(shí)際案例向大家展示操作過(guò)程,操作方法簡(jiǎn)單快捷,實(shí)用性強(qiáng),希望這篇“Linux中怎么安裝autofs自動(dòng)掛載服務(wù)”文章能幫助大家解決問(wèn)題。

autofs自動(dòng)掛載服務(wù)是一種Linux系統(tǒng)守護(hù)進(jìn)程,當(dāng)檢測(cè)到用戶視圖訪問(wèn)一個(gè)尚未掛載的文件系統(tǒng)時(shí),會(huì)自動(dòng)掛載該文件系統(tǒng)。簡(jiǎn)單來(lái)說(shuō),將掛載信息寫(xiě)入/etc/fstab文件中,系統(tǒng)在每次開(kāi)機(jī)時(shí)都會(huì)自動(dòng)掛載,而autofs服務(wù)則是在用戶需要使用該文件系統(tǒng)時(shí)才去動(dòng)態(tài)掛載,從而節(jié)約了網(wǎng)絡(luò)資源和服務(wù)器硬件資源的開(kāi)銷(xiāo)。

Linux中怎么安裝autofs自動(dòng)掛載服務(wù)
[root@localhost ~]# yum install autofs  Loaded plugins: langpacks, product-id, subscription-manager  
......  
Running transaction  
Installing : hesiod-3.2.1-3.el7.x86_64 1/2  
Installing : 1:autofs-5.0.7-40.el7.x86_64 2/2  
Verifying : hesiod-3.2.1-3.el7.x86_64 1/2  
Verifying : 1:autofs-5.0.7-40.el7.x86_64 2/2  
Installed:  
autofs.x86_64 1:5.0.7-40.el7  
Dependency Installed:  
hesiod.x86_64 0:3.2.1-3.el7  
Complete!

處于生產(chǎn)環(huán)境中的Linux服務(wù)器,一般會(huì)同時(shí)管理許多設(shè)備的掛載操作。如果把這些設(shè)備掛載信息都寫(xiě)入到autofs服務(wù)的主配置文件中,無(wú)疑會(huì)讓主配置文件臃腫不堪,不利于服務(wù)執(zhí)行效率,也不利于日后修改里面的配置內(nèi)容,因此在 autofs 服務(wù)程序的主配置文件中需要按照“掛載目錄 子配置文件”的格式進(jìn)行填寫(xiě)。掛載目錄是設(shè)備掛載位置的上一級(jí)目錄。

例如,光盤(pán)設(shè)備一般掛載到/media/cdrom目錄中,那么掛載目錄寫(xiě)成/media即可。對(duì)應(yīng)的子配置文件則是對(duì)這個(gè)掛載目錄內(nèi)的掛載設(shè)備信息作進(jìn)一步的說(shuō)明。子配置文件需要用戶自行定義,文件名字沒(méi)有嚴(yán)格要求,但后綴必須以.misc結(jié)束。具體的配置參數(shù)如第7行的加粗字所示。

[root@localhost ~]# vim /etc/auto.master  #  # Sample auto.master file  # This is an automounter map and it has the following format  # key [ -mount-options-separated-by-comma ] location  # For details of the format look at autofs(5).  /media /etc/iso.misc  
/misc /etc/auto.misc  #  # NOTE: mounts done from a hosts map will be mounted with the  # "nosuid" and "nodev" options unless the "suid" and "dev"  # options are explicitly given.  /net -hosts  #  # Include /etc/auto.master.d/*.autofs  +dir:/etc/auto.master.d  #  # Include central master map if it can be found using  # nsswitch sources.  #  # Note that if there are entries for /net or /misc (as  # above) in the included master map any keys that are the  # same will not be seen as the first read key seen takes  # precedence.  +auto.master

在子配置文件中,應(yīng)按照“掛載目錄 掛載文件類(lèi)型及權(quán)限 :設(shè)備名稱(chēng)”的格式進(jìn)行填寫(xiě)。例如,要把光盤(pán)設(shè)備掛載到/media/iso目錄中,可將掛載目錄寫(xiě)為iso,而-fstype為文件系統(tǒng)格式參數(shù),iso9660為光盤(pán)設(shè)備格式,ro、nosuid及nodev為光盤(pán)設(shè)備具體的權(quán)限參數(shù),/dev/cdrom則是定義要掛載的設(shè)備名稱(chēng)。配置完成后再順手將autofs服務(wù)程序啟動(dòng)并加入到系統(tǒng)啟動(dòng)項(xiàng)中:

[root@localhost ~]# vim /etc/iso.misc  iso   -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom  
[root@localhost ~]# systemctl start autofs  [root@localhost ~]# systemctl enable autofs  ln -s '/usr/lib/systemd/system/autofs.service' '/etc/systemd/system/multi-user.target.wants/autofs.service'

接下來(lái)將發(fā)生一件非常有趣的事情。我們先查看當(dāng)前的光盤(pán)設(shè)備掛載情況,確認(rèn)光盤(pán)設(shè)備沒(méi)有被掛載上,而且/media目錄中根本就沒(méi)有iso子目錄。但是,我們卻可以使用cd命令切換到這個(gè)iso子目錄中,而且光盤(pán)設(shè)備會(huì)被立即自動(dòng)掛載上。我們也就能順利查看光盤(pán)內(nèi)的內(nèi)容了。

[root@localhost ~]# df -h  Filesystem Size Used Avail Use% Mounted on  
/dev/mapper/rhel-root 18G 3.0G 15G 17% /  
devtmpfs 905M 0 905M 0% /dev  
tmpfs 914M 140K 914M 1% /dev/shm  
tmpfs 914M 8.9M 905M 1% /run  
tmpfs 914M 0 914M 0% /sys/fs/cgroup  
/dev/sda1 497M 119M 379M 24% /boot
[root@linuxprobe ~]# cd /media  [root@localhost media]# ls  [root@localhost media]# cd iso  [root@localhost iso]# ls -l  total 812  
dr-xr-xr-x. 4 root root 2048 May 7 2017 addons  
dr-xr-xr-x. 3 root root 2048 May 7 2017 EFI  
-r--r--r--. 1 root root 8266 Apr 4 2017 EULA  
-r--r--r--. 1 root root 18092 Mar 6 2012 GPL  
dr-xr-xr-x. 3 root root 2048 May 7 2017 images  
dr-xr-xr-x. 2 root root 2048 May 7 2017 isolinux
dr-xr-xr-x. 2 root root 2048 May 7 2017 LiveOS  
-r--r--r--. 1 root root 108 May 7 2017 media.repo  
dr-xr-xr-x. 2 root root 774144 May 7 2017 Packages  
dr-xr-xr-x. 24 root root 6144 May 7 2017 release-notes  
dr-xr-xr-x. 2 root root 4096 May 7 2017 repodata  
-r--r--r--. 1 root root 3375 Apr 1 2017 RPM-GPG-KEY-redhat-beta  
-r--r--r--. 1 root root 3211 Apr 1 2017 RPM-GPG-KEY-redhat-release  
-r--r--r--. 1 root root 1568 May 7 2017 TRANS.TBL  
[root@localhost ~]# df -h  Filesystem Size Used Avail Use% Mounted on  
/dev/mapper/rhel-root 18G 3.0G 15G 17% /  
devtmpfs 905M 0 905M 0% /dev  
tmpfs 914M 140K 914M 1% /dev/shm  
tmpfs 914M 8.9M 905M 1% /run  
tmpfs 914M 0 914M 0% /sys/fs/cgroup  
/dev/cdrom 3.5G 3.5G 0 100% /media/iso
/dev/sda1 497M 119M 379M 24% /boot

關(guān)于“Linux中怎么安裝autofs自動(dòng)掛載服務(wù)”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí),可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會(huì)為大家更新不同的知識(shí)點(diǎn)。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI