Wednesday 1 May 2013

How to Setup NFS Server in Linux

NFS depends on the portmapper daemon
/etc/init.d/portmap start
/etc/init.d/portmap status

Providing NFS service requires the service of si daemons,

portmap:Enables NFS clients to discover the NFS services

         available on a given NFS server
nfsd   :provides all NFS services except file locking and

         quota management
lockd  :Starts the kernels NFS lock manager
statd  :Implements NFS lock recovery when an NFS server

        system crashes
rquotad:Handles user file quotas on exported volumes to NFS

        clients
mountd : Processes NFS client mount requests

The daemons are all part of the nfs-utils package. If your distribution does not include them in the startup scripts, then you should add them and configure it to start in the following

order,
  portmap
  nfsd
  mountd
  statd
  rquotad (if necessary)

The nfs-utils package has a sample startup script for redhat and the script will take care of starting all the NFS server daemons for you except the portmapper.

/etc/rc.d/init.d/nfs start/stop/status/restart
/etc/init.d/portmap start
/etc/init.d/nfs start
/etc/init.d/nfslock start


Verifying that NFS is running

To do this, query the portmapper with the command 


# rpcinfo -p
 

to find out what services it is providing. You should get something like this:

# rpcinfo -p portmapper

Making changes to /etc/exports later on

If you come back and change your /etc/exports file, the changes you make may not take effect immediately.  You should therefore run the command


# rpcinfo -pra -- to force nfsd to re-read the /etc/exports file. If you can't find exportfs command, then you can kill nfsd and restart it.

exportfs command will also let you manipulate the list of available exports or list the currently exported file systems

# exportfs -v // List currently exported file systems

# exportfs -v -u 192.168.0.25:/home // remove an exported 

         file system

Setting up an NFS Client

1. Mounting remote directories:

Firstly, kernal on the client machine needs to be compiled with NFS support.

Portmapper should be running on the client machine and to use NFS file locking you also need statd and lockd running on both the client and the server. With portmap,lockd, and statd running you should now be able to mount the remote directory from your server just the way you mount a local hard drive, with the mount command

mounting home dir of master.com to slave.com

 # mount -t nfs 192.168.0.25:/home /home1 OR
 # mount -t nfs 192.168.0.25:/home /home1 -o -rw,soft

to unmount the file system

# umount /home1
 

Getting NFS file system to be mounted at boot time

NFS file systems can be added to /etc/fstab, the only difference is that the file system type will be set to nfs and the dump and fsck order will have to
be set to zero.

ex:
   

Device        mountpoint fs-type options dump fsckorder
host.com:/home  /home1    nfs      rw     0     0


No comments:

Post a Comment