What is NFS? – Network File Share – NFS mounts work to share a directory between several servers.

PROS
Saves disk space – As the home directory is only kept on one server, and others can connect to it over the network

CONS
Due to the above. The NFS server can be a single point of failure for all other servers relying on it.

 

Setup:

Note: For installation of Debian/Ubuntu – substitute the yum command with apt-get.

First off, install the required packages for the NFS Server.

yum install nfs-utils nfs-utils-lib

Set NFS to start on boot.
chkconfig nfs on **Not Required for Debian/Ubuntu**

Start required services.
service rpcbind start
service nfs start

Export the Shared Directory
Add the directory you wish to share to /etc/exports :
/var/www $CLIENT_IP(rw,sync,no_root_squash,no_subtree_check)

These settings accomplish several tasks:

* rw: This option allows the client server to both read and write within the shared directory
* sync: Sync confirms requests to the shared directory only once the changes have been committed.
* no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger filesystem, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.
* no_root_squash: This phrase allows root to connect to the designated directory

Once you have entered in the settings for each directory, run the following command to export them:
exportfs -a

Setup the NFS Client(s)

Install the required packages for the NFS Client.
yum install nfs-utils nfs-utils-lib

Mount the Directories

Create a directory where you would like the NFS shared files to be stored.
mkdir -p /mnt/var/www

Then go ahead and mount it
mount $MASTER_IP:/nfs /mnt/var/www

You can use the df -h command to check that the directory has been mounted. You will see it last on the list.
df -h

Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 20G 1.3G 18G 7% /
tmpfs 496M 0 496M 0% /dev/shm
$MATER_IP:/var/www 20G 1.4G 18G 8% /mnt/var/www

** Recommended**
You could also add this to /etc/fstab to ensure that the Remote directory is mounted when the server reboots.
$MASTER_IP:/var/www /mnt/var/www nfs auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0

Once it has been added to /etc/fstab you can mount it by executing the below:

mount -a

Removing the NFS Mount

Should you decide to remove a directory, you can unmount it using the umount command:
cd
sudo umount /mnt/var/www