Configure NFS server in CentOS


NFS is a very useful thing if you have multiple servers, and you need to organize a joint access to a specific repository for each of them.
NFS allows to make files and folders available for other servers through the network.

So I’m going to use the following example.
We have 2 servers:
web01, ip: 10.0.0.10
web02, ip: 10.0.0.20

There are 2 websites on them. First website is in WordPress, the second one is Joomla!

I need to make the following folders to have identical content on both servers:

  • /var/www/html/wordpress-site.com/wp-content/uploads
  • /var/www/html/joomla-site.com/cache
  • /var/www/html/joomla-site.com/media

I’m going to share these folders from web01 to web02

1. Install the software on web01:

yum install nfs-utils nfs-utils-lib

Enable startup for NFS and launch it:

chkconfig nfs on
/etc/init.d/nfs start

Make sure to launch rpcbind, if you receive the following error message:

Starting NFS daemon: rpc.nfsd: writing fd to kernel failed: errno 111 (Connection refused)

It is much better to enable startup for:

chkconfig rpcbind on
/etc/init.d/rpcbind start

Next edit the exports file (/etc/exports) and allow remote access to local folders:

/var/www/html/wp-site.com/wp-content/uploads   10.0.0.20(rw,sync,no_root_squash,no_subtree_check)
/var/www/html/joomla-site.com/cache            10.0.0.20(rw,sync,no_root_squash,no_subtree_check)
/var/www/html/joomla-site.com/media            10.0.0.20(rw,sync,no_root_squash,no_subtree_check)

The example for subnet:

/var/www 10.10.0.0/16(rw,sync,no_root_squash,no_subtree_check)

I will not describe all aspects of this file. All information is available here

Save changes and close file. Next run the following to apply the changes:

exportfs -a

2. Install the software on web02:

yum install nfs-utils nfs-utils-lib

Enable startup for NFS and launch it:

chkconfig nfs on
/etc/init.d/nfs start

Next we need to edit the /etc/fstab to define the permanent NFS mounts:

10.0.0.10:/var/www/html/wp-site.com/wp-content  /var/www/html/wp-site.com/wp-content   nfs      rw,sync,hard,intr  0     0
10.0.0.10:/var/www/html/joomla-site.com/cache   /var/www/html/joomla-site.com/cache    nfs      rw,sync,hard,intr  0     0
10.0.0.10:/var/www/html/joomla-site.com/media   /var/www/html/joomla-site.com/media    nfs      rw,sync,hard,intr  0     0

Save changes and close file. Next run the following to apply the changes:

mount -a

Next you can run the following command to make sure that remote folders have been mounted:

df -a

Don’t worry if the folders exist on web02 server. NFS mounts will prioritize.

Next you can try to create a test tile or folder on the web01 server and check if it appeared on web02.

Share Button

Leave a Reply

You must be logged in to post a comment.