autofs自动挂载

一般我们将需要挂载的信息写入到/etc/fstab中,这样远程共享资源时就会自动随着服务器开机而进行挂载了,这样虽然很方便,但是如果挂载的远程资源太多时,则会给宽带和服务器的资源带来较大的负载。假若资源挂载后长期不使用,也会造成服务器硬件资源的浪费。

今天我们来学习下自动挂载,当检测到用户访问一个尚未挂载的文件系统时进行动态挂载,从而节约了网络资源和服务器的硬件资源。

例题:通过autofs自动挂载光驱文件

1. 安装autofs软件包

yum install autofs -y

2. 编辑主配置文件,格式为“挂载目录 子配置文件”

vim /etc/auto.master

#
# Sample auto.master file
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# For details of the format look at autofs(5).
#
/misc   /etc/auto.misc
/mnt    /etc/auto.cdrom     #新增加的挂载记录
#
# 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

3. 修改子配置文件,格式为“挂载目录 挂载文件类型及权限 :设备名称”

vim /etc/auto.cdrom

#添加以下记录

cdrom -fstype=iso9660,ro,nosuid,nodev :/dev/sr0

4. 重启服务

service autofs restart

5. 测试

autofs自动挂载

猜你喜欢

转载自blog.51cto.com/10316297/2116195