linux服务器设置自动挂载目录

1:配置/etc/exports文件

把需要共享的文件系统直接编辑到/etc/exports文件中,这样当NFS服务器重新启动时系统就会自动读取/etc/exports文件,从而告诉内核要输出的文件系统和相关的存取权限。如在server2的/etc/exports:

/var/spool/test1    server1(rw) server2(rw)
/var/spool/test2    server1(rw) server2(rw)
/var/spool/test3    server1(rw) server2(rw)

2:autofs的主要配置文件有两个,分别是/etc下的auto.master和auto.misc。其中,auto.master是起控制作用的,它定义了挂在点和automount动作的文件。其内容如下:

# $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         #/misc是定义的自动mount的挂载点,/etc/auto.misc里定义了mount的动作
/home  /etc/auto.home         #/home是定义的自动mount的挂载点;/etc/auto.home定义了mount的动作,
                                  #此文件系统默认不存在,需要我们手工创建。
/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.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         #将/dev/cdrom自动挂载到/misc/cd/下

# the following entries are samples to pique your imagination
#linux          -ro,soft,intr           ftp.example.org:/pub/linux  #将ftp.example.org的共享目录
                                                                            #/pub/linux/自动挂载到/misc/linux/下
#boot           -fstype=ext2            :/dev/hda1         #将本地磁盘分区/dev/hda1自动挂载到/misc/boot下
#floppy         -fstype=auto            :/dev/fd0          #将软盘设备/dev/fd0自动挂载到/misc/floppy下
#floppy         -fstype=ext2            :/dev/fd0
#e2floppy       -fstype=ext2            :/dev/fd0
#jaz            -fstype=ext2            :/dev/sdc1
#removable      -fstype=ext2            :/dev/hdd

在server1的/etc/auto.misc文件中添加如下设置:

test1        -fstype=nfs,rw,nolock         server2:/var/spool/test1
test2        -fstype=nfs,rw,nolock         server2:/var/spool/test2
test3        -fstype=nfs,rw,nolock         server2:/var/spool/test3

保存后,cd /misc/test1 

server1就可以访问server2的共享目录了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值