How to Setup NFS(Network File System) Between Many Servers – Ubuntu

NFS setup :

NFS (Network file system) Network File System (NFS) is a distributed file system allowing a user on a client computer to access files over a network in a manner similar to how local storage is accessed. A system for accessing and sharing file systems across a computer network using UNIX and Linux.

Server Side :-
All Ports should be open for TCP & UDP using that particular ip.

the file /etc/apt/sources.list file comment out the lines
deb natty-security main
deb-src natty-security main
deb natty-security universe
deb-src natty-security universe
It should then look like(commented)
#deb natty-security main
#deb-src natty-security main
#deb natty-security universe
#deb-src natty-security universe

Then, We are still on the server side:
apt-get update
apt-get install nfs-kernel-server nfs-common portmap
/etc/init.d/portmap restart

At the end of the file /etc/apt/sources.list add these lines :

deb natty main restricted universe multiverse
deb natty-updates main restricted universe multiverse
deb natty-security main restricted universe multiverse

vi /etc/exports (edit on server side)

/path/of/folder/you/want/to/share/of/server/side/folder_name “ip address of client server” (rw,no_root_squash, no_subtree_check)
/var/www/,no_root_squash,no_subtree_check) #{First Client}
/var/www/,no_root_squash,no_subtree_check) #{Second Client}
/var/www/,no_root_squash,no_subtree_check) #{Third Client}
/var/www/,no_root_squash,no_subtree_check) #{Forth Client}
save and exit.

Execute the below command on server side:
exportfs -ar

Some tools used for troubleshooting:
* rpcinfo -p server_ip
* showmount -e server_ip

On Client Side
Run this command : mount -t nfs private-ip-on-server-side:/path/of/server/to/be/mount/ /path/of/client/
mount -t nfs /var/www/

then Edit the file  /etc/fstab in the client
Add this line on the client : “IP of host server”:/Mount path on host server/ /mount point on client server/ nfs defaults 0 0

Now the question is that how to check that mounted is done or not on the client.
for checking df -h
root@ip-10-136-98-113:# df -h
Filesystem                                               Size  Used Avail Use% Mounted on
/dev/xvda1                                             7.9G  4.0G  3.6G  53% /
udev                                                      3.4G  8.0K  3.4G   1% /dev
tmpfs                                                     1.4G  188K  1.4G   1% /run
none                                                      5.0M     0  5.0M   0% /run/lock
none                                                      3.4G     0  3.4G   0% /run/shm  493G  240G  228G  52% /var/www/web/media

For Unmounting the nfs server :( On the client server)
You have to use the following command :
umount /path/of/client/

  • Simone

    Hi, nice tutorial. I was looking that you are exporting /media folder..what about the magento folder it self? how do you sync the folder across all webserver?
    if i use nfs to share the magento folder across many webservers, page rendering is very very slow..

    thank you