加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

NFS 学习手记

(2007-01-08 22:25:24)
分类: 技术文章
 一。什么是NFS?
NFS是network file system即网络文件系统的意思,是主机间通过网络进行文件共享的网络协议,多用于局域网环境,用于多台主机共享同一主机上的文件资源,最早由Sun微系统公司作为TCP/IP网上的文件共享系统开发.NFS共享文件访问速度快,稳定性高等优点,多应用于工程系统中。un公司估计现在大约有超过310万个系统在运行NFS,大到大型计算机、小至PC机,其中至少有80%的系统是非Sun平台。
二。NFS的安装。
NFS的安装很简单,包括两个软件包:nfs-utils和portmap,NFS的安装过程如下:。
rpm -ivh portmap-4.0-65
rpm -ivh nfs-utils-1.0.7-8
注意:安装的时候要先安装portmap,因为portmap服务器为NFS服务提供rpc服务的支持。
安装完成后,查询下安装的情况:
[root@FC4 linux-fox]# rpm -q portmap
portmap-4.0-65
[root@FC4 linux-fox]# rpm -q nfs-utils
nfs-utils-1.0.7-8
三。NFS服务器的启动和停止。
1.NFS服务器的启动。
service portmap start
service nfs start     //启动的时候,portmap要先于nfs启动
2.NFS服务器的停止。
service nfs stop
service portmap stop   //如果又其他服务需要portmap服务,可以不停止它
四。NFS服务器的配置。
NFS服务器的配置文件是exports,路径为/etc/exports,默认情况下的设置为空,这即使系统启动nfs服务也不会提供任何的共享。
1.设置共享。
以共享/mnt/nfsshare为例:
vi /etc/exports  //用vi程序编辑exports文件,下面的命令输入到该文件中
/mnt/nfsshare    *(sync,ro)
:wq
该配置文件的格式如下:共享目录      客户端主机地址(设置选项)
2.客户端主机地址。
在exports文件中,客户端主机地址的指定非常灵活,具体如下:
客户端主机地址                                    说明
192.168.10.3                               指定ip地址的单个主机
192.168.1.2/100                            指定网段的所有主机
*.linux.com                                  指定域中的所有主机
fox.linux.cm                                  指定域名的主机
                                        所有主机
3.设置选项。
选项                                         说明
sync                                 设置nfs服务器同步写磁盘
ro                                   设置共享目录只读(read  only)
rw                                   设置共享目录可读写(read  write)
五。两个常用的命令。
1。showmount命令。
该命令用来查询NFS服务器的共享目录状态。
先看看man说明:
SHOWMOUNT(8)                                                      SHOWMOUNT(8)
NAME
       showmount - show mount information for an NFS server
SYNOPSIS
       /usr/sbin/showmount [ -adehv ] [ --all ] [ --directories ] [ --exports ] [ --help ] [ --version ] [ host ]
DESCRIPTION
       showmount  queries  the mount daemon on a remote host for information about the state of the NFS server on that machine.
       With no options showmount lists the set of clients who are mounting from  that  host.   The  output  from  showmount  is
       designed to appear as though it were processesed through ‘‘sort -u’’.
OPTIONS
       -a or --all
              List both the client hostname and mounted directory in host:dir format.
       -d or --directories
              List only the directories mounted by some client.
       -e or --exports
              Show the NFS server’s export list.
       -h or --help
              Provide a short help summary.
       -v or --version
              Report the current version number of the program.
       --no-headers
              Suppress the descriptive headings from the output.
showmount不加任何参数显示连接到指定NFS服务器的所有主机。
showmount -h        显示帮助信息。
showmount -a        以host:dir的格式列出所有客户端主机和被挂载的目录。
showmount -d        仅列出被客户端挂载的目录。
showmount -e        显示NFS服务器的输出目录列表。
showmount -v        显示程序的当前版本。
2.exportfs命令。
该目录用于维护当前主机的输出目录列表。
先看看man说明:
NAME
       exportfs - maintain list of NFS exported file systems
SYNOPSIS
       /usr/sbin/exportfs [-avi] [-o options,..] [client:/path ..]
       /usr/sbin/exportfs -r [-v]
       /usr/sbin/exportfs [-av] -u [client:/path ..]
       /usr/sbin/exportfs [-v]
       /usr/sbin/exportfs -f
DESCRIPTION
       The exportfs command is used to maintain the current table of exported file systems for NFS. This list is kept in a sep-
       arate file named /var/lib/nfs/xtab which is read by mountd when a remote host requests access to mount a file tree,  and
       parts of the list which are active are kept in the kernel’s export table.
       Normally  this xtab file is initialized with the list of all file systems named in /etc/exports by invoking exportfs -a.
       However, administrators can choose to add and delete  individual  file  systems  without  modifying  /etc/exports  using
       exportfs.
       exportfs  and  it’s partner program mountd work in one of two modes, a legacy mode which applies to 2.4 and earlier ver-
       sions of the Linux kernel, and a new mode which applies to 2.6 and later versions providing the nfsd virtual  filesystem
       has been mounted at /proc/fs/nfsd or /proc/fs/nfs.  If this filesystem is not mounted in 2.6, the legacy mode is used.
       In  the  new  mode,  exportfs  does  not  give  any information to the kernel but only provides it to mountd through the
       /var/lib/nfs/xtab file.  mountd will listen to requests from the kernel and will provide information as needed.
       In the legacy mode, any export requests which identify a specific host (rather  than   subnet  or  netgroup  etc)  are
       entered  directly  into  the  kernel’s  export  table as well as being written to /var/lib/nfs/xtab.  Further, any mount
       points listed in /var/lib/nfs/rmtab which match a non host-specific export request  will  cause  an  appropriate  export
       entry for the host given in rmtab to be entered into the kernel’s export table.
OPTIONS
       -a     Export or unexport all directories.
       -o options,...
              Specify a list of export options in the same manner as in exports(5).
       -i     Ignore the /etc/exports file, so that only default options and options given on the command line are used.
       -r     Reexport   all   directories.  It  synchronizes  /var/lib/nfs/xtab  with  /etc/exports.  It  removes  entries  in
              /var/lib/nfs/xtab which are deleted from /etc/exports, and remove any entries from the kernel export table  which
              are no longer valid.
-u     Unexport one or more directories.
       -f     In ’new’ mode, flush everything out of the kernels export table. Any clients that are active will get new entries
              added by mountd when they make their next request.
       -v     Be verbose. When exporting or unexporting, show what’s going on. When displaying the current  export  list,  also
              display the list of export options.

exportfs -a    输出或不输出所有的目录。
exportfs -r    重新输出所有的目录。
exportfs -v    显示相信信息。
exportfs -u    不输出一个或多个目录。

以上是我个人对NFS服务的肤浅认识,命令说明参考自man说明,由于水平有限,理解的偏差和翻译的错误在所难免,权当抛砖引玉,请linux高手多多指正。

                                           ------linux-fox
                                                2006/06/21

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有