Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2395904
  • 博文数量: 328
  • 博客积分: 4302
  • 博客等级: 上校
  • 技术积分: 5486
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-01 11:14
个人简介

悲剧,绝对的悲剧,悲剧中的悲剧。

文章分类

全部博文(328)

文章存档

2017年(6)

2016年(18)

2015年(28)

2014年(73)

2013年(62)

2012年(58)

2011年(55)

2010年(28)

分类: LINUX

2011-03-08 16:03:54


   摘要:

  automount 和 autofs是易于使用的文件系统管理工具,功能强大。它允许同一台机器上的所有用户在他们需要的时候去安装不同的文件系统。

  简介:

  对于不同的物理设备(硬盘、软盘、cdrom等等)和/或操作系统,数据的写入过程也是不同的:这就是我们所称的文件系统。/etc /fstab文件决定了启动时安装的硬盘安装点。每个安装点对应一块区域或一个文件系统(例如,一个硬盘分区)。然后,如果你想存取其它的分区,只有 root用户能使用mount命令(除非特定的选项“user”包含在/etc/fstab中)。作为超级用户root,你要指明安装位置,被安装的分 区,有时还包括文件系统和其他一些选项。幸运的是,普通用户没有这种权限,不能存取所有的数据。

  Mount 和 fstab 的man pages提供了有关这些命令和概念的更详细的描述。

  Automount和autofs允许系统管理员配置机器能够访问的所有的文件系统,他同样要用到mount。用户可以用一种完全透明的方式来访问这些系统,完全不必关心内核是如何回答这些请求的。

  描述:

  这一对命令(automount,autofs)可以看作是网络系统中的客户机/服务器模式。服务器正在运行,等待发出的请求。请求到来时,服务器将自动复制,这边用来回应系统的请求,那边继续等待请求。

  现在,autofs扮演了等待服务器的角色,automount则扮演了另一个角色。请求将背保存在配置文件中。

  autofs

  通常,autofs在系统启动时被运行,关机或重新启动时被关闭。然而,系统管理员能够手工启动或停止它的运行。

  1.Start:含义很明显,启动进程。启动时,autofs将在配置文件/etc/auto.master中查询“maps”(maps指明 了安装位置)。然后,他为每个安装位置启动automount。接着,autofs查询NIS maps(关于这一点,这篇文章不作过多涉及)。

  2.Stop: 停止autofs和所有automounts的运行。

  3.Status:显示当前的配置和所有正在运行的automount。

  4.Reload:重新读取auto.master map,杀掉当前的automount,然后重新运行。注意,maps中的变化在重新启动后将被体现出来。另一方面,auto.master的变化也要求autofs重新启动。

  总之,autofs只是一个脚本,它在运行于每一个安装点的automount之前要访问auto.master。

  automount

  Automount运行时,要用到初始安装目录(启动automount时被autofs找到的),还有描述初始安装目录特性的新的map文 件。与automount相关的map文件包含自动安装文件系统所需的所有信息。当有人试图访问开始于安装点的目录树时,自动安装过程就会自动完成。

  然后,当经过非活动期之后(缺省是5分钟),文件系统就会被自动卸载。

  Configuration

  配置将在2个文件的帮助下完成。Auto.master文件,包含安装点,以及为特定安装点提供安装选项的安装点文件。


/etc/auto.master file

  这里,我们描述一下Sun格式的maps文件。另一种格式(hesiod)不适合下面讲到的语法。

  /etc/auto.master是autofs的主要文件。每一行描述一个安装点,指向包含文件系统描述的文件,该文件系统将被安装到这个安装点目录。

  每一行的语法如下:


mount-point map-for-the-associated-automount
[ -mount-options-separated-by-comma ]
Example :
/home /etc/auto.home
/misc /etc/auto.misc --timeout 60
/mnt yp:mnt.map -intr,nosuid,nodev

  这里设置了3个安装点,/home,/misc和/mnt。为了访问/misc目录下的文件,automount将会读取/etc/auto.misc文件,以便找到安装选项和与文件系统相关的关键字(the key)。

  最后2行包含可选项。他们在mount的man page中有描述,而且是标准的。就象例子中最后一行所显示的那样,autofs和automount与黄页maps(NIS或其他)是全兼容的。


The key represents an identifier for the file system under the mount point .
The place is the true physical location.

  这个文件的语法同auto.master基本相同(两者都是map文件嘛):


key [ -mount-options-separated-by-comma ] place

  我们回头看一下使用/etc/auto.misc文件的那个例子:


kernel -ro,soft,intr ftp.kernel.org:/pub/linux
cdrom -fstype=iso9660,ro :/dev/cdrom
floppy -fstype=auto :/dev/fd0
windoz -fstype=vfat :/dev/hda1

  文件的绝对路径如下:


/mount-point/key/path/file

  现在,为了读取我的windows文件config.sys,我只要运行一下“cat /misc/windoz/config.sys”,就能存取到/dev/hda1设备。

  我们注意到这个文件的第一行指向了一个NFS的出口目录(这也正显示了automount和autofs的灵活应用)。



实例:
# cat /etc/auto.master
#/misc  /etc/auto.misc --timeout=60
#/misc  /etc/auto.misc
/net    /etc/auto.net
如果此处为:“/net    -hosts”,那么/net目录用户不可写,只有autofs可用


# cat /etc/auto.net


#!/bin/sh



# $Id: auto.net,v 1.6 2005/01/04 14:36:54 raven Exp $



# This file must be executable to work! chmod 755!



# Look at what a host is exporting to determine what we can mount.

# This is very simple, but it appears to work surprisingly well



key="$1"



# add "nosymlink" here if you want to suppress symlinking local filesystems

# add "nonstrict" to make it OK for some filesystems to not mount

opts="-fstype=nfs,hard,intr,nodev,nosuid"



# Showmount comes in a number of names and varieties.  "showmount" is

# typically an older version which accepts the '--no-headers' flag

# but ignores it.  "kshowmount" is the newer version installed with knfsd,

# which both accepts and acts on the '--no-headers' flag.

#SHOWMOUNT="kshowmount --no-headers -e $key"

#SHOWMOUNT="showmount -e $key | tail -n +2"



# I've wanted to do this for ages.

# Taken from a script contributed by Elmar Pruesse for

# mounting smb mounts.

for SMNT in /{,usr/}{,s}bin/{,k}showmount

do

        if [ -x $SMNT ]

        then

                break

        fi

done



[ -x $SMNT ] || exit 1



# Newer distributions get this right

SHOWMOUNT="$SMNT --no-headers -e $key"



$SHOWMOUNT | LC_ALL=C sort +0 | \

        awk -v key="$key" -v opts="$opts" -- '

        BEGIN   { ORS=""; first=1 }

                { if (first) { print opts; first=0 }; print " \\\n\t" $1, key ":" $1 }

        END     { if (!first) print "\n"; else exit 1 }

        '

# /etc/init.d/autofs restart

现在如果访问/net/10.10.10.10/opt, autofs会自动把10.10.10.10:/opt装载到/net/10.10.10.10/opt目录。

  


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