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的共享目录了。