NFS (简体中文)

From ArchWiki

Jump to: navigation, search
Image:Tango-preferences-desktop-locale.png This page was marked to be translated.
If you understand both "original" and "target" languages of this page, please help complete the translation.
i18n
English
Italiano
Русский
Česky
简体中文

Contents

目标

这篇文档的目的是建立一个通过网络共享文件的nfs服务器。我们将尽可能的使其简单,容易理解。 备注: 查看更多关于 NFSv4 的信息

必须的软件包

服务器端和客户端所需要的软件包都是很少的。
你只需要安装:

  • core/portmap
  • core/nfs-utils

这两个软件包都在 [core] repository 中, 新的Arch会默认包含他们。

安装服务器端

现在你可以编辑配置文件(configuration),启动守护进程。需要以root身份运行以下命令。


文件

/etc/exports

这个文件(/ect/exports)定义了服务器端不同的共享,及其权限。
A few examples:

/files *(ro,sync) ; Read-only access to anyone
/files 192.168.0.100(rw,sync) ; Read-write access to a client on 192.168.0.100
/files 192.168.1.1/24(rw,sync) ;  Read-write access to all clients from 192.168.1.1 to 192.168.1.255

如果你在启动守护进程后修改了 /etc/exports,可以通过以下命令使其立即生效:

exportfs -r

如果希望NFS共享是公开(public)和可写(writable),可和 anonuid 选项,anongid 选项一起使用 all_squash 选项。 例如,给 nobody 组中的用户 nobody 设定优先级,可以:

; Read-write access to a client on 192.168.0.100, with rw access for the user 99 with gid 99
/files 192.168.0.100(rw,sync,all_squash,anonuid=99,anongid=99))

这也意味着,如果想对这个目录拥有写权限,nobody.nobody 必须是共享目录的所有者(owner)。

chown -R nobody.nobody /files

exports 文件的详细信息请参考 exports 的man page。

/etc/conf.d/nfs

编辑这个文件以传递合适(appropriate)的运行选项给 nfsd, mountd, statd, 和 sm-notify。默认的 Arch NFS 初始化脚本(init scripts)要求 --no-notify 参数的 statd 选项,如下:

 STATD_OPTS="--no-notify"

其他的选项可采用默认,或者根据需要修改。 详细信息请参考相应的man pages。

/etc/hosts.allow

编辑 /etc/hosts.allow ,允许对nfs 服务器的网络访问。
下面的例子对所有人打开这些服务:

 nfsd: ALL
 portmap: ALL
 mountd:ALL

这样运行网络访问是非常不安全的(This is a very insecure way of allowing host access)。 To get better control over who is allowed to access the daemons hosts.deny should be everyone, and hosts.allow should specifically allow certain people. In this example, 192.168.0.101 should be the IP address of the person(s) allowed to access it.

 nfsd: 192.168.0.101/255.255.255.0
 portmap: 192.168.0.101/255.255.255.0
 mountd: 192.168.0.101/255.255.255.0

希望得到更好的控制,请参看 hosts_access(5) man page.

守护进程

你可以用如下命令开启NFS服务程序:

/etc/rc.d/portmap start
/etc/rc.d/nfslock start
/etc/rc.d/nfsd start

请注意,必须按照如上顺序启动.
可以将portmap nfslock nfsd 依次加入到/etc/rc.conf的DAEMONS中以使NFS服务程序一开始就启动.

设置客户端

文件

/etc/conf.d/nfs

Edit this file to pass appropriate run-time options to statd - the remaining options are for server use only. Do NOT use the --no-notify option on the client side, unless you are fully aware of the consequences of doing so.

Please refer to the statd man page for full details.

守护进程

Start the portmap and nfslock daemons:

/etc/rc.d/portmap start
/etc/rc.d/nfslock start

Please note that they must be started in that order.
To start the daemons at boot time, add them to the DAEMONS array in /etc/rc.conf.

Then just mount as normal:

mount server:/files /files

启动时自动挂载

欲使网络文件夹在启动时自动挂载,须确保netfs在/etc/rc.confDAEMONS行中,且在/etc/fstab 中有相应设置,例如:

server:/files /files nfs defaults 0 0

如果你要指定读写数据包的大小,可以在fstab中设置。如下所列数据为默认值:

server:/files /files nfs rsize=32768,wsize=32768 0 0

man nfs 以获取更多信息,包括可用的挂载选项等.

疑难问题解决

Unreliable performance, slow data transfer, and/or high load when using NFS and gigabit

This is a result of the default packetsize used by NFS, which causes significant fragmentation on gigabit networks. You can modify this behavior by the rsize and wsize mount parameters. Using rsize=32768,wsize=32768 should suffice. Please note that this problem does not occur on 100Mb networks, due to the lower packet transfer speed.

Note: Default value for NFS4 is 32768. Maximum is 65536. Increase from default in increments of 1024 until maximum transfer rate is achieved.

Portmap daemon fails to start at boot

Make sure you place portmap BEFORE netfs in the daemons array in /etc/rc.conf .

参考链接

HOWTO: Diskless network boot NFS root
Very helpful

Personal tools