Chinaunix首页 | 论坛 | 博客
  • 博客访问: 226108
  • 博文数量: 36
  • 博客积分: 3044
  • 博客等级: 中校
  • 技术积分: 356
  • 用 户 组: 普通用户
  • 注册时间: 2010-02-20 18:31
文章分类

全部博文(36)

文章存档

2010年(36)

分类: LINUX

2010-02-20 21:24:54

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任.http://U16.cublog.cn 
   
    我们经常会去下载别的服务器上的东西..或者挂载本地的目录到一另一个目录主要为了访问起来方便路径容易记住.这个服务主要有两个配置文件一个是/etc/auto.master.这个文件定义了挂载的挂载点后面紧跟着mount动作...另一个是/etc/auto.misc,这个文件定义挂载的地方以及被挂在的目录.此目录可以是远程服务器上的目录也可以是本地目录.....我们可以间接来进行映射远程机器上的目录到本机,也可直接映射本地的目录...

   下面我来给大家详细讲解间接映射远程机器目录到本地的目录.......先看看看/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         
/myfiles         /etc/auto.home     # /myfiles定义了mount的挂载点.而/etc/auto.home定
义了mount的动作./etc/auto.home本身不存在可以自己创建..
/myftp           /etc/auto.misc      # 同理/myftp定义了mount的挂载点而/etc/auto.misc定
义了mount的动作..
# 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.
        我们在来看一下/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          

boot           -fstype=ext2            :/dev/hda1  #将本地磁盘/dev/hda1自动挂载到/myftp/boot上..
#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
pub             -ro,intr,soft           192.168.0.254:/var/ftp/pub  #这儿定义的挂载点将远程目录挂载到本地myftp/pub目录...
然后执行此命令重启服务..启动完成进入myftp目录..
    [root@station18 pub]#service   autofs   restart
    [root@station18 pub]#cd   /myftp/;ls  -l
                                total 0
我们会看见返回的结果是total  0...并没有发现目录...这时你要看第二个配置文件中挂载
点是pub...所以执行
   [root@station18 pub]#cd    /myftp/pub;ls -l
    drwxrwxr-x+ 2 root root   4096 Feb  6 17:20 books
    dr-xr-xr-x  3 root root   4096 Jan 23 22:49 Cluster
    dr-xr-xr-x  3 root root   4096 Jan 23 22:49 ClusterStorage
    -rw-r--r--  1 2021 2021  51200 Jan 25 02:17 course.ppt
    drwxr-xr-x  2 root root   4096 Jan 23 22:44 docs
    dr-xr-xr-x  3 root root   4096 Jan 23 22:49 errata
    -rw-r--r--  2 root root   1220 Jan 23 22:48 EXAMPLE-CA-CERT
    -rw-r--r--  2 root root   1220 Jan 23 22:48 example-ca.crt
     drwxrwxr-x+ 2 root root   4096 Feb  6 02:23 Files
    -rw-r--r--  1 root root     28 Jul 31  2009 getme
    drwxr-xr-x  5 root root   4096 Jan 23 22:48 gls
    drwxr-xr-x  4 root root   4096 Feb  5 08:00 homework
    dr-xr-xr-x  4 root root   4096 Aug 19 14:02 images
    drwx------  2 root root  16384 Jan 23 22:30 lost+found
    drwxr-xr-x  2 root root   4096 Jan 23 22:48 namedfiles
    drwxr-xr-x  2 root root   4096 Jan 23 22:48 RPMS
    dr-xr-xr-x  3 root root 147456 Jan 23 22:51 Server
    drwxrwxr-x  2 2021 2021   4096 Feb  7 07:57 Sources
    drwxrwxr-x+ 2 root root   4096 Jan 26 19:06 test
    drwxrwxr-x+ 4 root root   4096 Feb  5 10:09 Tools
    dr-xr-xr-x  3 root root   4096 Jan 23 22:49 VT
         在返回到myftp目录执行下面命令
         [root@station18 myftp]# ls  -l
    total 8
     drwxrwxr-x+ 21 root root 4096 Feb  4 07:56 pub
 
       看到pub目录显示出啦,当我们第一次访问这个目录时只有进去这个目录它才会被显示出来...这地方列的都是我FTP服务器上的东西....这样就把远程主机上的资料挂载到本地的目录中,访问起来很方便....强调一点的是过几分钟这个目录也就是/pub会自动消失...起到保护的作用,要想访问得输入准确的路径才行...这儿我测试过默认也就是五分钟会消失....而定义这个时间的文件在/etc/sysconfig/autofs中,我们可以用cat查看一下这个文件
 
 
          第一个配置文件中myftp这个目录可以自己创建也可不创建,当重启动autofs服务的时候系统会自动创建......
   
          当在/etc/auto.miscr配置文件中插入一行...写入
llm     -ro,intr,soft     192.168.0.254:/var/ftp/pub 
          重启动autofs服务,执行
             #cd   /myftp/llm;ls  -l

       我们会发现远程主机的目录全被列了出来.....这里强调的是myftp目录必须得先创建.
和上面的不同....
    #
# Define default options for autofs.
#
# MASTER_MAP_NAME - default map name for the master map.
#
#MASTER_MAP_NAME="auto.master"
#
# TIMEOUT - set the default mount timeout (default 600).
#
TIMEOUT=300
#
# NEGATIVE_TIMEOUT - set the default negative timeout for
#                    failed mount attempts (default 60).
#
#NEGATIVE_TIMEOUT=60
#
# UMOUNT_WAIT - time to wait for a response from umount(8).
#
#UMOUNT_WAIT=12
#
# BROWSE_MODE - maps are browsable by default.
#
BROWSE_MODE="no"
#
# APPEND_OPTIONS - append to global options instead of replace.
#
#APPEND_OPTIONS="yes"
#
# LOGGING - set default log level "none", "verbose" or "debug"
#
#LOGGING="none"
#
# Define base dn for map dn lookup.
#
# Define server URIs
#
# LDAP_URI - space seperated list of server uris of the form
#            ://[/] where can be ldap
#            or ldaps. The option can be given multiple times.
#            Map entries that include a server name override
#            this option.
#
#            This configuration option can also be used to
#            request autofs lookup SRV RRs for a domain of
#            the form :///[]. Note that a
#            trailing "/" is not allowed when using this form.
#            If the domain dn is not specified the dns domain
#            name (if any) is used to construct the domain dn
#            for the SRV RR lookup. The server list returned
#            from an SRV RR lookup is refreshed according to
#            the minimum ttl found in the SRV RR records or
#            after one hour, whichever is less.
#
#LDAP_URI=""
#
# LDAP__TIMEOUT - timeout value for the synchronous API  calls
#                 (default is LDAP library default).
#
#LDAP_TIMEOUT=-1
#
# LDAP_NETWORK_TIMEOUT - set the network response timeout (default 8).
#
#LDAP_NETWORK_TIMEOUT=8
#
# SEARCH_BASE - base dn to use for searching for map search dn.
#               Multiple entries can be given and they are checked
#               in the order they occur here.
#
#SEARCH_BASE=""
#
# Define the LDAP schema to used for lookups
#
# If no schema is set autofs will check each of the schemas
# below in the order given to try and locate an appropriate
# basdn for lookups. If you want to minimize the number of
# queries to the server set the values here.
#
#MAP_OBJECT_CLASS="nisMap"
#ENTRY_OBJECT_CLASS="nisObject"
#MAP_ATTRIBUTE="nisMapName"
#ENTRY_ATTRIBUTE="cn"
#VALUE_ATTRIBUTE="nisMapEntry"
#
# Other common LDAP nameing
#
#MAP_OBJECT_CLASS="automountMap"
#ENTRY_OBJECT_CLASS="automount"
#MAP_ATTRIBUTE="ou"
#ENTRY_ATTRIBUTE="cn"
#VALUE_ATTRIBUTE="automountInformation"
#
#MAP_OBJECT_CLASS="automountMap"
#ENTRY_OBJECT_CLASS="automount"
#MAP_ATTRIBUTE="automountMapName"
#ENTRY_ATTRIBUTE="automountKey"
#VALUE_ATTRIBUTE="automountInformation"
#
# AUTH_CONF_FILE - set the default location for the SASL
#                          authentication configuration file.
#
#AUTH_CONF_FILE="/etc/autofs_ldap_auth.conf"
#
# MAP_HASH_TABLE_SIZE - set the map cache hash table size.
#                       Should be a power of 2 with a ratio roughly
#                       between 1:10 and 1:20 for each map.
#
#MAP_HASH_TABLE_SIZE=1024
#
# General global options
#
# If the kernel supports using the autofs miscellanous device
# and you wish to use it you must set this configuration option
# to "yes" otherwise it will not be used.
USE_MISC_DEVICE="yes"
#
#OPTIONS=""
#
  
       关于autofs我们就说到这儿....自动挂载本地目录和远程的目录会经常用到.所以喜欢linux的朋友一定要把这个学好了...
   
    
   
 
 
阅读(4482) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~