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

[root@study ~]# yum install autofs
Loaded plugins: fastestmirror
abc | 3.6 kB 00:00:00
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package autofs.x86_64 1:5.0.7-54.el7 will be installed
--> Processing Dependency: libtirpc.so.1()(64bit) for package: 1:autofs-5.0.7-54.el7.x86_64
--> Processing Dependency: libhesiod.so.0()(64bit) for package: 1:autofs-5.0.7-54.el7.x86_64
--> Running transaction check
---> Package hesiod.x86_64 0:3.2.1-3.el7 will be installed
---> Package libtirpc.x86_64 0:0.2.4-0.6.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================
Package Arch Version Repository Size
====================================================================================================================
Installing:
autofs x86_64 1:5.0.7-54.el7 abc 794 k
Installing for dependencies:
hesiod x86_64 3.2.1-3.el7 abc 30 k
libtirpc x86_64 0.2.4-0.6.el7 abc 85 k

Transaction Summary
====================================================================================================================
Install 1 Package (+2 Dependent packages)

Total download size: 908 k
Installed size: 5.3 M
Is this ok [y/d/N]: y
Downloading packages:
--------------------------------------------------------------------------------------------------------------------
Total 1.7 MB/s | 908 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : hesiod-3.2.1-3.el7.x86_64 1/3
Installing : libtirpc-0.2.4-0.6.el7.x86_64 2/3
Installing : 1:autofs-5.0.7-54.el7.x86_64 3/3
Verifying : 1:autofs-5.0.7-54.el7.x86_64 1/3
Verifying : libtirpc-0.2.4-0.6.el7.x86_64 2/3
Verifying : hesiod-3.2.1-3.el7.x86_64 3/3

Installed:
autofs.x86_64 1:5.0.7-54.el7

Dependency Installed:
hesiod.x86_64 0:3.2.1-3.el7 libtirpc.x86_64 0:0.2.4-0.6.el7

Complete!

生产环境中的Linux服务器,会同时管理许多设备的挂载操作。如果把这些设备挂载信息写入到autofs服务中的主配置文件中,会让主配置文件繁杂,不利于服务执行效率,也不利于日后修改里面的配置内容,因此在autofs服务程序的主配置文件中需要按照“挂载目录 子配置文件”的格式进行填写。挂载目录是设备挂载位置的上一级目录。

[root@study ~]# vim /etc/auto.master

1 #
2 # Sample auto.master file
3 # This is a 'master' automounter map and it has the following format:
4 # mount-point [map-type[,format]:]map [options]
5 # For details of the format look at auto.master(5).
6 #
7 /media /etc/iso.misc
8 /misc /etc/auto.misc
9 #
10 # NOTE: mounts done from a hosts map will be mounted with the
11 # "nosuid" and "nodev" options unless the "suid" and "dev"
12 # options are explicitly given.
13 #
14 /net -hosts
15 #
16 # Include /etc/auto.master.d/*.autofs
17 # The included files must conform to the format of this file.
18 #
19 +dir:/etc/auto.master.d
20 #
21 # Include central master map if it can be found using
22 # nsswitch sources.
23 #
24 # Note that if there are entries for /net or /misc (as
25 # above) in the included master map any keys that are the
26 # same will not be seen as the first read key seen takes
27 # precedence.
28 #
29 +auto.master

在子配置文件中,按照“挂载目录 挂载文件类型及权限:设备名称”的格式进行填写。例如要把光盘设备挂载到/media/iso目录中,可将挂载目录写为iso,而-fstype为文件系统格式参数,iso9660为光盘设备格式,ro、nosuid及nodev为光盘设备具体的权限参数,/dev/cdrom则是定义要挂载的设备名称。

[root@study ~]# vim /etc/iso.misc
[root@study ~]# systemctl start autofs
[root@study ~]# systemctl enable autofs
Created symlink from /etc/systemd/system/multi-user.target.wants/autofs.service to /usr/lib/systemd/system/autofs.service.

接下来会发现,查看当前光盘设备挂载情况,光盘设备没有被挂载上,而且/media目录也没有iso子目录,但是可以用cd命令切换到这个iso子目录,而且光盘设备会立即被挂载上。

[root@study ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18G 2.8G 15G 17% /
devtmpfs 479M 0 479M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 483M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 497M 125M 373M 25% /boot
tmpfs 98M 0 98M 0% /run/user/0
[root@study ~]# cd /media/
[root@study media]# ls
[root@study media]# cd iso
[root@study iso]# ls -l
total 1490
-r--r--r-- 1 root root 14 Dec 9 2015 CentOS_BuildTag
dr-xr-xr-x 3 root root 2048 Dec 9 2015 EFI
-r--r--r-- 1 root root 215 Dec 9 2015 EULA
-r--r--r-- 1 root root 18009 Dec 9 2015 GPL
dr-xr-xr-x 3 root root 2048 Dec 9 2015 images
dr-xr-xr-x 2 root root 2048 Dec 9 2015 isolinux
dr-xr-xr-x 2 root root 2048 Dec 9 2015 LiveOS
dr-xr-xr-x 2 root root 1486848 Dec 9 2015 Packages
dr-xr-xr-x 2 root root 4096 Dec 9 2015 repodata
-r--r--r-- 1 root root 1690 Dec 9 2015 RPM-GPG-KEY-CentOS-7
-r--r--r-- 1 root root 1690 Dec 9 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r-- 1 root root 2883 Dec 9 2015 TRANS.TBL
[root@study iso]# cd
[root@study ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18G 2.8G 15G 17% /
devtmpfs 479M 0 479M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 483M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 497M 125M 373M 25% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr0 7.3G 7.3G 0 100% /media/iso

Linuxautofs自动挂载服务的更多相关文章

  1. Linux服务——二、配置NFS及autofs自动挂载服务

    一.NFS服务配置步骤 NFS的作用:能够使两台虚拟机之间实现文件共享.数据同步 准备:主机名.网络.yum源 Server端: 1.安装nfs-util和rpcbind:(图形化自带) [root@ ...

  2. 06、自动挂载+超级守护进程+时间同步+tcpwrapper+软硬链接+日志管理

    autofs  自动挂载服务   把下面这两条命令做成自动挂载 172.16.2.35:/share/soft /nfs/soft 172.16.2.35:/share/iso  /nfs/iso . ...

  3. Linux 系统安装 AutoFs 挂载服务

    关注「开源Linux」,选择"设为星标" 回复「学习」,有我为您特别筛选的学习资料~ 作者: Escape 链接: https://escapelife.github.io/pos ...

  4. Archlinux 自动挂载移动硬盘,开机自动启动smb服务

    Archlinux + Raspberry 打造NAS: samba篇 树莓派自动挂载硬盘,并开启smb服务. 开机自动挂在移动硬盘ntfs 安装ntfs-3g sudo pacman -S ntfs ...

  5. autofs自动挂载

    autofs是根据需要自动挂载,默认5分钟不使用自动卸载挂载点!nfs,smb,iso,sd*的挂载 环境:RHEL6.5/Centos6.5    172.24.0.25 01.安装autofs y ...

  6. 开机自动挂载 VHD 的方法

    一.批处理 除了将 VHD 文件用人工方式在[磁盘管理]里[附加]来挂载以外,也能用[脚本]来实现自动挂载. 打开[启动],将写好的 mount.bat 放入即可: Mount.bat 文件的内容为: ...

  7. Autofs自动挂载探讨

    Autofs介绍: mount是用来挂载文件系统的,可以在系统启动的时候挂载也可以在系统启动后挂载.对于本地固定设 备,如硬盘可以使用mount挂载:而光盘.软盘.NFS.SMB等文件系统具有动态性, ...

  8. mount命令和自动挂载实例

    前言 介绍mount命令和一个实例. mount命令 作用 作用:挂载linux系统外的文件 命令格式 mount [-hV] mount -a [-fFnrsvw] [-t vfstype] mou ...

  9. 阿里云 centos 服务器无法自动挂载 nas 的问题

    阿里云服务器 centos 7.3 ,开始是通过 fstab 配置的自动挂载: xxx.cn-hangzhou.nas.aliyuncs.com:/ /nas nfs4 auto 0 0 但服务器启动 ...

随机推荐

  1. C#中的Skip()和Take()

    Skip()和Take()方法都是IEnumerable<T> 接口的扩展方法,包括C#中的所有Collections类,如ArrayList,Queue,Stack等等,还有数组和字符串 ...

  2. variable '' of type '' referenced from scope '', but it is not defined 异常解决方法

    最近在做一个功能,通过拼接lamdba表达试来实现的功能,但测试时总是出现一个错误,如下图所示,网上也找不到答案,差点都放弃了.. 如上图图所示,我是想通过一个lamdba表达式(上图的IdField ...

  3. 发送RCS成功的消息log_1

    //12-02 16:39:00.869323 24174 27394 I CarrierServices: [1172] cpb.x: Send INVITE//12-02 16:39:00.920 ...

  4. 使用 Flutter 开发 Mac 桌面应用

    Flutter 可以开发 Mac,Linux,Windows 桌面,但是对于平台目前只能打对于的包,以及调试本平台的包. 切换到 master 分支 首先必须切换到 master 分支.我之前在 de ...

  5. MySQL数据库~~~~~查询行(文件的内容)

    1. 单表查询 语法 select distinct 字段 from 库名.表名 where 条件 group by 字段 # 分组 having 筛选 # 过滤 order by 字段 # 排序 l ...

  6. 并发编程~~~协程~~~greenlet模块, gevent模块

    一 协程 1. 协程: 单线程下的并发,又称微线程,纤程.协程是一种用户态的轻量级线程,即协程是由用户程序自己控制调度的. 并发真正的核心: 切换并且保持状态. 开启协程并发的执行,自己的程序把控着C ...

  7. Linux笔记16 使用Vsftpd服务传输文件;使用Samba或NFS实现文件共享。

    FTP协议有下面两种工作模式. 1.主动模式:FTP服务器主动向客户端发起连接请求. 2.被动模式:FTP服务器等待客户端发起连接请求(FTP的默认工作模式).Vsftpd服务程序vsftpd作为更加 ...

  8. diango运行流程

    diango运行流程 Django处理一个请求的流程: 在浏览器的地址栏中输入地址,回车,发了一个GET请求 wsgi模块接收了请求,将请求的相关信息封装成request对象 根据地址找到对应函数 执 ...

  9. HashMap如何在Java中工作?

    通过优锐课学习笔记分享,我们可以看到HashMap问题在工作面试中很常见. 这也是HashMaps在Java内部如何工作的一些深入说明,分享给大家参考学习. HashMap在内部如何工作已成为几乎所有 ...

  10. 数据、模型、IT系统认知

    数据.模型.IT系统认知 量化投资定义 量化投资主要是指通过数理模型来实现投资理念,由计算机产生交易策略的一种投资方法. 量化投资是一种方法论,而不是具体的交易策略. 通常与基本面.技术面分析相结合. ...