Shared filesystem between servers using NFS

Mar 30th, 2017 in  by Michael Cho

Mount a directory to be shared between multiple servers using Network File System (NFS).

A while ago I needed to share the same copy of some large files between several server instances. It needed to be the same actual file, and synced instantly - ruling out the use of hacky solutions like rsync'ing files via a cron job etc. 

It turns out this isn't too difficult to do with NFS, which lets you nominate a folder on a master server which can be accessed by one (or more) client servers. 

Here's how to do this, using CentOS servers:

# Set NFS file sharing between servers (Run on master server)
yum install nfs-utils nfs-utils-lib
chkconfig nfs on

# Edit /etc/exports to enable the /var/www/mydomain/shared folder to be shared with client servers at these IP addresses

# edit /etc/sysconfig/nfs and uncomment the following lines

# Setup NFS on client server
yum install nfs-utils nfs-utils-lib

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

mkdir -p /path/to/where/to/mount
mount -t nfs /path/to/where/to/mount/

# add the following lines to /etc/fstab (client server only) to automount every reboot nfsrw,sync,hard,intr 0 0


Other articles you may like

Running Metabase locally as a service
May 29th, 2017
Create a custom Alexa Skill with AWS Lambda - Part 3 (Lambda)
Dec 18th, 2016
Create a custom Alexa Skill with AWS Lambda - Part 2 (Alexa Skill)
Nov 10th, 2016
Create a custom Alexa Skill with AWS Lambda - Part 1 (Overview)
Nov 1st, 2016
Using iptables to open a port on CentOS
Jul 25th, 2016