← All Articles

Shared filesystem between servers using 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


Made with JoyBird