In this article I will show you how to configure a NFS mount on CentOS machines. I’ve used this technology when sharing a folder between multiple web servers that were hosting a single web application. This method is useful because a folder is mounted on multiple servers and deployments can be made on a single machine while changes will be replicated between all nodes, thus you decrease the number of mistakes that can occur.
For this demonstration I will be using two CentOS Virtual Machines hosted in my VMware testing environment. To create a NFS mount we need at least two machines: the server (which hosts the directory) and the client (which mounts the specified directory). We’ll start configuring these two components:
We’ll need to install the nfs-util and its library package by executing the following command:
yum install nfs-utils nfs-utils-lib
NFS depends on the rpcbind service so make sure you start this service by typing service rpcbind start. You can then verify its status by executing service rpcbind status:
Start the NFS service with the same command then verify its status (you can also use ps -aux | grep nfs):
In /var/www/ I’ve created a new folder named web.ppscu.com which will be mounted on the client.
The /etc/exports file is used to specify which file systems will be exported to remote machines. I’ll add the following entry in the exports file:
You can check out the parameters available in the exports file on this
Once the entry has been added to the file, we’ll need to export the directory using the exportfs -a command.
Install the necessary packages by typing yum install nfs-utils nfs-utils-lib
Create the folder to be mounted on the client machine:
mkdir -p /var/www/web.ppscu.com
Now we can safely mount the shared folder by using the following command:
mount 192.168.61.136:/var/www/web.ppscu.com/ /var/www/web.ppscu.com/ where 192.168.61.136 is the IP address of the NFS server.
umount /var/www/web.ppscu.com/ is used to remove a mount from a CentOS machine.
Note that the directory will be connected to the server until it’s rebooted. To create a persistent mount point, we’ll need to edit the /etc/fstab
file and add the following line:
192.168.61.136:/var/www/web.ppscu.com/ /var/www/web.ppscu.com/ nfs auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0
We can verify that the directory was mounted successfully by typing df -h:
Another way in which we can check out the mount point is by typing mount without parameters:
mount -a is used to force the OS to reload and mount all the entries added in the /etc/fstab file
You can also try to create a file in the specified folder with the touch file_name command and then verify if you are able to see it from the client.
That’s about it for this article folks, I hope you’ll find it useful.