Linuxautofs自动挂载详解与实现攻略
时间:2025-05-06 22:13:03 159浏览 收藏
Linux自动挂载autofs详解及实现方法:autofs服务可以实现对外部设备和NFS共享目录的自动挂载,并在空闲5分钟后自动卸载。本文详细介绍了autofs的安装、配置和使用方法,包括如何通过autofs实现光盘和NFS共享的自动挂载。此外,还介绍了如何使用tuned工具优化Linux系统性能,提供了多种调整配置文件的选择和应用方法,帮助系统管理员根据具体需求提升系统性能。
目录
实现自动挂载-autofs
autofs工具简单使用
autofs配置详细说明
自动挂载资源有两种格式
优化Linux系统性能
安装Tuned
选择调整配置文件
检查系统推荐的调整配置文件
实现自动挂载-autofs
autofs服务可以实现对外部设备、NFS共享目录等的自动挂载,并在空闲5分钟后自动卸载。
相关包和文件:
软件包:autofs
服务文件:/usr/lib/systemd/system/autofs.service
配置文件:/etc/auto.master
autofs工具简单使用
<code>#安装autofs工具 [root@rhel82 ~]# yum install -y autofs <h1>启动autofs服务</h1><p>[root@rhel82 ~]# systemctl start autofs</p><h1>autofs服务启动后会生成/misc/cd目录,设置虚拟机连接光盘,实现自动挂载系统光盘</h1><p>[root@rhel82 ~]# ll /misc/ 总用量 0</p><p>[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</p><p>[root@rhel82 ~]# rpm -ql autofs [root@rhel82 ~]# rpm -qc autofs </p></code>
autofs配置详细说明
查看帮助:man 5 autofs
自动挂载资源有两种格式
相对路径挂载法
将mount point挂载点路径分为dirname和basename分别配置,可能会影响现有的目录结构
<code># 例如挂载光盘: mount /dev/sr0 /mnt/sr0,其中/mnt目录为dirname,/mnt/sr0为basename,相当于/mnt/sr0 = /dirname/basename </code>
autofs主配置文件/etc/auto.master格式
挂载点的dirname指定目录的配置文件路径,如:/etc/test.auto
指定子配置文件格式/etc/test.auto
挂载点的basename挂载选项选项设备
注意:autofs配置的dirname目录和basename目录不需要手动创建,会覆盖已存在挂载点的dirname目录下原数据
autofs默认提供挂载光盘范例
<code>[root@Centos8 ~]# cat /etc/auto.master /misc /etc/auto.misc<p>[root@centos8 ~]# cat /etc/auto.misc cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom</p><h1>特殊写法:挂载点dataname和挂载目录dataname相同,即:mount 10.0.0.18:/data/www /misc/www</h1><ul><li>-fstype=nfs 10.0.0.18:/data/& </li></ul></code>
范例:利用autofs自动挂载NFS
<code>#服务端和客户端安装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/<h1>centos6系统nfs服务叫做nfs.service</h1><h1>centos7系统上nfs.service和nfs-server.service同一个服务</h1><h1>centos8只有nfs-server.service服务</h1><p>[root@server ~]# systemctl start nfs</p><h1>centos7系统可以解决服务之间依赖关系,并且nfs服务启动会自动启动rpcbind.service</h1><p>[root@server ~]# systemctl status rpcbind</p><p>[root@server ~]# vim /etc/exports /nfs *(rw)</p><p>[root@server ~]# exportfs -r [root@server ~]# exportfs -v /nfs <world>(sync,wdelay,hide,no_subtree_check,sec=sys,rw,root_squash,no_all_squash)</p><p>[root@server ~]# systemctl restart nfs [root@server ~]# showmount -e 192.168.192.128 Export list for 192.168.192.128: /nfs *</p><p>[root@client ~]# showmount -e 192.168.192.128 Export list for 192.168.192.128: /nfs *</p><p>[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</p><h1>编写autofs主配置文件</h1><p>[root@client ~]# vim /etc/auto.master /opt /etc/auto.master.d/auto.nfs</p><h1>编写子配置文件</h1><p>[root@client ~]# vim /etc/auto.master.d/auto.nfs nfs -fstype=nfs 192.168.192.128:/nfs</p><h1>挂载点/dirname是/目录,查看autofs配置未生效,/目录数据</h1><p>[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</p><h1>如果修改主配置文件需要重启服务</h1><p>[root@client ~]# systemctl restart autofs</p><h1>一旦重启autofs服务,挂载dirname目录属于autofs服务管理,源数据不存在</h1><p>[root@centos8 ~]# ll /opt/ total 0</p><h1>cd进入指定挂载点,autofs就会自动挂载</h1><p>[root@client ~]# ls /opt/ [root@client ~]# cd /opt/nfs [root@client nfs]# ls passwd</p><p>[root@client nfs]# df -h | grep nfs 192.168.192.128:/nfs 62G 1.7G 61G 3% /opt/nfs </world></p></code>
绝对路径挂载法
直接匹配全部的绝对路径名称,都写入到指定的配置文件里,不会影响本地目录结构
autofs主配置文件/etc/auto.master格式
/- 指定目录的配置文件路径(使用/-表示使用绝对目录)
指定子配置文件格式/etc/test.auto
挂载点绝对路径挂载选项选项设备
范例
<code>[root@client ~]# vim /etc/auto.master /- /etc/auto.master.d/auto.nfs<p>[root@client ~]# vim /etc/auto.master.d/auto.nfs /opt/nfs -fstype=nfs 192.168.192.128:/nfs</p><h1>autofs服务使用绝对路径自动挂载,不会覆盖原数据</h1><p>[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</p><p>[root@client ~]# cd /opt/nfs/ [root@client nfs]# ls passwd </p></code>
优化Linux系统性能
使用tuned-adm命令优化Linux系统性能。作为系统管理员,可以通过调整各种设置来优化Linux系统的性能,以适应当前用例的工作负载,帮助提升Linux的性能。
可以调整的可用配置文件:
- balanced:非常适合在节能和性能之间寻求折衷的系统。
- desktop:源自平衡配置文件,提供交互式应用程序的更快响应。
- throughput-performance:调整系统以获得最大吞吐量。
- latency-performance:对于要求低延迟,以功耗为代价的服务器系统的理想选择。
- network-latency:源自延迟性能配置文件,它启用其他网络调整参数以提供较低的网络延迟。
- network-throughput:从吞吐量性能概要文件得出,附加的网络调整参数适用于最大的网络吞吐量。
- powersave:调整系统以最大程度地节省电力。
- oracle:基于吞吐量性能概要文件针对Oracle数据库负载进行了优化。
- virtual-guest:优化以在虚拟访客中运行。
- virtual-host:如果用于运行KVM guest虚拟机,请调整系统以获得最佳性能。
安装Tuned
<code>[root@rhel82 ~]# yum install tuned -y<p>[root@rhel82 ~]# systemctl status tuned </p></code>
选择调整配置文件
调整的配置文件包含性能提升配置文件,性能提升配置文件包括侧重于:存储和网络的低延迟、高吞吐量的存储和网络、虚拟主机性能、虚拟机性能的配置文件。
我们将使用tuned-adm命令来选择和应用这些配置文件。
检查当前活动的调优配置文件:
<code>[root@rhel82 ~]# tuned-adm active Current active profile: virtual-guest </code>
可以使用更多配置文件,如下:
<code>[root@rhel82 ~]# tuned-adm list Available profiles:<ul><li>accelerator-performance - Throughput performance based tuning with disabled higher latency STOP states</li><li>balanced - General non-specialized tuned profile</li><li>desktop - Optimize for the desktop use-case</li><li>hpc-compute - Optimize for HPC compute workloads</li><li>intel-sst - Configure for Intel Speed Select Base Frequency</li><li>latency-performance - Optimize for deterministic performance at the cost of increased power consumption</li><li>network-latency - Optimize for deterministic performance at the cost of increased power consumption, focused on low latency network performance</li><li>network-throughput - Optimize for streaming network throughput, generally only necessary on older CPUs or 40G+ networks</li><li>optimize-serial-console - Optimize for serial console use.</li><li>powersave - Optimize for low power consumption</li><li>throughput-performance - Broadly applicable tuning that provides excellent performance across a variety of common server workloads</li><li>virtual-guest - Optimize for running inside a virtual guest</li><li>virtual-host - Optimize for running KVM guests Current active profile: virtual-guest</li></ul></code>
tuned-adm配置文件命令用于将活动配置文件切换到其他配置文件,此示例将调整我们的系统以实现最大吞吐量:
<code>[root@rhel82 ~]# tuned-adm profile throughput-performance </code>
确认当前配置文件:
<code>[root@rhel82 ~]# tuned-adm active Current active profile: throughput-performance </code>
检查系统推荐的调整配置文件
tuned-adm命令还可以建议系统的调整配置文件,这基于各种系统特征,包括系统是否为虚拟机以及在系统安装期间选择的其他预定义类别:
<code>[root@rhel82 ~]# tuned-adm recommend virtual-guest </code>
然后,可以将个人资料设置为推荐值:
<code>[root@rhel82 ~]# tuned-adm profile virtual-guest </code>
查看配置文件详细信息,请运行:
<code>[root@rhel82 ~]# tuned-adm profile_info virtual-guest Profile name: virtual-guest<p>Profile summary: Optimize for running inside a virtual guest</p><p>Profile description: </p></code>
关闭已调优的调整活动:
<code>[root@rhel82 ~]# tuned-adm off<p>[root@rhel82 ~]# tuned-adm active No current active profile. </p></code>
好了,本文到此结束,带大家了解了《Linuxautofs自动挂载详解与实现攻略》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多科技周边知识!
-
501 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
221 收藏
-
293 收藏
-
139 收藏
-
281 收藏
-
467 收藏
-
194 收藏
-
472 收藏
-
413 收藏
-
210 收藏
-
462 收藏
-
386 收藏
-
435 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 543次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 515次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 499次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习