nfs既是服务又是文件系统
时间:2006-12-04 来源:适兕
想像一下,一个高可用的服务集群,没有共享的、奢侈的存储阵列,只有一台古老的、廉价的PC. NFS是最佳选择。
The Network File System (NFS) was developed to allow machines to mount a disk partition on a remote machine as if it were a local disk. It allows for fast, seamless sharing of files across a network.
废话就尽量不多说了,从实用的角度来讲,那就是如何让这个服务活起来并正常使用:
一、运行的依赖服务
portmap(portmap 服务是用于 RPC 服务(如 NIS 和 NFS)的动态端口分配守护进程) 设置 portmap 只对 NFSv2 和 NFSv3 起作用,NFSv4 不再使用这个服务。
二、相关的配置文件
/etc/exports /etc/host.allow /etc/host.deny
1、/etc/exports文件的各选项属性
目录 客户机(属性值)
客户机可以列出主机名,也可以是无间或路由(DNS address or their IP address 。
属性值有下面几种
- ro: The directory is shared read only; the client machine will not be able to write it. This is the default.
- rw: The client machine will have read and write access to the directory.
- no_root_squash: By default, any file request made by user root on the client machine is treated as if it is made by user nobody on the server. (Exactly which UID the request is mapped to depends on the UID of user "nobody" on the server, not the client.) If no_root_squash is selected, then root on the client machine will have the same level of access to the files on the system as root on the server. This can have serious security implications, although it may be necessary if you want to perform any administrative work on the client machine that involves the exported directories. You should not specify this option without a good reason.
- no_subtree_check: If only part of a volume is exported, a routine called subtree checking verifies that a file that is requested from the client is in the appropriate part of the volume. If the entire volume is exported, disabling this check will speed up transfers.
- sync: By default, all but the most recent version (version 1.11) of the exportfs command will use async behavior, telling a client machine that a file write is complete - that is, has been written to stable storage - when NFS has finished handing the write over to the filesystem. This behavior may cause data corruption if the server reboots, and the sync option prevents this
- 注意最后一项属性值。是绝对重要的。。。
3 /etc/host.deny
此两项略过。
三、启动服务
/etc/init.d/portmap start
/etc/init.d/nfs start
四、检查服务
[root@lee media]# rpcinfo -p lee.redflag
程序 版本 协议 端口
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
391002 2 tcp 59108 sgi_fam
100011 1 udp 995 rquotad
100011 2 udp 995 rquotad
100011 1 tcp 998 rquotad
100011 2 tcp 998 rquotad
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100021 1 udp 1195 nlockmgr
100021 3 udp 1195 nlockmgr
100021 4 udp 1195 nlockmgr
100021 1 tcp 25131 nlockmgr
100021 3 tcp 25131 nlockmgr
100021 4 tcp 25131 nlockmgr
100005 1 udp 1012 mountd
100005 1 tcp 1015 mountd
100005 2 udp 1012 mountd
100005 2 tcp 1015 mountd
100005 3 udp 1012 mountd
100005 3 tcp 1015 mountd
五、挂接到本地,
mount ip:/directory/ /media/xxx/
enjoy it!
如果要理解其原理,深入到其安全、稳定等因素,那么就需要深究了。下面是两个连接
http://nfs.sourceforge.net/nfs-howto/
http://www.ietf.org/rfc/rfc3530.txt
还有就是要理会一下sun的rpc原理。
2007-8-27补充:
又汗了一把,竟然从未听到过autofs.以学习为准;以下是一些其内容:
如果使用手工mount的方法访问一个NFS共享, 重新启动系统后这个文件系统必须mount才可以使用,Linux提供了两种方法来自动的挂载远程文件系统。/etc/fstab和autofs服务.
autofs 服务会根据/etc/auto.master文件来控制自动挂载命令:automount的命令可以更加方便的指定挂载点,主机名, 输出目录等等。
autofs的配置文件以父-子关系来组织,主配置文件(/etc/auto.master) 列出了所有的挂载点,然后他会连接到一个特定的映射类型, 这个类型可以是配置文件,程序, NIS映射或者其他挂载方式,auto.master文件包含了如下内容。
<mount-point> <map-type>
<mount-point>用于指定本地挂载点,<map-type>指定如何挂载,最通常的NFS挂载做法是使用一个文件,这个文件通常命名成auto.<mount-point>, <mount-point>是在auto.master指定的挂载点,一个NFS类型的auto.<mount-point>的内容如下:
</local/directory> -<options> <server>:</remote/export>
使用本地挂载点替换 </local/directory;> ,该目录必须手动创建。
可以使用nfs的选项替换 <options> ,多个选项之间使用“,”分开,如果需要更多的信息查看man fstab. 确定在options列表前使用了符号"-"。
使用你的NFS服务器替换如上的 <server> ,
使用NFS服务器的输出路径替换如上的 </remote/export> .
可以使用nfs的选项替换 <options>
autofs配置文件可以用于很多中挂载方式和不同的文件系统上,特使是在NFS的挂载上特别有用,举例来说,有些单位把所有的/home目录集中于一台NFS服务器上, 然后在每个节点上配置auto.master指向auto.home,使得每个节点都可以通过autofs挂载/home目录。所有的用户都可以在任何一台工作站上访问自己/home/下的的数据和配置文件,该案中的auto.master看起来会像如下所示。
/home /etc/auto.home
这个文件设置了/home/挂载点被配置到了/etc/auto.home文件上,auto.home看起来应该如下:
* -fstype=nfs,soft,intr,rsize=8192,wsize=8192,nosuid,tcp server.example.com:/home
这个文件显示了如果用户所要访问/home下的一个目录,它应该产生一个到nfs.example.com的NFS mount, mount的选项说明了每个/home下的目录都会使用各自的设定.