網站首頁 編程語言 正文
無論是Samba服務還是NFS服務,都要把掛載信息寫入到/etc/fstab中,這樣遠程共享資源就會自動隨服務器開機而進行掛載。雖然這很方便,但是如果掛載的遠程資源太多,則會給網絡帶寬和服務器的硬件資源帶來很大負載。如果在資源掛
載后長期不使用,也會造成服務器硬件資源的浪費。
可能會有讀者說,可以在每次使用之前執行mount命令進行手動掛載。這是一個不錯的選擇,但是每次都需要先掛載再使用,您不覺得麻煩嗎?
autofs自動掛載服務可以幫我們解決這一問題。與mount命令不同,autofs服務程序是一種Linux系統守護進程,當檢測到用戶試圖訪問一個尚未掛載的文件系統時,將自動掛載該文件系統。
換句話說,我們將掛載信息填入/etc/fstab文件后,系統在每次開機時都自動將其掛載,而autofs服務程序則是在用戶需要使用該文件系統時才去動態掛載,從而節約了網絡資源和服務器的硬件資源。
[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!
處于生產環境中的Linux服務器,一般會同時管理許多設備的掛載操作。如果把這些設備掛載信息都寫入到autofs服務的主配置文件中,無疑會讓主配置文件臃腫不堪,不利于服務執行效率,也不利于日后修改里面的配置內容,因此在 autofs
服務程序的主配置文件中需要按照“掛載目錄 子配置文件”的格式進行填寫。掛載目錄是設備掛載位置的上一級目錄。
例如,光盤設備一般掛載到/media/cdrom目錄中,那么掛載目錄寫成/media即可。對應的子配置文件則是對這個掛載目錄內的掛載設備信息作進一步的說明。子配置文件需要用戶自行定義,文件名字沒有嚴格要求,但后綴必須以.misc結束。
具體的配置參數如第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
在子配置文件中,應按照“掛載目錄 掛載文件類型及權限 :設備名稱”的格式進行填寫。例如,要把光盤設備掛載到/media/iso目錄中,可將掛載目錄寫為iso,而-fstype為文件系統格式參數,iso9660為光盤設備格式,ro、nosuid及nodev為光盤
設備具體的權限參數,/dev/cdrom則是定義要掛載的設備名稱。配置完成后再順手將autofs服務程序啟動并加入到系統啟動項中:
[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'
接下來將發生一件非常有趣的事情。我們先查看當前的光盤設備掛載情況,確認光盤設備沒有被掛載上,而且/media目錄中根本就沒有iso子目錄。
但是,我們卻可以使用cd命令切換到這個iso子目錄中,而且光盤設備會被立即自動掛載上。我們也就能順利查看光盤內的內容了。
[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
原文鏈接:https://blog.51cto.com/u_15103042/2651399
相關推薦
- 2023-01-14 詳解Go語言如何進行Http調用_Golang
- 2022-06-29 Oracle中PL/SQL的塊與表達式_oracle
- 2023-03-29 詳解C++中菱形繼承的原理與解決方法_C 語言
- 2023-04-03 Python數據結構棧實現進制轉換簡單示例_python
- 2024-01-27 Apache POI 及 alibaba EasyExcel使用
- 2022-07-07 Python數據分析之?Matplotlib?3D圖詳情_python
- 2022-08-15 創建型設計模式之建造者模式
- 2022-05-25 從零搭建開發腳手架 SpringBoot自定義配置的多種姿勢及Idea自動提示
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支