Chinaunix首页 | 论坛 | 博客
  • 博客访问: 863006
  • 博文数量: 72
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1693
  • 用 户 组: 普通用户
  • 注册时间: 2014-08-04 15:53
个人简介

主要从事Linux,云原生架构改造,服务网格,ELK,python,golang等相关技术。

文章分类

全部博文(72)

文章存档

2015年(52)

2014年(20)

分类: 系统运维

2014-09-20 21:01:30

        Autofs是只用来自动挂载文件系统的,与Mount/Umount的不同之处在于,它是一种看守程序。如果它检测到用户正试图访问一个尚未挂接的文件系统,它就会自动检测该文件系统,如果存在,那么Autofs会自动将其挂接。另一方面,如果它检测到某个已挂接的文件系统在一段时间内没有被使用,那么Autofs会自动将其卸载。因此一旦运行了Autofs后,用户就不再需要手动完成文件系统的挂接和卸载。

Autofs的安装和配置
[root@server10 ~]# yum install autofs -y
        一般这个服务系统会自动安装,我们在/etc下可以在看到这两个文件:
auto.master和auto.misc,我们经常会去下载别的服务器上的东西,或者挂载本地的目录到一另一个目录主要为了访问起来方便路径容易记住,这里我们对这两个文件进行说明:
    auto.master:这个文件定义了挂载点后面紧跟着的mount动作
    auto.misc:这个文件定义了挂载的地方以及被挂载所在的目录,此目录可以是远程的服务器的目录,也可以是本地的目录,我们可以间接来进行映射远程主机
               上的目录到本机,也可以直接映射本地的目录。

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

点击(此处)折叠或打开

  1. #
  2. # Sample auto.master file
  3. # This is an automounter map and it has the following format
  4. # key [ -mount-options-separated-by-comma ] location
  5. # For details of the format look at autofs(5).
  6. #
  7. #/misc /etc/auto.misc
  8. /myfile /etc/auto.home /myfiles定义了mount的挂载点.而/etc/auto.home定义了mount的动作./etc/auto.home本身不存在可以自己创建
  9. /myftp /etc/auto.misc 同理/myftp定义了mount的挂载点而/etc/auto.misc定义了mount的动作
  10. #
  11. # NOTE: mounts done from a hosts map will be mounted with the
  12. # "nosuid" and "nodev" options unless the "suid" and "dev"
  13. # options are explicitly given.
  14. #
  15. /net -hosts
  16. #
  17. # Include central master map if it can be found using
  18. # nsswitch sources.
  19. #
  20. # Note that if there are entries for /net or /misc (as
  21. # above) in the included master map any keys that are the
  22. # same will not be seen as the first read key seen takes
  23. # precedence.
  24. #
  25. +auto.master
[root@server10 ~]# vim /etc/auto.misc 

点击(此处)折叠或打开

  1. # This is an automounter map and it has the following format
  2. # key [ -mount-options-separated-by-comma ] location
  3. # Details may be found in the autofs(5) manpage
  4. cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
  5. # the following entries are samples to pique your imagination
  6. #linux -ro,soft,intr ftp.example.org:/pub/linux
  7. #boot -fstype=ext2 :/dev/hda1
  8. #floppy -fstype=auto :/dev/fd0
  9. #floppy -fstype=ext2 :/dev/fd0
  10. #e2floppy -fstype=ext2 :/dev/fd0
  11. #jaz -fstype=ext2 :/dev/sdc1
  12. #removable -fstype=ext2 :/dev/hdd
  13. pub -ro,intr,soft 192.168.201.131:/var/ftp/pub 这儿定义的挂载点将远程目录挂载到本地myftp/pub目录...然后执行此命令重启服务..启动完成进入myftp目录

[root@server10 ~]# /etc/init.d/autofs start
[root@server10 ~]#cd /myftp
[root@server10 ~]#ls        //我们看不到任何文件
[root@server10 ~]#cd pub        //但是当我们在进入的时候,这个目录将会自动挂载
[root@server10 ~]#
ls                //这时我们将看到所有192.168.201.131:/var/ftp/pub已经被挂载
file1  file1a  file1b  file1c  file2a  file2b  file2c  file3a  file3b  file3c
[root@server10 pub]# cd ..
[root@server10 myftp]# ls
pub                                  //当我们退出这个目录后我们会看到这个目录,一段时间如果我们不再进入,则它会自动卸载。

这样就实现了文件系统的自动挂载,和自动卸载的操作。




阅读(7081) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~