NFSv3

From ArchWiki
Revision as of 15:18, 23 May 2008 by Progdan (Talk | contribs) (Added link to czech version)

Jump to: navigation, search

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n links end

Goals

The goal of this article is setting up a nfs-server for sharing files over a network. We'll keep it simple here, so everything should be pretty much understandable. Note: for NFSv4, see NFSv4

Required packages

Required packages for both the server and the client are minimal.
You'll only need to install:

  • core/portmap
  • core/nfs-utils

As both packages are in the [core] repository, they will be included by default in new Arch installations.

Setting up the server

You can now edit your configuration and start the daemons. You need to be root to execute the following commands.

Files

/etc/exports

This file (/etc/exports) defines the various shares on the nfs server, and their permissions.
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

If you make changes to /etc/exports after starting the daemons, you can make them effective by issuing the following command:

exportfs -r

If you decide to make your NFS share public and writable, you can use the all_squash option in combination with anonuid and the anongid option. For example, to set the privileges for the user nobody in the group nobody, you can do the following:

; 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))

This also means, that if you want write access to this directory, nobody.nobody must be the owner of the share directory:

chown -R nobody.nobody /files

Full details on the exports file are provided by the exports man page.

/etc/conf.d/nfs

Edit this file to pass appropriate run-time options to nfsd, mountd, statd, and sm-notify. The default Arch NFS init scripts require the --no-notify option for statd, as follows:

STATD_OPTS="--no-notify"

Others may be left at the provided defaults, or changed according to your requirements. Please refer to the relevant man pages for full details.

/etc/hosts.allow

To allow network access to the nfs server you should edit /etc/hosts.allow.
The following example opens these services to anyone:

 nfsd: ALL
 portmap: ALL
 mountd:ALL

For finer control, read the hosts_access(5) man page.

Daemons

You can now start the server with the following commands:

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

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

Setting up the client

Files

/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.

Daemons

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

Auto-mount on boot

If you want to mount on boot, make sure netfs is in the DAEMONS array in /etc/rc.conf, and add an appropriate line in /etc/fstab, for example:

server:/files /files nfs defaults 0 0

If you wish to specify a packet size for read and write packets, specify them in your fstab entry. The values listed below are the defaults if none are specified:

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

Read the nfs man page for further information, including all available mount options.

Troubleshooting

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 .

Links & References

Very helpful