autofs自动挂载服务

大部分情况下,我们都需要将挂载信息写入到/etc/fstab文件中,使其能随机器开机时自动挂载。

但是对于像Samba、NFS等远程资源,建议还是使用autofs自动挂载服务,因为如果挂载的远程资源太多,则会给网络带宽和服务器的硬件资源带来很大负载。

与mount命令不同,autofs服务程序是一种Linux系统守护进程,当检测到用户试图访问一个尚未挂载的文件系统时,将自动挂载该文件系统。换句话说,将挂载信息填入/etc/fstab文件后,系统在每次开机时都自动将其挂载,而autofs服务程序则是在用户需要使用该文件系统时才去动态挂载,从而节约了网络资源和服务器的硬件资源。

安装autofs服务程序:

1
[root@wu ~]# dnf install autofs

 /etc/auto.master是antofs的主配置文件,在autofs服务程序的主配置文件中需要按照“挂载目录 子配置文件”的格式进行填写,挂载目录是设备挂载位置的上一级目录。

在子配置文件中,应按照“挂载目录 挂载文件类型及权限 :设备名称”的格式进行填写。

示例1:

将远程主机172.25.250.10的NFS文件系统/rhome/file1挂载到本地/haha/hehe目录下

主配置文件

1
2
3
4
5
6
7
8
9
10
[rootwu ~]# vim /etc/auto.master
#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
<strong>/haha  /etc/ceshi.misc   #/haha是本地挂载路径,/etc/ceshi.misc是子配置文件(子配置文件名称需要以.misc结尾)</strong>
/misc   /etc/auto.misc   #参考文件,默认存在
#

子配置文件

1
2
[rootwu ~]# vim /etc/ceshi.misc
<strong>hehe  -fstype=nfs,rw  172.25.250.10:/rhome/file1</strong> <strong> #-fstype指定文件系统的类型,rw定义文件的权限,172.25.250.10:/rhome/file1是待挂载的文件设备</strong>

重启服务

1
2
[root@wu ~]# systemctl start autofs
[root@wu ~]# systemctl enable autofs

使用

1
[root@wu ~]#cd /haha/hehe  #当切换到hehe目录中的时候,会将设备信息自动挂载

示例2:

将光盘设备/dev/cdrom挂载到/media/cdrom目录中。

主配置文件

1
2
3
4
5
6
7
8
9
10
11
[rootwu ~]# vim /etc/auto.master
#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
<strong>/media  /etc/iso.misc</strong>
/haha   /etc/ceshi.misc  
/misc   /etc/auto.misc   #参考文件,默认存在
#

子配置文件

1
2
3
[rootwu ~]# vim /etc/<strong>iso.misc</strong>
<strong>cdrom   -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
</strong>

重启服务

1
2
[root@wu ~]# systemctl start autofs
[root@wu ~]# systemctl enable autofs

  

 

  

  

 

posted @   小蟋帅  阅读(1726)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示