Tuesday, February 8, 2011

NFS (Network File System ) Tutorial

NFS was developed to allow a computer system to access directories on remote computers by mounting them on a local filesystem as if they were a local disk. The systems administrator on the NFS server has to define the directories that need to be activated, or exported, for access by the NFS clients, and administrators on the clients need to define both the NFS server and the subset of its exported directories to use. 

Key NFS Concepts


VFS

The virtual filesystem (VFS) interface is the mechanism used by NFS to transparently and automatically redirect all access to NFS-mounted files to the remote server. This is done in such a way that files on the remote NFS server appear to the user to be no different than those on a local disk.
VFS also translates these requests to match the actual filesystem format on the NFS server's disks. This allows the NFS server to be not only a completely different operating system, but also use different naming schemes for files with different file attribute types.

NFS Versions

Three versions of NFS are available currently: versions 2, 3, and 4.  version 2, which:
  • Supports files up to 4GB long
  • Requires an NFS server to successfully write data to its disks before the write request is considered successful
  • Has a limit of 8KB per read or write request.
The main differences with version 3 are that it
  • Supports extremely large file sizes of up to 264 - 1 bytes
  • Supports the NFS server data updates as being successful when the data is written to the server's cache
  • Negotiates the data limit per read or write request between the client and server to a mutually decided optimal value.
Version 4 maintains many of version 3's features, but with the additions that
  • File locking and mounting are integrated in the NFS daemon and operate on a single, well known TCP port, making network security easier
  • File locking is mandatory, whereas before it was optional
  • Support for the bundling of requests from each client provides more efficient processing by the NFS server.
It is important to match the versions of NFS running on clients and server to help ensure the necessary compatibility to get NFS to work predictably.

Important NFS Daemons

  • rpcbind: (portmap in older versions of Linux) The primary daemon upon which all the others rely, rpcbind manages connections for applications that use the RPC specification. By default, rpcbind listens to TCP port 111 on which an initial connection is made. This is then used to negotiate a range of TCP ports, usually above port 1024, to be used for subsequent data transfers. You need to run rpcbind on both the NFS server and client.
  • nfs: Starts the RPC processes needed to serve shared NFS file systems. The nfs daemon needs to be run on the NFS server only.
  • nfslock: Used to allow NFS clients to lock files on the server via RPC processes. The nfslock daemon needs to be run on both the NFS server and client.
  • netfs: Allows RPC processes run on NFS clients to mount NFS filesystems on the server. The netfs daemon needs to be run on the NFS client only. 

Configuring NFS on The Server

The /etc/exports file is the main NFS configuration file, and it consists of two columns. The first column lists the directories you want to make available to the network. The second column has two parts. The first part lists the networks or DNS domains that can get access to the directory, and the second part lists NFS options in brackets.

In all cases, use the sync option to ensure that file data cached in memory is automatically written to the disk after the completion of any disk data copying operation.
#/etc/exports
/data/files           *(ro,sync)
/home                 192.168.1.0/24(rw,sync)
/data/test            *.my-site.com(rw,sync)
/data/database        192.168.1.203/32(rw,sync)
After configuring your /etc/exports file, you need to activate the settings, but first make sure that NFS is running correctly.

Starting NFS on the Server

chkconfig --level 35 nfs on
chkconfig --level 35 nfslock on 
chkconfig --level 35 rpcbind on
Test whether NFS is running correctly with the rpcinfo command. 
rpcinfo -p localhost

Configuring NFS on The Client

chkconfig --level 35 netfs on
chkconfig --level 35 nfslock on
chkconfig --level 35 rpcbind on

Troubleshooting NFS

Too many levels of remote in path Attempting to mount a filesystem that has already been mounted.
Permission denied User is denied access. This could be the client's root user who has unprivileged status on the server due to the root_squash option. Could also be because the user on the client doesn't exist on the server.
No such host Typographical or DNS configuration error in the name of the server.
No such file or directory Typographical error in the name of the file or directory: they don't exist.
NFS server is not responding The server could be overloaded or down.
Stale file handle A file that was previously accessed by the client was deleted on the server before the client closed it.
Fake hostname Forward and reverse DNS entries don't exist for the NFS client.

The nfsstat Command

The nfsstat command provides useful error statistics. The -s option provides NFS server stats, while the -c option provides them of for clients. Threshold guidelines are provided in below mentioned table
nfsstat -s
Server rpc stats:
calls      badcalls   badauth    badclnt    xdrcall
1547       0          0          0          0
Server nfs v2:
null       getattr    setattr    root       lookup     readlink
244    100% 0       0% 0       0% 0       0% 0       0% 0       0%
read       wrcache    write      create     remove     rename
0       0% 0       0% 0       0% 0       0% 0       0% 0       0%
link       symlink    mkdir      rmdir      readdir    fsstat
0       0% 0       0% 0       0% 0       0% 0       0% 0       0%
 
Server nfs v3:
null       getattr    setattr    lookup     access     readlink
251    19% 332    25% 0       0% 265    20% 320    24% 0       0%
read       write      create     mkdir      symlink    mknod
39      2% 14      1% 1       0% 1       0% 0       0% 0       0%
remove     rmdir      rename     link       readdir     readdirplus
0       0% 0       0% 0       0% 0       0% 0       0% 31       2%
fsstat     fsinfo     pathconf   commit
1       0% 34      2% 0       0% 14      1%
 

Error Thresholds For The "nfsstat" Command

Value Threshold Description
readlink > 10% Excessive numbers of symbolic links slowing performance. Try to replace them with a directory and mount the filesystem directly on this new mount point.
getattr > 50% File attributes, like file data, is cached in NFS. This value tracks the percentage of file attribute reads that are not from cache refresh requests. Usually caused by the NFS "noac" mount option which prevents file attribute caching.
badcalls > 0 Bad RPC requests. Could be due to poorly configured authentication, the root user attempting to access data governed by the "root_squash" directive or having a user in too many groups.
retrans > 5% Percentage of requests for service that the client had to retransmit to the servers. Could be due to slow NFS servers or poor network conditions.
writes > 10% Writes are slow due to poor caching values. Check the "noac" and "wsize" mount options.
read > 10% Reads are slow due to poor caching values. Check the "noac" and "rsize" mount options.

 

Note that this document comes without warranty of any kind. But every effort has been made to provide the information as accurate as possible. I welcome emails from any readers with comments, suggestions, and corrections at webmaster_at admin@linuxhowto.in

Copyright © 2012 LINUXHOWTO.IN




3 comments:

  1. شركة الطيار تعتبر افضل شركة تنظيف شقق بالدمام نقوم بتنظيف الشقق و الفلل بمدينة الدمام بافضل المكينات و الطرق الحديثة حيث اننا كما اننا نعتبر افضل شركة شركة كشف تسربات المياه بالرياض
    نقوم بتنظيف الشقق من الداخل جزء جزء علكم ان تتصلو علي شركة الطيار باسرع وقت ممكن لاننا افضل شركة تنظيف فلل بالدمام يمكنك معرفة المزيد حول الخدمة شركة كشف تسربات المياه بالاحساء

    ReplyDelete