時間:2022-10-11來源:系統城裝機大師作者:佚名
autofs 服務實現自動掛載外圍設備,NFS共享目錄等,并在空閑5分鐘后后自動卸載
相關包和文件 :
軟件包:autofs
服務文件:/usr/lib/systemd/system/autofs.service
配置文件:/etc/auto.master
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#安裝autofs工具 [root@rhel82 ~] # yum install -y autofs #啟動autofs服務 [root@rhel82 ~] # systemctl start autofs #autofs服務啟動后會有/misc/cd目錄,設置虛擬機連接光盤,實現自動掛載系統光盤 [root@rhel82 ~] # ll /misc/ 總用量 0 [root@rhel82 ~] # cd /misc/cd [root@rhel82 cd ] # df -h 文件系統 容量 已用 可用 已用% 掛載點 devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs 2.0G 10M 2.0G 1% /run tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup /dev/nvme0n1p5 25G 4.4G 21G 18% / /dev/nvme0n1p2 1014M 208M 807M 21% /boot tmpfs 392M 1.2M 391M 1% /run/user/42 tmpfs 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 autofs |
參看幫助:man 5 autofs
相對路徑掛載法
將mount point 掛載點路徑分成 dirname 和 basename 分別配置,可能會影響現有的目錄結構
1 | # 比如掛載掛載光盤: mount /dec/sr0 /mnt/sr0 , 其中 /mnt目錄為dirname, /mnt/sr0為basename 等價于 /mnt/sr0 = /dirname/basename |
autofs主配置文件/etc/atuo.master格式
掛載點的dirname 指定目錄的配置文件路徑,如:/etc/test.auto
指定子配置文件格式/etc/test.auto
掛載點的basename 掛載選項 選項設備
注意:autofs配置的dirname目錄和basename目錄不需要手動創建,會覆蓋已存在掛載點的dirname目錄下原數據
autof默認提供掛載光盤范例
1 2 3 4 5 6 7 8 |
[root@centos8 ~ ] # cat /etc/auto.master /misc /etc/auto .misc [root@centos8 ~ ] # cat /etc/auto.misc cd -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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
#服務端和客戶端安裝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系統nfs服務叫做nfs.service #centos7系統上nfs.service 和 nfs-server.service同一個服務 #centos8只有nfs-server.service服務 [root@server ~] # systemctl start nfs #centos7系統可以解決服務之間依賴關系,并且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.128 Export list for 192.168.192.128: /nfs * [root@client ~] # showmount -e 192.168.192.128 Export 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 nfs 192.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.nfs nfs -fstype=nfs 192.168.192.128: /nfs #掛載點/dirname是/目錄,查看autofs配置未生效,/目錄數據 [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服務管理,源數據不存在 [root@centos8 ~ ] # ll /opt/ total 0 #cd進入指定掛載點,autofs就會自動掛載 [root@client ~] # ls /opt/ [root@client ~] # cd /opt/nfs [root@client nfs] # ls passwd [root@client nfs] # df -h | grep nfs 192.168.192.128: /nfs 62G 1.7G 61G 3% /opt/nfs |
絕對路徑掛載法
直接匹配全部的絕對路徑名稱,都寫入到指定的配置文件里,不會影響本地目錄結構
autofs主配置文件/etc/atuo.master格式
/- 指定目錄的配置文件路徑(使用 /- 表示使用絕對目錄)
指定子配置文件格式/etc/test.auto
掛載點絕對路徑 掛載選項 選項設備
范例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[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服務使用絕對路徑自動掛載,不會覆蓋原數據 [root@client ~] # systemctl start autofs [root@client ~] # ll /opt/ 總用量 4 -rw-------. 1 root root 1453 12月 5 04:03 anaconda-ks.cfg drwxr-xr-x. 2 root root 20 12月 4 19:39 nfs [root@client ~] # cd /opt/nfs/ [root@client nfs] # ls passwd |
使用tuned-adm命令優化Linux系統性能。作為系統管理員,能夠通過調整各種設置來優化Linux系統的性能,以適合當前用例工作負載,幫助優化Linux的性能。
可以調整到的可用配置文件:
1 2 3 |
[root@rhel82 ~] # yum install tuned -y [root@rhel82 ~] # systemctl status tuned |
調整的配置文件包含性能提升配置文件,性能提升配置文件包括側重于:存儲和網絡的低延遲、高吞吐量的存儲和網絡、虛擬主機性能、虛擬機性能的配置文件。
我們將使用tuned-adm命令來更改已調整守護程序的設置。
檢查當前活動的調優配置文件:
1 2 |
[root@rhel82 ~] # tuned-adm active Current active profile: virtual-guest |
可以使用更多配置文件,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[root@rhel82 ~] # tuned-adm list Available 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 guests Current active profile: virtual-guest |
tuned-adm配置文件命令用于將活動配置文件切換到其他配置文件,此示例將調整我們的系統以實現最大吞吐量:
1 | [root@rhel82 ~] # tuned-adm profile throughput-performance |
確認當前配置文件:
1 2 |
[root@rhel82 ~] # tuned-adm active Current active profile: throughput-performance |
tuned-adm命令還可以建議系統的調整配置文件,這基于各種系統特征,包括系統是否為虛擬機以及在系統安裝期間選擇的其他預定義類別:
1 2 |
[root@rhel82 ~] # tuned-adm recommend virtual-guest |
然后,可以將個人資料設置為推薦值:
1 | [root@rhel82 ~] # tuned-adm profile virtual-guest |
查看配置文件詳細信息,請運行:
1 2 3 4 5 6 7 8 |
[root@rhel82 ~] # tuned-adm profile_info virtual-guest Profile name: virtual-guest Profile summary: Optimize for running inside a virtual guest Profile description: |
關閉已調優的調整活動:
1 2 3 4 |
[root@rhel82 ~] # tuned-adm off [root@rhel82 ~] # tuned-adm active No current active profile. |
到此這篇關于Linux實現自動掛載autofs的方法詳解的文章就介紹到這了
2022-10-02
Elasticsearch6.2服務器升配后的bug(避坑指南)2022-10-02
aarch64服務器部署mysql的流程分析2022-10-02
解決Navicat 連接服務器不成功的問題1、安裝python 2、安裝PaddlePaddle CPU 版本 3、安裝 paddlehub 4、從github下載 PaddleOCR 5、下載推理模型庫 6、修改模型配置文件 7、啟動 ocr_system 服務 8、測試 ocr_system 服務...
2022-09-21