Chinaunix首页 | 论坛 | 博客
  • 博客访问: 19733559
  • 博文数量: 679
  • 博客积分: 10495
  • 博客等级: 上将
  • 技术积分: 9308
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-18 10:51
文章分类

全部博文(679)

文章存档

2012年(5)

2011年(38)

2010年(86)

2009年(145)

2008年(170)

2007年(165)

2006年(89)

分类: LINUX

2008-08-01 09:19:21

磁针石

联系方式: gmail and gtalk: xurongzhong#gmail.com

 

参考资料

OReilly.Running.Linux.5th.Edition.Dec.200510.2.3. Automounting Devices

 

简介

 

Automounter是内核功能,后台程序,配置文件的结合,能透明地加载文件系统。在需要使用的时候加载,一定时间不用的时候umount。在访问网络文件系统的时候尤其有用。使用这个功能需要在编译内核的时候打开。同时还需要开启NFS功能。如果有Automounter安装,就会产生/usr/lib/autofs目录。目前有2个版本:34。由于3被很多发行版本使用,我们讨论这个版本。我们假设所有文件系统加载到/automount。如果需要把文件系统分布到多个目录,需要使用多个automount后台程序。

       样例配置文件一般位于:sample/auto.mastersample/auto.misc需要拷贝到/etc. sample/rc.autofs为启动文件,一般拷贝到/etc/init.d,重命名为autofs

 

实验环境:Red Hat Enterprise Linux ES release 4 (Nahant Update 6)      64

       首先要修改/etc/auto.master。如下

# vi /etc/auto.master

 

#

# $Id: auto.master,v 1.3 2003/09/29 08:22:35 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 --timeout=60

/misc   /etc/auto.misc

#/net   /etc/auto.net

 

/misc   /etc/auto.misc 指明需要使用的目录和配置文件。/misc系统会autofs启动时自动创建。

 

 

# vi /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

home            -fstype=auto :/dev/sda5

 

# 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

 

其中home            -fstype=auto :/dev/sda5是我们添加的。/misc/home系统会autofs启动时自动创建。

 

NFS格式一般如下配置:sources    -fstype=nfs,soft    sourcemaster:/sources

确认配置文件为不可执行的。

#chmod a-x /etc/auto.misc

 

使用service autofs start 启动。也可以使用/etc/init.d/autofs start

 

查看状态:

# /etc/init.d/autofs status

Configured Mount Points:

------------------------

/usr/sbin/automount --timeout=60 /misc file /etc/auto.misc

 

Active Mount Points:

--------------------

/usr/sbin/automount --timeout=60 /misc file /etc/auto.misc

 

如果没有成功,可能时模块没有安装,使用modprobe autofs,或者modprobe autofs4

 

Automounter在映射数据方面用途不少,具体参见:autofs(5) and automount(8)

 

 

其他参考信息:

 

 

 以前,我使用Amd自动挂载程序,并探索如何使用它提供按需所求的远程NFS共享目录访问。Amd是一个用户空间工具,可以在Linux和其它UNIX操作系统中获得。

  另一方面,AutoFS是一个部分用户空间部分内核空间的Linux操作系统工具。和Amd不同,AutoFS几乎符合所有Linux操作系统标准。

  如果你的系统上还没有该工具,需要先安装AutoFS包。使用apturpmiyum所有需要的依赖都会安装好。下一步,编辑/etc/autofs/auto.master文件:

  # mount point config file options

  /net /etc/autofs/autofs.net --timeout=30 --ghost

  /home /etc/autofs/autofs.home --timeout=60 --ghost

 这个编辑文件中我们定义了两个主挂载点,其中所有的自动挂载目录都是活动的。本例中/net/home都是最高层目录,其中包含了自动挂载目录。它们分别通过/etc/autofs/autofs.net/etc/autofs/autofs.home配置文件定义。

  最后,/net目录树的不活动超时时间为30秒,而/home目录树的为60秒。两者都创建了配置文件中所列挂载点的空目录。这就防止了当目录未被挂载时被删除。为了确保定义的最高层目录是存在的,你需要创建/net目录和/home目录。

  /etc/auto/autofs.net文件配置如下所示

  # directory mount options device to mount

  remote_nfs -rsize=8192,wsize=8192,soft,timeo=30,rw nfs.host:/srv

  remote_smb -fstype=smbfs,credentials=/etc/smb.auth ://win.host/Share

 这里,定义了两个不同类型的远程目录。第一个是远程NFS目录,第二个是远程Samba共享目录。在本例中,第一个目录被挂载为/net/remote_nfs/,第二个为/net/remote_smb/。对于Samba共享目录,需要有认证信息,这在/etc/smb.auth中定义。如下所示:

  username=user

  password=secret

  确保该文件的模式为0600,有根用户所有,因此认证信息是公开的。

  与Amd不同,AutoFS还可以用来挂载本地设备。你可以用它来挂载CD-ROM或软盘设备。例如,为了挂载软盘,我们可以使用下面的定义:

  floppy -fstype=auto :/dev/fd0

  与Amd的另一个不同的地方是,使用AutoFS,挂载程序将不会显示远程挂载目录。你可以通过查看/proc/mounts来查看挂载内容:

  #cat /proc/mounts|grep autofs

 AutoFS是一个相当灵活的工具,你可以使用它挂载CD-ROMs,远程NFSSamba共享目录,甚至ISO镜像。有些发行版本中包含了特殊的配置文件,使用它可以挂载任何网络上可以获得网络挂载点,且不许要任何预定义的配置文件。至需简单的开启AutoFS,指向它的一个配置文件,就可以开始改变目录(例如,/net/titan,如果远程主机名称为titan的话)。

 

 

 

 

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