linux之autofs自动挂载

我们在linux中常用的挂载方式有两种,一个是直接手动挂载mount,另一个是通过添加挂载信息到/etc/fstab配置文件中,前者只是临时挂载,重起机器后就会挂载失效,后者则会永久挂载,那么有没有一种我需要用时自动挂载上,等一段时间不用时又自动卸载的挂载方式呢,很高兴确实有,那就是今天要说的autofs自动挂载。

那么如何使用呢,步骤如下:

1、先安装autofs软件:yum -y install autofs

2、通过rpm -qc autofs来看它的相关配置文件,我们会发现里面有/etc/auto.master和/etc/sysconfig/autofs等配置文件

[root@server0 ~]# rpm -qc autofs
/etc/auto.master--------声明autofs挂载目录和挂载策略的配置文件
/etc/auto.misc
/etc/auto.net
/etc/auto.smb
/etc/autofs_ldap_auth.conf
/etc/sysconfig/autofs-------autofs系统配置文件
/usr/lib/systemd/system/autofs.service

注意:根据版本不同,有的版本里没有/etc/sysconfig/autofs文件而是用/etc/autofs.conf来做autofs系统配置文件

3、配置/etc/auto.master文件: vim /etc/auto.master
/home/guests     /etc/auto.guests --------    手动添加的

/home/guests------声明的挂载父目录     /etc/auto.guests--------声明的挂载策略文件名
/misc   /etc/auto.misc--------系统自带模版

4、配置挂载策略文件: vim /etc/auto.guests

ldapuser0        -rw           classroom.example.com:/home/guests/ldapuser0

classroom.example.com:/home/guests/ldapuser0--------此处是被挂载设备的设备路径

扫描二维码关注公众号,回复: 2292979 查看本文章

此处的ldapuser0是指/home/guests/ldapuser0,这就是真正的挂载点,并且也是监控点,一旦以后操作到/home/guests/ldapuser0该目录,autofs就会自动挂载。那么它会挂载多久呢,就要看   vim /etc/sysconfig/autofs 看是如何配置的

# TIMEOUT - set the default mount timeout in secons. The internal
#           program default is 10 minutes, but the default installed
#           configuration overrides this and sets the timeout to 5
#           minutes to be consistent with earlier autofs releases.
#
TIMEOUT= 30----------此处默认是300s,我设置为了30s,即30秒不用autofs会自动卸载

5、重启服务 :systemctl   restart  autofs

当30秒不用autofs,又想要挂载的话,只需要ls /home/guests/ldapuser0 或者 cd /home/guests/ldapuser0就可激活自动挂载。

感谢您的拜读!!!

猜你喜欢

转载自blog.csdn.net/perfect11_1/article/details/81096825