Thursday, 7 January 2010

Network File Service ( NFS)

A Network File System(NFS) allows remote hosts to mount file systems over the network and interact with those file systems as though they are mounted locally.
NFS v3 has got many features over older version of NFS ( NFS v2) like better error reporting, variable size file handling. NFS v2 uses UDP protocol which is stateless protocol so reduces network traffic but when server goes down client will clog the network with traffic with packets to search for NFS server. NFS v3 uses TCP as the default protocol.

Following are the services required to run a NFS server

1. portmap : The rpc service for Linux, maps calls made from other machines to the correct RPC services.
2. nfs: Starts the appropriate RPC processes to service requests for shared NFS file systems.
3. rpc.mountd : mounts and unmounts filesystems.
4. rpc.nfsd : NFS server process . This process corresponds to nfs service.

Other services are rpc.lockd, rpc.statd, rpc.rquotad

As already mentioned that NFS is a rpc process, so before starting nfs portmap service which actually maps rpc request to the correct services should be up and running. When a RPC service start , it notifies to portmap with the port no that they are monitoring and the RPC program number they expect to serve. Client system contacts portmap on the server with a particular RPC program number . The portmap service redirect the clinet to the proper port no so it can communicate with the requested service.

So before we go ahead with nfs server configuration , lets check the status of portmap service status and the RPC based services which is enabled for portmap
rpcinfo -p
or # service portmap status ( to check for only portmap status)

Configuration file

NFS server configuration file is /etc/exports which controls which filesystems are exported to remote hosts and specifies options.

Example:

/data linuxserver

where /data is exported filesystem and which can be accessed only from host( linuxserver). Without any options specifed , it will be mounted as read-only . To mount as rw mode , you need to specifically mentioned as given below

/data linuxserver(rw)

There are various options are available like wdelay, root_squash, all_squash. async and sync . For detailed explanation of each option , please visit the following link.
http://www.redhat.com/docs/manuals/enterprise/RHEL-3-Manual/ref-guide/s1-nfs-server-export.html

Once you are ready with the configuration file(/etc/exports) , start the nfs server (service nfs start)

Cool server configuration is done . Below are the few utilities which is useful to verify the exported list , refreshes the export list .
exporftfs -a
exportfs -v ( to view the exports and their options on the local machine).
showmount -e hostname (to display the exports from remote machine)
rpcinfo -p hostname ( used to probe the portmapper on hostname and print a list of all registered RPC services)
exportfs -u (unexport all shared directories)

Finally we are done with the server configuration . Now lets start with the client side configuration . Nothing much on the client side, we need to know various ways of mounting the remote filesystem.
NFS share mounted at boot time by /etc/init.d/netfs so check whether netfs service is running
chkconfig --list grep netfs

Option 1:

Using mount command
e.g mount linuxserver:/data /local/data

where linuserver is the hostname where /data is in the export list . /local/data is the mount point in the local machine .

Option 2:

No comments:

Post a Comment