Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1117156
  • 博文数量: 309
  • 博客积分: 6093
  • 博客等级: 准将
  • 技术积分: 3038
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-03 17:14
个人简介

linux学习记录

文章分类

全部博文(309)

文章存档

2014年(2)

2012年(37)

2011年(41)

2010年(87)

2009年(54)

2008年(88)

分类:

2010-08-25 15:35:43

                     RHCE学习笔记

 

下面是关于linux下面自动挂载器的讨论,

 

自动挂载器的介绍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.miscauto.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网络资源又会被自动挂载过来。

 

在linux下面自动挂载器的讨论就到这里了。

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