Rootop 服务器运维与web架构

使用autofs自动挂载cifs共享

自动挂载器是一个监视目录的守护进程,并在目标子目录被引用时,自动执行预定义的挂载。
自动挂载器由autofs服务脚本管理。

安装:
[root@Master ~]# yum install -y autofs
[root@Master ~]# 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).
#
/misc /etc/auto.misc

/mnt /etc/auto.nas –timeout 60  #必须以auto.开头
#
# NOTE: mounts done from a hosts map will be mounted with the
# “nosuid” and “nodev” options unless the “suid” and “dev”
# options are explicitly given.
#
/net -hosts
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master

其中第一部分指定一个安装点为/mnt,第二部分指定该挂接点的配置文件为/etc/auto.nas,第三部分指定所挂接的文件系统在空闲60秒后自动被卸载。

编辑/etc/auto.nas:

nas -fstype=cifs,rw,noperm,user=administrator,pass=admin@123 ://192.168.0.241/VKTVOD

参数解释:
其中”nas”列,指将//192.168.0.241/VKTVOD挂载到/mnt/nas。其它为指定文件系统,身份验证。

重启autofs服务:
[root@Master ~]# service autofs restart

输入命令ls /mnt/nas,autofs会自动检测cifs路径,会自动将其挂载到/mnt/nas中,这样ls就会列出其中的内容。如果在60秒内没有再次访问/mnt/nas,autofs会自动将/mnt/nas卸载。

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/3389.html

作者:Venus

服务器运维与性能优化

评论已关闭。