|簡體中文

比思論壇

 找回密碼
 按這成為會員
搜索



查看: 589|回復: 0
打印 上一主題 下一主題

RHEL5_4配置自动挂载器

[複製鏈接]

36

主題

0

好友

1244

積分

高中生

Rank: 4

  • TA的每日心情
    開心
    3 小時前
  • 簽到天數: 2325 天

    [LV.Master]伴壇終老

    推廣值
    0
    貢獻值
    1
    金錢
    13886
    威望
    1244
    主題
    36
    樓主
    發表於 2014-12-5 17:13:33

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

    要想实现自动挂载的功能,必须安装autofs这个包
    自动挂载是通过两个文件来实现的
    /etc/auto.master
    /etc/auto.misc
    还有个配置文件
    /etc/sysconfig/autofs
    现在我们打开/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网络资源又会被自动挂载过来。
    重要聲明:本論壇是以即時上載留言的方式運作,比思論壇對所有留言的真實性、完整性及立場等,不負任何法律責任。而一切留言之言論只代表留言者個人意見,並非本網站之立場,讀者及用戶不應信賴內容,並應自行判斷內容之真實性。於有關情形下,讀者及用戶應尋求專業意見(如涉及醫療、法律或投資等問題)。 由於本論壇受到「即時上載留言」運作方式所規限,故不能完全監察所有留言,若讀者及用戶發現有留言出現問題,請聯絡我們比思論壇有權刪除任何留言及拒絕任何人士上載留言 (刪除前或不會作事先警告及通知 ),同時亦有不刪除留言的權利,如有任何爭議,管理員擁有最終的詮釋權。用戶切勿撰寫粗言穢語、誹謗、渲染色情暴力或人身攻擊的言論,敬請自律。本網站保留一切法律權利。

    手機版| 廣告聯繫

    GMT+8, 2024-5-29 11:52 , Processed in 0.015649 second(s), 17 queries , Gzip On, Memcache On.

    Powered by Discuz! X2.5

    © 2001-2012 Comsenz Inc.

    回頂部