Debian和Ubuntu Linux的NFS配置介绍



DebianUbuntuLinuxNFS配置介绍 2



安装配置nfs服务器

1安装
root@ubuntu:/# apt-get install nfs-commonnfs-kernel-server nfs-client
正在件包列表...完成
正在分析件包的依赖关
Reading state information... 完成
nfs-common 是最新的版本了。
nfs-kernel-server 是最新的版本了。
注意,我nfs-common 而非nfs-client
nfs-common 是最新的版本了。
共升0 件包,新安装了0 件包,要卸0 件包,有0 件未被升

2 配置
root@ubuntu:~# nano /etc/exports

#/etc/exports: the access control list for filesystems which may beexported
# to NFS clients. See exports(5).
#
# Example forNFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync)hostname2(ro,sync)
#
# Example for NFSv4:
# /srv/nfs4gss/krb5i(rw,sync,fsid=0,crossmnt)
# /srv/nfs4/homesgss/krb5i(rw,sync)
/home/cache/netboot192.168.1.0/24(rw,no_root_squash,sync)
(注*上面一行是服器端提供的磁的位置,可以是服器的任一目,建将一个独的磁分区挂在个目下。但是注意:个服器端的/home/cache/netboot并不是将来客端的虚根目,因/home/cache/netboot下面将会有一个名root的子目,而/home/cache/netboot/root才是本文中的客端的虚根目,在启完成后、实际运行程中,工作就局限在/home/cache/netboot/root中了。建立root问题下文将会到)

3 nfs或者重新加
nfs
root@ubuntu:/#/etc/init.d/nfs-kernel-server start
* Exporting directories forNFS kernel daemon...
exportfs: /etc/exports [1]: Neither'subtree_check' or 'no_subtree_check' specified for export"192.168.1.0/24:/home/cache/netboot".
Assuming defaultbehaviour ('no_subtree_check').
NOTE: this default has changedsince nfs-utils version 1.0.x
...done.
* Starting NFS kerneldaemon
...done.
如果是修改了/etc/exports配置文件,不需要重新启nfs器,只需要刷新一下,命令如下
root@ubuntu:/# exportfs -r
exportfs:/etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check'specified for export "192.168.1.0/24:/home/cache/netboot".
Assumingdefault behaviour ('no_subtree_check').
NOTE: this default haschanged since nfs-utils version 1.0.x



DebianUbuntuLinuxNFS配置介绍

NFSNetworkFile System文件系)可以通将分享不同主机(不同的OS)的目——可以通NFS载远程主机的目访问该就像访问本地目
 
  一般而言,使用nfs方便地使各unix-like间实现共享。但如果需要在unix-likewindows共享,就得使用samba了!
 
  NFS运行在SUNRPCRemoteProcedure Call用)基上,RPC了一与系的方法来实现进通信。由此, NFSserver也可以看作是RPCserver.
 
  正因NFS是一个RPC程序,所以在使用它之前,先要映射好端口——portmap定。比如: 某个NFSclientNFS务请它需要先得到一个端口(port)。所以它先通portmap得到portnumber. (不NFS所有的RPC程序启之前,都需要定好portmap
 
  在启RPC(比如NFS)之前,需要启portmap!(nfsportmap是否存在于当前系看后面的"NFS安装"部分。
 
  与NFS的几个文件,命令
 
  1/etc/exports
 
  NFS卷的访问是由exports来批准,它枚了若干有权访问NFS器上文件系的主机名。
 bitscn_com
  2/sbin/exportfs
 
  维护NFS源共享。可以通它重新/etc/exports 的共享目NFSServer共享的目或者重新共享等。
 
  3/usr/sbin/showmount
 
  用在NFS Server 端,而showmount 主要用在Client 端。showmount 可以用來NFS共享的目录资源。
 
  4/var/lib/nfs/xtab
 
  NFS记录文档:它可以看有哪些Client接到NFS主机的记录
 
  下面几个并不直接负责NFS实际上它们负责所有的RPC
 
  5/etc/default/portmap
 
  实际上,portmap负责映射所有的RPC端口,它的内容非常非常之简单(后面述)
 
  6/etc/hosts.deny
 
  定拒portmap的主机
 
  7/etc/hosts.allow
 
  定允portmap的主机
 
  安装NFS
 
  Debian/Ubuntu上默是没有安装NFS器的,首先要安装NFS程序:
 
  $sudo apt-get installnfs-kernel-server
 
  (安装nfs-kernel-serverapt会自安装nfs-commonportmap
 
  这样,宿主机就相当于NFSServer.
 
  同地,目NFS的客端,需要安装NFS端程序。如果是Debian/Ubuntu需要安装nfs-common.

feedom.net


 
  $sudo apt-get installnfs-commmon
 
  nfs-commonnfs-kernel-server都依portmap
 
  配置NFS
 
  由于NFS是一个RPCserver程序。portmap是用来挂你RPC的端口号映射的。所以先要配置portmap.
 
  配置portmap
 
  方法1编辑/etc/default/portmap -i127.0.0.1 去掉。
 
  方法2 sudodpkg-reconfigure portmap Shouldportmap be bound to the loopback addressN.
 
  配置/etc/hosts.deny
 
  (禁止任何host(主机)能和你的NFSNFS接),加入:
 
  ###NFSDAEMONS
 
  portmapALL
 
  lockdALL
 
  mountdALL
 
  rquotadALL
 
  statdALL
 
  配置/etc/hosts.allow
 
  允那些你想要的主机和你的NFS器建立接。下列步骤将允任何IP地址以192.168.2开头的主机(接到NFS器上),也可以指定特定的IP地址。参看manhosts_access5),hosts_options5)。加入:
 
  ###NFS DAEMONS
 
  portmap192.168.2.
 
  lockd192.168.2. 网管网bitsCN_com
 
  rquotad192.168.2.
 
  mountd192.168.2.
 
  statd192.168.2.
 
  /etc/hosts.deny /etc/hosts.allow portmap访问采用两个配置文件有点"mask"的意思。/etc/hosts.deny中禁止所有用户对portmap访问再在/etc/hosts.allow中允某些用户对portmap访问
 
  运行 sudo/etc/init.d/portmap restart 重启portmapdaemon.
 
  配置/etc/exports
 
  NFS限由/etc/exports文件定
 
  比如我要将将我的home中的/home/zp/share录让192.168.2.*IP共享,文件末尾添加下列句:
 
  /home/zp/share192.168.2.*rwsyncno_root_squash
 
  或者:/home/zp/share192.168.2.0/24rwsyncno_root_squash
 
  192.168.2.*网段内的NFS端能共享NFS/home/zp/share内容。且有,写限,并且户进/home/zp/share后的身份root
 
  最好加上sync sudoexportfs -r 出警告,syncNFS的默认选项
 
  运行 showmount-e NFSserverexportlist.

网管网bitsCN.com


 
  若更改了/etc/exports运行 sudo exportfs -r 更新
 
  运行 sudo/etc/init.d/nfs-kernel-server restart重启nfs
 
  /etc/exports实际上就是nfs器的核心配置文件了。哥的Linux私房菜列了一些exports文件的写法。
 
  测试NFS
 
  可以尝试一下挂本地磁(假本地主机IP地址192.128.2.1,将/home/zp/share/mnt
 
  $sudo mount 192.168.2.1/home/zp/share/mnt
 
  运行 df看看
 
  $sudo umount /mnt
 
  注意被拷文件的/写限!
 
  另外,可以使用一定的参数:
 
  使用加参数的法:mount-o nolockrsize=1024wsize=1024timeo=15192.168.2.130/tmp//tmp/




你可能感兴趣的:(Debian和Ubuntu Linux的NFS配置介绍)