Linux實現(xiàn)自動掛載autofs的方法詳解
實現(xiàn)自動掛載-autofs
Autofs服務可以自動掛載外圍設備、NFS共享目錄等。,并在空空閑5分鐘后自動卸載。
相關包和文件:
包:autofs
服務文件:/usr/lib/systemd/system/autofs . service
配置文件:/etc/auto.master
Autofs工具使用簡單。
#安裝autofs工具[root@rhel82 ~]# yum install -y autofs#啟動autofs服務[root@rhel82 ~]# systemctl start autofs #autofs服務啟動后會有/misc/cd目錄,設置虛擬機連接光盤,實現(xiàn)自動掛載系統(tǒng)光盤[root@rhel82 ~]# ll /misc/總用量 0[root@rhel82 ~]# cd /misc/cd[root@rhel82 cd]# df -h文件系統(tǒng) 容量 已用 可用 已用% 掛載點devtmpfs 1.9G 0 1.9G 0% /devtmpfs 2.0G 0 2.0G 0% /dev/shmtmpfs 2.0G 10M 2.0G 1% /runtmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup/dev/nvme0n1p5 25G 4.4G 21G 18% //dev/nvme0n1p2 1014M 208M 807M 21% /boottmpfs 392M 1.2M 391M 1% /run/user/42tmpfs 392M 4.6M 387M 2% /run/user/0/dev/sr0 7.9G 7.9G 0 100% /misc/cd[root@rhel82 ~]# rpm -ql autofs[root@rhel82 ~]# rpm -qc autofsAutofs配置詳細信息
請參見幫助:man 5 autofs
自動掛載資源有兩種格式。
相對路徑安裝方法
如果掛載點路徑被分別劃分為dirname和basename,現(xiàn)有的目錄結構可能會受到影響。
# 比如掛載掛載光盤: mount /dec/sr0 /mnt/sr0 , 其中 /mnt目錄為dirname, /mnt/sr0為basename 等價于 /mnt/sr0 = /dirname/basenameAutofs主配置文件/etc/atuo.master格式
掛載的dirname
指定了目錄的配置文件路徑,比如:/etc/test.auto。指定子配置文件格式/etc/test.auto。
掛載的basename
掛載選項注意:autofs配置的dirname目錄和basename目錄不需要手動創(chuàng)建,已經(jīng)有掛載點的dirname目錄下的原始數(shù)據(jù)會被覆蓋。
Autof提供了一個默認掛載CD的例子。
[root@centos8 ~ ]# cat /etc/auto.master/misc /etc/auto.misc[root@centos8 ~ ]# cat /etc/auto.misccd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom#特殊寫法: 掛載點dataname和掛載目錄dataname相同,即: mount 10.0.0.18:/data/www /misc/www* -fstype=nfg 10.0.0.18:/data/&示例:使用autofs自動掛載nfs
#服務端和客戶端安裝nfs-utils工具包[root@server ~]# yum install -y nfs-utils[root@client ~]# yum install -y nfs-utils[root@server ~]# mkdir /nfs[root@server ~]# cp /etc/passwd /nfs/#centos6系統(tǒng)nfs服務叫做nfs.service#centos7系統(tǒng)上nfs.service 和 nfs-server.service同一個服務#centos8只有nfs-server.service服務[root@server ~]# systemctl start nfs#centos7系統(tǒng)可以解決服務之間依賴關系,并且nfs服務啟動會自動啟動rpcbind.service[root@server ~]# systemctl status rpcbind[root@server ~]# vim /etc/exports/nfs *(rw)[root@server ~]# exportfs -r[root@server ~]# exportfs -v/nfs <world>(sync,wdelay,hide,no_subtree_check,sec=sys,rw,root_squash,no_all_squash)[root@server ~]# systemctl restart nfs[root@server ~]# showmount -e 192.168.192.128Export list for 192.168.192.128:/nfs *[root@client ~]# showmount -e 192.168.192.128Export list for 192.168.192.128:/nfs *[root@client ~]# mkdir /opt/nfs[root@client ~]# mount 192.168.192.128:/nfs /opt/nfs/[root@client ~]# df -h | grep nfs192.168.192.128:/nfs 62G 1.7G 61G 3% /opt/nfs#編寫autofs主配置文件[root@client ~]# vim /etc/auto.master/opt /etc/auto.master.d/auto.nfs#編寫子配置文件[root@client ~]# vim /etc/auto.master.d/auto.nfsnfs -fstype=nfs 192.168.192.128:/nfs#掛載點/dirname是/目錄,查看autofs配置未生效,/目錄數(shù)據(jù)[root@client ~]# cp /root/anaconda-ks.cfg /opt/[root@client ~]# ll /opt/總用量 4-rw-------. 1 root root 1453 12月 5 04:03 anaconda-ks.cfg#如果修改主配置文件需要重啟服務[root@client ~]# systemctl restart autofs#一旦重啟atuofs服務,掛載dirname目錄屬于autofs服務管理,源數(shù)據(jù)不存在[root@centos8 ~ ]# ll /opt/total 0#cd進入指定掛載點,autofs就會自動掛載[root@client ~]# ls /opt/[root@client ~]# cd /opt/nfs[root@client nfs]# lspasswd[root@client nfs]# df -h | grep nfs192.168.192.128:/nfs 62G 1.7G 61G 3% /opt/nfs絕對路徑安裝方法
所有絕對路徑名直接匹配并寫入指定的配置文件,不會影響本地目錄結構。
Autofs主配置文件/etc/atuo.master格式
/-
指定目錄的配置文件路徑(使用/-表示使用絕對目錄)指定子配置文件格式/etc/test.auto。
掛載絕對路徑
掛載選項 選項設備模型
[root@client ~]# vim /etc/auto.master/- /etc/auto.master.d/auto.nfs[root@client ~]# vim /etc/auto.master.d/auto.nfs/opt/nfs -fstype=nfs 192.168.192.128:/nfs#autofs服務使用絕對路徑自動掛載,不會覆蓋原數(shù)據(jù)[root@client ~]# systemctl start autofs[root@client ~]# ll /opt/總用量 4-rw-------. 1 root root 1453 12月 5 04:03 anaconda-ks.cfgdrwxr-xr-x. 2 root root 20 12月 4 19:39 nfs[root@client ~]# cd /opt/nfs/[root@client nfs]# lspasswd優(yōu)化 Linux 系統(tǒng)性能
使用tuned-adm命令優(yōu)化Linux系統(tǒng)性能。作為一名系統(tǒng)管理員,我可以通過調(diào)整各種設置來優(yōu)化Linux系統(tǒng)的性能,以適應當前的用例工作負載,并幫助優(yōu)化Linux的性能。
可以調(diào)整的可用配置文件:
balanced:非常適合在節(jié)能和性能之間尋求折衷的系統(tǒng)。desktop:源自平衡配置文件,提供交互式應用程序的更快響應。throughput-performance:調(diào)整系統(tǒng)以獲得最大吞吐量。latency-performance:對于要求低延遲,以功耗為代價的服務器系統(tǒng)的理想選擇。network-latency:源自延遲性能配置文件,它啟用其他網(wǎng)絡調(diào)整參數(shù)以提供較低的網(wǎng)絡延遲。network-throughput:從吞吐量性能概要文件得出,附加的網(wǎng)絡調(diào)整參數(shù)適用于最大的網(wǎng)絡吞吐量。powersave:調(diào)整系統(tǒng)以最大程度地節(jié)省電力。oracle:基于吞吐量性能概要文件針對Oracle數(shù)據(jù)庫負載進行了優(yōu)化。virtual-guest:優(yōu)化以在虛擬訪客中運行。virtual-host:如果用于運行KVM guest虛擬機,請調(diào)整系統(tǒng)以獲得最佳性能。安裝調(diào)整
[root@rhel82 ~]# yum install tuned -y[root@rhel82 ~]# systemctl status tuned選擇調(diào)整配置文件。
調(diào)整后的配置文件包括性能改進配置文件,其中包括側重于存儲和網(wǎng)絡的低延遲和高吞吐量、虛擬主機性能和虛擬機性能的配置文件。
我們將使用tuned-adm命令來更改調(diào)整后的守護程序的設置。
檢查當前活動的調(diào)整配置文件:
[root@rhel82 ~]# tuned-adm activeCurrent active profile: virtual-guest可以使用更多配置文件,如下所示:
[root@rhel82 ~]# tuned-adm listAvailable profiles:- accelerator-performance - Throughput performance based tuning with disabled higher latency STOP states- balanced - General non-specialized tuned profile- desktop - Optimize for the desktop use-case- hpc-compute - Optimize for HPC compute workloads- intel-sst - Configure for Intel Speed Select Base Frequency- latency-performance - Optimize for deterministic performance at the cost of increased power consumption- network-latency - Optimize for deterministic performance at the cost of increased power consumption, focused on low latency network performance- network-throughput - Optimize for streaming network throughput, generally only necessary on older CPUs or 40G+ networks- optimize-serial-console - Optimize for serial console use.- powersave - Optimize for low power consumption- throughput-performance - Broadly applicable tuning that provides excellent performance across a variety of common server workloads- virtual-guest - Optimize for running inside a virtual guest- virtual-host - Optimize for running KVM guestsCurrent active profile: virtual-guestTuned-adm profile命令用于將活動配置文件切換到其他配置文件。此示例將調(diào)整我們的系統(tǒng)以實現(xiàn)最大吞吐量:
[root@rhel82 ~]# tuned-adm profile throughput-performance確認當前配置文件:
[root@rhel82 ~]# tuned-adm activeCurrent active profile: throughput-performance檢查系統(tǒng)推薦的調(diào)整配置文件
tuned-adm命令還可以建議系統(tǒng)的調(diào)整配置文件,該文件基于各種系統(tǒng)特征,包括系統(tǒng)是否為虛擬機以及在系統(tǒng)安裝期間選擇的其他預定義類別:
[root@rhel82 ~]# tuned-adm recommendvirtual-guest然后,您可以將配置文件設置為推薦值:
[root@rhel82 ~]# tuned-adm profile virtual-guest要查看配置文件的詳細信息,請運行:
[root@rhel82 ~]# tuned-adm profile_info virtual-guestProfile name:virtual-guestProfile summary:Optimize for running inside a virtual guestProfile description:關閉調(diào)諧的調(diào)整活動:
[root@rhel82 ~]# tuned-adm off[root@rhel82 ~]# tuned-adm activeNo current active profile.關于Linux安裝autofs的詳細方法,本文就講到這里。關于Linux安裝autofs的更多信息,請搜索Script House以前的文章或繼續(xù)瀏覽下面的相關文章。希望大家以后多多支持劇本之家!
如果您的問題還未解決可以聯(lián)系站長付費協(xié)助。

有問題可以加入技術QQ群一起交流學習
本站vip會員 請加入無憂模板網(wǎng) VIP群(50604020) PS:加入時備注用戶名或昵稱
普通注冊會員或訪客 請加入無憂模板網(wǎng) 技術交流群(50604130)
客服微信號:15898888535
聲明:本站所有文章資源內(nèi)容,如無特殊說明或標注,均為采集網(wǎng)絡資源。如若內(nèi)容侵犯了原著者的合法權益,可聯(lián)系站長刪除。