Autofs自动挂载探讨
Autofs介绍:
mount是用来挂载文件系统的,可以在系统启动的时候挂载也可以在系统启动后挂载。对于本地固定设
备,如硬盘可以使用mount挂载;而光盘、软盘、NFS、SMB等文件系统具有动态性,即需要的时候才有
必要挂载。光驱和软盘我们一般知道什么时候需要挂载,但NFS和SMB共享等就不一定知道了,即我们
一般不能及时知道NFS共享和SMB什么时候可以挂载。而autofs服务就提供这种功能,好像windows中的
光驱自动打开功能,能够及时挂载动态加载的文件系统。免去我们手动挂载的麻烦。要实现光驱,软盘
等的动态自动挂载,需要进行相关的配置。
Autofs特点:
Autofs与Mount/Umount的不同之处在于,它是一种看守程序。如果它检测到用户正试图访问一个尚未
挂接的文件系统,它就会自动检测该文件系统,如果存在,那么Autofs会自动将其挂接。另一方面,
如果它检测到某个已挂接的文件系统在一段时间内没有被使用,那么Autofs会自动将其卸载。因此一
旦运行了Autofs后,用户就不再需要手动完成文件系统的挂接和卸载。
Autofs常用配置:
Autofs需要从/etc/auto.master文件中读取配置信息。该文件中可以同时指定多个挂接点,由Autofs
来挂接文件系统。文件中的每个挂接点单独用一行来定义,每一行可包括3个部分,分别用于指定挂接
点位置,挂接时需使用的配置文件及所挂接文件系统在空闲多长时间后自动被卸载。例如在文件中包括
了如下一行:
/auto /etc/auto.misc --timeout
其中第一部分指定一个安装点为/auto,第二部分指定该挂接点的配置文件为/etc/auto.misc,
第三部分指定所挂接的文件系统在空闲60秒后自动被卸载。
文件/etc/auto.misc的示例如下:
cd -fstype=iSO9660,ro :/dev/cdrom
fd -fstype=msdos :/dev/fd0
文件每一行都说明某一个文件系统如何被挂接。其中第一行指定将/dev/cdrom挂接在/auto/cd中,
第二行指定将/dev/fd0挂接在/auto/fd中。每一行的第二个值-fstype是一个可选项,用来表明所
挂接的文件系统的类型和挂接选项,在mount命令中能使用的挂接选项同样适用于-fstype。
实验环境:
NFS 服务器:
IP:192.168.112.130
[root@node03 ~]# cat /etc/redhat-release
CentOS release 6.6 (Final)
[root@node03 ~]# uname -r
2.6.-.el6.x86_64
[root@node03 ~]#
[root@node03 ~]# getenforce
Disabled
[root@node03 ~]# service iptables status
iptables: Firewall is not running.
[root@node03 ~]#
客户端:
IP:192.168.112.129
[root@node02 ~]# cat /etc/redhat-release
CentOS release 6.6 (Final)
[root@node02 ~]# uname -r
2.6.-.el6.x86_64
[root@node02 ~]#
[root@node02 ~]# getenforce
Disabled
[root@node02 ~]# service iptables status
iptables: Firewall is not running.
[root@node02 ~]#
1、NFS服务器安装nfs服务:
[root@node03 ~]# yum install rpcbind nfs nfs-utils
[root@node03 ~]# service rpcbind start
Starting rpcbind: [ OK ]
[root@node03 ~]#
[root@node03 ~]# service nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
[root@node03 ~]#
创建两个共享目录:cvxtmp和cvxtmp2
[root@node03 ~]# mkdir -p /cvxtmp
[root@node03 ~]# mkdir -p /cvxtmp2
[root@node03 ~]#
将磁盘/dev/sdb和/dev/sdc分别挂在到cvxtmp和cvxtmp2
[root@node03 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext4 97G .3G 89G % /
tmpfs tmpfs 236M 12K 236M % /dev/shm
/dev/sda1 ext4 976M 27M 898M % /boot
/dev/sdb ext4 50G 94M 47G % /cvxtmp2
/dev/sdc ext4 .9T .4G .6T % /cvxtmp
[root@node03 ~]#
2、修改nfs配置文件,将cvxtmp和cvxtmp2共享出去
[root@node03 ~]# cat /etc/exports
/cvxtmp *(rw,no_all_squash,no_subtree_check,sync)
/cvxtmp2 *(rw,no_all_squash,no_subtree_check,sync)
[root@node03 ~]#
[root@node03 ~]# showmount -e 192.168.112.130
Export list for 192.168.112.130:
/cvxtmp2 *
/cvxtmp *
[root@node03 ~]#
3、安装autofs服务
[root@node02 ~]# yum install autofs -y
安装完成之后,在/etc/下会有几个文件,如下所示:
[root@node02 ~]# ls -l /etc/auto.*
-rw-r--r-- root root Aug : /etc/auto.home
-rw-r--r-- root root Aug : /etc/auto.master
-rw-r--r-- root root Mar : /etc/auto.misc
-rwxr-xr-x root root Mar : /etc/auto.net
-rwxr-xr-x root root Mar : /etc/auto.smb
You have new mail in /var/spool/mail/root
[root@node02 ~]#
其中auto.master是主配置文件,之后我们要创建一个文件auto.home,然后将要挂载到本地的
分区的目录写入其中:
[root@node02 ~]# cat /etc/auto.home
/cvxtmp -rw,soft,intr node03:/cvxtmp
/cvxtmp2 -rw,soft,intr node03:/cvxtmp2
[root@node02 ~]#
此时编辑/etc/auto.master,将auto.home文件添加进去,autofs在启动时加载auto.home,"/- /etc/auto.home"
[root@node02 ~]# cat /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().
#
/misc /etc/auto.misc
#
# 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
/- /etc/auto.home
#
# 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
[root@node02 ~]#
然后重启autofs服务:
[root@node02 ~]# service autofs restart
Stopping automount: [ OK ]
Starting automount: [ OK ]
[root@node02 ~]#
查看挂在情况,结果发现我们配置的挂在分区居然没有挂在过来,难道配置错误?
[root@node02 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext4 97G .4G 89G % /
tmpfs tmpfs 236M 12K 236M % /dev/shm
/dev/sda1 ext4 976M 27M 898M % /boot
[root@node02 ~]#
接下来我们进入挂在的目录cvxtmp和cvxtmp2
[root@node02 ~]# cd /cvxtmp
[root@node02 cvxtmp]# cd ..
[root@node02 /]# cd cvxtmp2
[root@node02 cvxtmp2]#
然后再查看挂在情况:
[root@node02 cvxtmp2]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext4 97G .4G 89G % /
tmpfs tmpfs 236M 12K 236M % /dev/shm
/dev/sda1 ext4 976M 27M 898M % /boot
node03:/cvxtmp nfs .9T .4G .6T % /cvxtmp
node03:/cvxtmp2 nfs 50G 94M 47G % /cvxtmp2
[root@node02 cvxtmp2]#
发现挂在居然已经生效。此时到NFS服务端向这里两个目录分别写入文件cvxtmp.txt和cvxtmp2.txt
[root@node03 /]# echo cvxtmp > /cvxtmp/cvxtmp.txt
[root@node03 /]# echo cvxtmp2 > /cvxtmp2/cvxtmp2.txt
[root@node03 /]# cat /cvxtmp/cvxtmp.txt
cvxtmp
[root@node03 /]# cat /cvxtmp2/cvxtmp2.txt
cvxtmp2
[root@node03 /]#
然后再切换到挂载端查看。
[root@node02 ~]# cat /cvxtmp/cvxtmp.txt
cvxtmp
[root@node02 ~]# cat /cvxtmp2/cvxtmp2.txt
cvxtmp2
[root@node02 ~]#
发现挂在确实生效,至此autofs自动挂在功能已经实现。
Autofs自动挂载探讨的更多相关文章
- Linux:SAMBA共享、NFS共享、Autofs自动挂载
SAMBA.NFS共享区别 NFS开源文件共享程序:NFS(NetworkFile System)是一个能够将多台Linux的远程主机数据挂载到本地目录的服务,属于轻量级的文件共享服务,不支持Linu ...
- linux autofs自动挂载
autofs:自动挂载器 自动挂载器是一个监视目录的守护进程,并在目标子目录被引用时,自动执行预定义的NFS挂载 自动挂载器由autofs服务脚本管理 自动挂载器由auto.master配置文件进行配 ...
- autofs 自动挂载.
autofs 自动挂载. 操作环境:redhat 6 一.autofs 说明 自动挂载器是一个监视目录的守护进程,并在目标子目录被引用时,自动执行预定义的挂载 自动挂载器由autofs服务脚本管理 自 ...
- Linux服务——二、配置NFS及autofs自动挂载服务
一.NFS服务配置步骤 NFS的作用:能够使两台虚拟机之间实现文件共享.数据同步 准备:主机名.网络.yum源 Server端: 1.安装nfs-util和rpcbind:(图形化自带) [root@ ...
- autofs自动挂载
autofs是根据需要自动挂载,默认5分钟不使用自动卸载挂载点!nfs,smb,iso,sd*的挂载 环境:RHEL6.5/Centos6.5 172.24.0.25 01.安装autofs y ...
- NFS使用autofs自动挂载
NFS自动挂载设置在/etc/fstab和/etc/rc.local可能挂载不成功,假如是服务端NFS宕机还可能导致客户端无法启动,可以使用autofs实现自动挂载 安装autofs yum -y i ...
- 004.Autofs自动挂载
一 安装autofs [root@imxhy data]# yum -y install autofs 二 编辑自动挂载相关配置 2.1 修改master [root@imxhy ~]# vi /et ...
- 实现nfs持久挂载+autofs自动挂载
实验环境: 两台主机 node4:192.168.37.44 NFS服务器 node2:192.168.37.22 客户端 在nfs服务器,先安装nfs和rpcbind [root@node4 fen ...
- 2-5-NFS服务器配置和autofs自动挂载-配置Samba服务器配置现实文件共享
大纲: NFS服务器运行原理 实战配置NFS服务器 配置Samba服务器配置现实文件共享 ----------------------------------------------- 问题: # 怎 ...
随机推荐
- .net core通过多路复用实现单服务百万级别RPS吞吐
多路复用其实并不是什么新技术,它的作用是在一个通讯连接的基础上可以同时进行多个请求响应处理.对于网络通讯来其实不存在这一说法,因为网络层面只负责数据传输:由于上层应用协议的制订问题,导致了很多传统服务 ...
- Chapter 4 Invitations——18
But they were all in, and Edward was speeding away. 但是他们都在里面了之后,Edward就加速走了. I drove home slowly, ca ...
- Linux基础知识第二讲,文件目录命令使用
目录 一丶Linux终端使用技巧. 1.自动补全 Tab技巧. 2.使用输入过的命令 二丶Linux 目录知识 1.linux目录的特点 2.ls 隐藏文件的查看 3.ls 常用选项 4.通配符的配合 ...
- Java开发知识之Java的数字处理类Math类
Java开发知识之Java的数字处理类Math类 一丶Java.text.DecimalFormat类与NumberFormat类 首先 Java.text.DecimalFormat指的是Decim ...
- 解决Mysql错误:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
需要重启服务器:sudo /etc/init.d/mysql restart
- 【记录一次坑经历】axios使用x-www-form-urlencoded 服务器报400(错误的请求。 )(后端.Net MVC5 WebApi OAuth,前端Electron-Vue)
首先放上源码 electron-vue axios 注册 import Vue from 'vue' import axios from 'axios' axios.defaults.baseUR ...
- [C#] 使用 StackExchange.Redis 封装属于自己的 RedisHelper
使用 StackExchange.Redis 封装属于自己的 RedisHelper 目录 核心类 ConnectionMultiplexer 字符串(String) 哈希(Hash) 列表(List ...
- python3中json模块的用法
__author__ = "JentZhang" import json user_info = {"} # 将字典转换为JSON字符串 json_str = json. ...
- [PHP] 抽象类abstract的回顾
1.abstract定义为抽象的类不能被实例化. 2.它里面至少有一个方法是被声明为抽象的,那么这个类就必须被声明为抽象的. 3.被定义为抽象的方法只是声明了其调用方式(参数),不能定义其具体的功能实 ...
- Django学习之五:Django 之 注意事项及汇总
目录 Django 之 注意事项及汇总 全局 settings model模块-模型模块 URLs模块 Templates System 模版模块 View/HttpRequest/HttpRespo ...