Network File System (NFS) is a distributed file system which allows users to access the server file system on their client computer over network. User can use the NFS mounted file system as like as their local file system. The main advantage is to share one file system to many computers by which you can save disk space on the local system. Also we can use this as a centralize server for web applications having many application servers. If you will update your code on one place then it will distributed to all other servers.
In this article I will show you how to configure NFS master and client system. For this I am using two CentOS 6 system.
Master : 192.168.2.100
Client: 192.168.2.200
You need to use the root user for the setup.
Now on the both of the systems issue the below command to install NFS
yum install nfs-utils nfs-utils-lib
Add NFS to the startup scripts on the Master:
chkconfig nfs on service rpcbind start service nfs start
Now we will export our share directory:
We have to decide which directory we want to share with the client servers. Then we have to add that directory to the /etc/exports file, which specifies both the directory to be shared and the details of how it is shared. In my case I want to share a directory named “/linuxfundacode”
mkdir linuxfundacode
vi /etc/exports
/linuxfundacode 192.168.2.200/24(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
After finishing the configuration we need to issue the below command:
exportfs -a
We are done with the NFS server side. Now we will configure the NFS client.
We have already installed the NFS on the client system in First step. Now we need to mount the shared file system to our client machine. Create a directory where you want to mount the NFS file system. For me it’s /var/www/html/www.linuxfunda.com/
mkdir /var/www/html/www.linuxfunda.com/
Issue the below command to mount
mount 192.168.2.100:/linuxfundacode /var/www/html/www.linuxfunda.com/
Verify the mount
df -h
Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_tmishra-lv_root 50G 8.4G 41G 18% / tmpfs 1.5G 768K 1.5G 1% /dev/shm /dev/sda1 485M 66M 394M 15% /boot /dev/mapper/vg_tmishra-lv_home 21G 9.9G 9.9G 50% /home 192.168.2.100:/linuxfundacode 20G 785M 18G 5% /var/www/html/www.linuxfunda.com
If you want to make the mount permanent then you have to add the mount informations to the /etc/fstab file.
vi /etc/fstab
192.168.2.100:/linuxfundacode /var/www/html/www.linuxfunda.com nfs auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0
Save the file after appending the above code. Now the file system will automatically load at the boot time.
Issue the below command to mount the file system immediately.
mount -a