Wednesday, 12 August 2015

Network File System (NFS) Server, Client configurations


Requirements:

 
  • Server System OS installed. For this tutorial I used FBSD9.2
  • Disk Freespace.
  • Client System: This can be any windows or Linux/Unix. In this tutorial I used Unix  Linux/Unix Client.
Server Configurations:
 
Lets begin:
  1.  % su
  2.  # echo 'nfs_server_enable="YES"' >> /etc/rc.conf
  3.  # echo 'rpcbind_enable="YES"' >> /etc/rc.conf
  4.  # echo 'mountd_flags="r"' >> /etc/rc.conf
  5.  # echo 'rpc_lockd_enable="YES"' >> /etc/rc.conf
  6.  # echo 'rpc_statd_enable="YES"' >> /etc/rc.conf
  7.  # echo 'nfs_server_flags="-u -t -n 4"' >> /etc/rc.conf

By passing these options we guarantee that NFS related daemons are started at boot time. Steps 2 to 4 are mandatory and enable the NFS daemons, steps 5, 6 and 7 are optional and are used to guarantee file locking operations over NFS and monitor NFS client so that the NFS server can free resources when the host disappears.
Lets proceed by identifying what we want to share:
  •  % su
  •  # vi /etc/exports
  •  add the following line:
  • /usr/ports/distfiles network 192.168.1 mask 255.255.255.0
 
 

This shares the /usr/ports/distfiles directory and make it available to any client with an IP address beginning in 192.168.1 and netmask of 255.255.255.0.

Now that we've enabled the NFS server settings and configured the exports file, lets start the server


by:


1. % su
2. # rpcbind
3. # nfsd -u -t -n 4
4. # mountd -r

If you perform any changes changes to the exports file, reload it by:
 
1. % su

2. # /etc/rc.d/mountd onereload

Also, the showmount command can be used to display the exports on the server:



1. % su
2. # showmount e


I've focused on the basis to setup a home network NFS share, however there are loads of performance tuning flags that can be set on both server and client sides.


 
 NFS Client Side Configurations
To allow the machine to access NFS shares you need to add the following to /etc/rc.conf
#echo 'nfs_client_enable="YES"' >> /etc/rc.conf

Mounting NFS Shares
Mounting NFS shares can be done with the following command
 
#mount_nfs machine:dir localdirectory
So in my case here is the command.
#mount_nfs 192.168.1.27:/media/nfs-share /usr/nfs-client
 
For example if we were mounting the music folder from the server in the example above to a folder called /mymusic on our machine it would look like this
mount_nfs eclipse:/music /mymusic
 
Auto Mounting Shares
 
 
NFS shares can be automatically mounted by putting them into /etc/fstab An example of auto mounting the mount we just made above is shown below

# Device Mountpoint FStype Options Dump Pass#

   eclipse:/music /mymusic nfs rw 2 2
 
 


Lessons Learned

  1. Don't Share directory from "/" or "/root/"  location. This may cause issues on client side like  'NFS mount failed RPCPROG_MNT: RPC: Timed out ' or permission errors. 
  2. You might need to edit server machine /etc/hosts.allow file for this error

    RPCPROG_NFS: RPC: Program not registered

  3.  Add the following line: portmap : 192.168.1.26/255.255.255.0 : allow to server machine /etc/hosts.allow file
  4.  If still this problem popups then add this line also: rpcbind:192.168.1.26/255.255.255.0 :allow where 192.168.1.26 is the ip of client machine with specified netmask
  5. After these changes restart NFS daemon or Reboot system(if you in testing environment).
  6. mkdir myfile popups permission error so your /etc/exports file entry should be like this to remove this error /usr/yourpath -maproot=0 -network 192.168.0.0 -mask 255.255.255.0

For more detailed documentation take a look into:

http://nfs.sourceforge.net/nfshowto/index.html

No comments:

Post a Comment