免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1751 | 回复: 0
打印 上一主题 下一主题

RHEL5.4配置自动挂载器 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-02-23 22:42 |只看该作者 |倒序浏览

E-mail: rhroot1112@163.com                               2010-2-4
                      RHCE学习笔记

下面是关于自动挂载器的问题(automounter)

自动挂载器的介绍
自动挂载器就是当我们网络中有一台NFS Server的时候,客户端需要去挂载NFS Server上面的资源,如果将NFS的挂载信息写在/etc/fstab这个文件里面,那么客户端只要是启动计算机,就是自动挂载NFS资源。可能有些客户端不需要去挂载NFS的资源,这样就会浪费资源。而自动挂载器就可以帮我们实现,当客户端需要去访问的时候,才挂载,不需要访问的时候,资源是断开的,所以学习自动挂载器是很有必要的。

要想实现自动挂载的功能,必须安装autofs这个包
自动挂载是通过两个文件来实现的
/etc/auto.master
/etc/auto.misc
现在我们打开/etc/auto.master这个文件,看下里面是怎么定义的。
[root@localhost ~]# vim /etc/auto.master
# $Id: auto.master,v 1.4 2005/01/04 14:36:54 raven Exp $
#
# 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
#
# 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
可以看到,在/etc/auto.master里面是这样定义的,
我们先看这句话
/misc   /etc/auto.misc
将/etc/auto.misc里面的内容挂载到/misc这个目录下面去。
我们再来开到/etc/auto.misc这个文件
[root@localhost ~]# vim /etc/auto.misc
#
# $Id: auto.misc,v 1.2 2003/09/29 08:22:35 raven Exp $
#
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage

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

# the following entries are samples to pique your imagination
#linux          -ro,soft,intr           ftp.example.org:/pub/linux
#boot           -fstype=ext2            :/dev/hda1
#floppy         -fstype=auto            :/dev/fd0
#floppy         -fstype=ext2            :/dev/fd0
#e2floppy       -fstype=ext2            :/dev/fd0
#jaz            -fstype=ext2            :/dev/sdc1
#removable      -fstype=ext2            :/dev/hdd
~     
在/etc/auto.misc文件定义了将cdrom里面的东西挂载到cd目录下面去
注意,这里的cd目录是以/misc为根的,也就是/misc/cd目录。
我们将这两个文件整合一下,意思就是说将cdrom里面的东西挂载到/misc/cd目录下面去,就是这个意思。
现在我们将一张光盘放入光驱里面,看下能否自动挂载起来。
[root@localhost ~]# cd /misc/
[root@localhost misc]# ls
[root@localhost misc]#
我们现在已经进入了这个目录,可以看到,这个目录里面什么东西都没有,刚才哪两个文件定义说,是挂载到/misc/cd目录下面,现在我们进入cd目录。
[root@localhost ~]# cd /misc/
[root@localhost misc]# ls
[root@localhost misc]# cd cd
[root@localhost cd]# ls
AUTORUN.INF  HD4.GHO      PESETUP  README.TXT  WINPE.XPE
AXPE         OSGHOST.EXE  PESOFT   SYSTEM      WNPEFONT.BIN
[root@localhost cd]# cd ..
[root@localhost misc]# ls
cd
[root@localhost misc]#
可以看到,我们光盘里面的东西就被挂载到/misc/cd目录下面去了。
这个自动挂载的功能是系统默认就有了的,下面我们根据刚才的例子来学习如何利用自动挂载器的功能来实现挂载NFS网络资源。
首先编辑/etc/auto.master这个文件,
auto.master 文件定义本地挂载点. 本地挂载点目录/mnt
编辑auto.master 配置文件如下:
#
# $Id: auto.master,v 1.4 2005/01/04 14:36:54 raven Exp $
#
# 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.nfs
/etc/auto.nfs这个文件可以自己命名,在/etc/auto.misc这个文件定义也是可以的。
复制一个模板文件auto.misc成auto.nfs
这个文件名一定要与/etc/master中定义的一致。
[root@localhost ~]#
[root@localhost ~]# cp /etc/auto.misc /etc/auto.nfs
编辑/etc/auto.nfs配置文件如下
#
# $Id: auto.misc,v 1.2 2003/09/29 08:22:35 raven Exp $
#
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage
nfs                               192.168.0.254:/var/ftp/pub
这个nfs目录在/mnt下面不需要有
重启一下服务
[root@localhost ~]# service autofs restart
Stopping automount:                                        [  OK  ]
Starting automount:                                         [  OK  ]
[root@localhost ~]#
服务启动成功。
[root@localhost ~]# df -h
Filesystem             Size   Used     Avail      Use%       Mounted on
/dev/sda3             3.9G     3.8G     0           100%        /
/dev/sda6             494M   11M     458M    3%            /home
/dev/sda2             3.9G    118M    3.6G      4%            /var
/dev/sda1             99M    14M      81M      15%          /boot
tmpfs                   188M    0         188M     0%            /dev/shm
[root@localhost ~]#
现在可以df –h 可以看到的nfs网络资源是没有挂载过来的
现在进入/mnt目录里面什么东西也没有
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# ls
[root@localhost mnt]#
当我们进入nfs目录的时候,NFS网络资源是否会挂载过来呢
[root@localhost mnt]# cd nfs
[root@localhost nfs]# ls
Cluster  ClusterStorage  fstab  grub.conf  Server  server.repo  VT
[root@localhost nfs]# cd ..
[root@localhost mnt]# ls
nfs
[root@localhost mnt]#
当进入nfs目录的时候,网络资源已经被自动的挂载过来了。通过df- h 命令也能看到的nfs网络资源被挂载到/mnt/nfs下面了
[root@localhost ~]# df -h
Filesystem           Size      Used Avail        Use%    Mounted on
/dev/sda3           3.9G     3.8G    0          100%       /
/dev/sda6           494M    11M   458M   3%          /home
/dev/sda2           3.9G     118M  3.6G     4%          /var
/dev/sda1           99M     14M    81M     15%        /boot
tmpfs                 188M    0        188M    0%          /dev/shm
192.168.0.254:/var/ftp/pub
                        9.5G     2.9G    6.2G      32%        /mnt/nfs
[root@localhost ~]#
现在我们查看一下autofs的全局配置文件,
[root@localhost ~]# vim /etc/sysconfig/autofs
# TIMEOUT - set the default mount timeout (default 600).
#
TIMEOUT=300
#
在这里有个TIMEOUT=300,就是当300S内不做任何操作,那么自动挂载就将消失,当再次进入nfs目录的时候,NFS网络资源又会被自动挂载过来。


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/111899/showart_2185500.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP