NFS Server
1. Introduction
2. NFS Server
2.1 Creating the exports
2.2 Tune the NFS server
3. NFS Clients
4. Useful NFS Related Commands
4.1 Query RPC services
4.2 Show NFS exports
4.3 NFS statistics
4.4 Show detailed mount infomartion
5. Simple Performance Testing
5.1 Write test
5.2 Read test
Introduction
I use NFS to provide simple NAS services to my home network. I'll be exporting the directories '/home' and '/srv/media' on the NFS server so they are accessible to NFS clients on my home network. This is a really simple setup, which is not super secure, but ideal for my needs at home. I want the '/srv/media' export to be read/write to all clients on my home network so we can share a common source of Shared Documents, Music, Pictures, Videos, etc. Each user also mounts their own home directory, on the NFS server, for personal data.NFS Server
sudo aptitude install nfs-kernel-server
Creating the exports
A NFS clients typically access an NFS share as the user 'nobody'. However, the '/home' directory isn't owned by 'nobody', it is owned by the user. In order to enable read and write access to the '/home' export via NFS we need to instruct the NFS server that all accesses should be made as 'root' to the '/home' export. However, the '/srv/media' directory doesn't exist, so we can create it and change ownership to 'nobody' and 'nogroup'.mkdir -p /srv/media/Backups mkdir -p /srv/media/Documents mkdir -p /srv/media/Music mkdir -p /srv/media/Podcasts mkdir -p /srv/media/Pictures mkdir -p /srv/media/Videos chown -R nobody:nogroup /srv/media chmod 2775 /srv/mediaSetup the NFS exports.
sudo nano /etc/exportsSample
/home 192.168.1.0/24(rw,sync,no_root_squash,no_subtree_check) /srv/media 192.168.1.0/24(rw,sync,all_squash,no_subtree_check)Whenever '/etc/exports' is modified, you need to run...
exportfs -r -v...to re-export the new file systems.
Tune the NFS server
I am running my NFS server on an NLSU2 with just 32mb RAM, therefore I tweak the NFS server a little to try and use less resources.nano /etc/default/nfs-kernel-serverSample
# Number of servers to start up RPCNFSDCOUNT=2 # Do you want to start the svcgssd daemon? It is only required for Kerberos # exports. Valid alternatives are "yes" and "no"; the default is "no". NEED_SVCGSSD=noMore NFS server tuning.
vi /etc/default/nfs-commonSample
# Do you want to start the idmapd daemon? It is only needed for NFSv4. NEED_IDMAPD=no # Do you want to start the gssd daemon? It is required for Kerberos mounts. NEED_GSSD=no
NFS Clients
sudo aptitude install nfs-commonMake the mount points
mkdir -p ~/Backups mkdir -p ~/Documents mkdir -p ~/Public mkdir -p ~/Music mkdir -p ~/Podcasts mkdir -p ~/Pictures mkdir -p ~/VideosSetup the fstab, so that the exports will be automatically mounted at boot time.
sudo nano /etc/fstabSample
slug:/home/username /home/username/Documents nfs defaults 0 0 slug:/srv/media/Backups /home/username/Backups nfs defaults 0 0 slug:/srv/media/Music /home/username/Music nfs defaults 0 0 slug:/srv/media/Podcasts /home/username/Podcasts nfs defaults 0 0 slug:/srv/media/Pictures /home/username/Pictures nfs defaults 0 0 slug:/srv/media/shared-Documents /home/username/Public nfs defaults 0 0 slug:/srv/media/Videos /home/username/Videos nfs defaults 0 0You will notice that one of my mount points has a space in the name. From the fstab man page...
The second field, (fs_file), describes the mount point for the filesystem. For swap partitions, this field should be specified as ‘none’. If the name of the mount point contains spaces these can be escaped as ‘\040’.You could mount each NFS export manually now they are in fstab, such as...
sudo mount /home/username/DocumentsOr, you can just mount them all...
sudo mount -a
Useful NFS Related Commands
Query RPC services
rpcinfo -p slug
Show NFS exports
showmount -e slug
NFS statistics
nfsstat
Show detailed mount infomartion
cat /proc/mounts
Simple Performance Testing
The default Debian NFS mount options are optimal, you can measure the performance as follows.Write test
Where '/mnt/test' is a NFS mounted filesystem.time dd if=/dev/zero of=/mnt/test/benchmark bs=1024k count=1024Output
1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 230.803 seconds, 4.7 MB/s real 3m51.018s user 0m0.008s sys 0m13.097s
Read test
Where '/mnt/test' is a NFS mounted filesystem.time dd if=/mnt/test/benchmark of=/dev/null bs=1024kOutput
1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 150.198 seconds, 7.1 MB/s real 2m30.283s user 0m0.016s sys 0m1.472sMake sure you clean up afterwards ;-)
rm /mnt/test/benchmarkReferences
- http://www.nslu2-linux.org/wiki/DebianSlug/SetupNFSServer
- http://www.crazysquirrel.com/computing/debian/servers/nfs.jspx
- http://www.howtoforge.net/nfs-server-and-client-debian-etch
- http://rivendell.tryphon.org/wiki/index.php/Setting_up_a_dedicated_Rivendell_MySQL_and_audio_store_server
$Id: NFSServer,v 1.25 2008/07/05 08:39:53 martin Exp $
Wiki Index All Recent Edit Top

