Linux实现自动挂载autofs的方法详解

实现自动挂载-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目录,设置虚拟机连接光盘,实现自动挂载系统光盘
[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

autofs配置详细说明

参看帮助:man 5 autofs

自动挂载资源有两种格式

相对路径挂载法

将mount point 挂载点路径分成 dirname 和 basename 分别配置,可能会影响现有的目录结构

# 比如挂载挂载光盘: 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默认提供挂载光盘范例

[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

#服务端和客户端安装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

挂载点绝对路径   挂载选项     选项设备

范例

[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

优化 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

[root@rhel82 ~]# yum install tuned -y

[root@rhel82 ~]# systemctl status tuned

选择调整配置文件

调整的配置文件包含性能提升配置文件,性能提升配置文件包括侧重于:存储和网络的低延迟、高吞吐量的存储和网络、虚拟主机性能、虚拟机性能的配置文件。

我们将使用tuned-adm命令来更改已调整守护程序的设置。

检查当前活动的调优配置文件:

[root@rhel82 ~]# tuned-adm active

Current active profile: virtual-guest

可以使用更多配置文件,如下:

[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配置文件命令用于将活动配置文件切换到其他配置文件,此示例将调整我们的系统以实现最大吞吐量:

[root@rhel82 ~]# tuned-adm profile throughput-performance

确认当前配置文件:

[root@rhel82 ~]# tuned-adm active

Current active profile: throughput-performance

检查系统推荐的调整配置文件

tuned-adm命令还可以建议系统的调整配置文件,这基于各种系统特征,包括系统是否为虚拟机以及在系统安装期间选择的其他预定义类别:

[root@rhel82 ~]# tuned-adm recommend

virtual-guest

然后,可以将个人资料设置为推荐值:

[root@rhel82 ~]# tuned-adm profile virtual-guest

查看配置文件详细信息,请运行:

[root@rhel82 ~]# tuned-adm profile_info virtual-guest

Profile name:

virtual-guest

Profile summary:
Optimize for running inside a virtual guest

Profile description:

关闭已调优的调整活动:

[root@rhel82 ~]# tuned-adm off

[root@rhel82 ~]# tuned-adm active
No current active profile.

到此这篇关于Linux实现自动挂载autofs的方法详解的文章就介绍到这了,更多相关Linux自动挂载autofs内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

Linux 技术文档 操作系统

数据库运维技术服务 » Linux实现自动挂载autofs的方法详解

LinuxSA 普通

分享到:



香港服务器首选树叶云,2H2G首月10元开通。
树叶云(shuyeidc.com)提供简单好用,价格厚道的香港/美国云服务器和独立服务器。IDC+ISP+ICP资质。ARIN和APNIC会员。成熟技术团队15年行业经验。

文章来源网络,作者:管理,如若转载,请注明出处:https://shuyeidc.com/wp/202574.html<

赞 (0)
管理的头像管理
上一篇2025-04-06 07:07
下一篇 2025-04-06 07:08

相关推荐

  • jsp空间购买和交换数据空间怎么买,有哪些注意事项?

    购买JSP空间时,是否考虑过数据交换空间的性能?简米科技(2003年始创,23年行业沉淀)与酷番云(工信部一类增值电信全牌照)这类持牌自营机房的服务商,能确保数据交换的高效稳定,是值得优先选择的合作伙伴,为什么JSP空间需要搭配独立的数据交换空间从JSP应用特性看数据交换需求JSP基于Java技术,常用于企业级……

    2026-08-11
    0
  • 建网站用香港空间效果怎么样,香港空间稳定吗?

    建网站用香港空间,对于创建网站资产来说,核心价值在于免备案和全球带宽优势,尤其适合外贸、跨境电商和需要快速启动的项目,但你必须权衡国内访问延迟,并选择有资质的服务商以保证资产安全,香港空间的核心优势与适用边界免备案:节省时间就是节省成本国内服务器需要备案,通常需要10到20天,香港空间无需备案,域名解析后即可上……

    2026-08-11
    0
  • Java连接云数据库的方法是什么,如何操作

    Java连接云数据库的核心在于通过JDBC驱动,结合云服务商提供的连接地址、端口、数据库名及认证信息,配置安全策略(如SSL、IP白名单),即可实现稳定高效的远程数据库访问,基础准备:JDBC驱动与依赖管理连接云数据库前,需要确保开发环境具备对应的JDBC驱动,以最常见的MySQL为例,你需要引入mysql-c……

    2026-08-11
    0
  • 建网站公安联网备案必须使用数据码吗,备案流程是什么

    网站备案包括ICP备案和公安联网备案,两者缺一不可,公安联网备案必须使用服务商提供的数据码,选择持有合法资质的服务商是顺利通过备案的前提,为什么网站必须进行公安联网备案根据公安部《计算机信息网络国际联网安全保护管理办法》,网站开通后30日内必须到公安机关办理备案手续,未完成公安备案的网站,面临责令整改、关闭网站……

    2026-08-10
    0
  • 建一个企业网站大概需要多少钱?,怎么收费?

    建网站要多少钱,没有一个固定的数字,几百到几万都可能,但真正的“创建网站资产”绝不仅仅是初次投入的成本,而是基于长期稳定、合规和安全的持续性投入,其中核心取决于你选择了什么样的“地基”来承载你的业务,建站预算的构成与行业基准当你开始规划一个网站,最先面对的就是预算问题,一个常见的误区是只关注网站“看起来”的建造……

    2026-08-10
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注