Setting Up An NFS Server And Client On CentOS 6

From Brian Nelson Ramblings
Revision as of 14:52, 14 March 2014 by Brian (Talk | contribs) (How to remove a Mounted NFS Partition)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Setting Up An NFS Server And Client On CentOS 6

NFS (Network File System) allows you to 'share' a directory located on one networked computer with other computers/devices on that network. The computer 'sharing' the directory is called the server and the computers or devices connecting to that server are called clients. The clients 'mount' the shared directory, it becomes part of their own directory structure.

NFS is perfect for a NAS (Networked Attached Storage) deployment in a Linux/Unix environment. It is a native Linux/Unix protocol as opposed to Samba which uses the SMB protocol developed by Microsoft. The Apple OS has good support for NFS. Windows 7 has some support for NFS.


NFS Server: server.example.com, IP address: 192.168.0.100
NFS Client: client.example.com, IP address: 192.168.0.200

Setup NFS Server

This should be setup as root.

1) Install Required Software

Let start of by installing the required software

yum install nfs-utils nfs-utils-lib -y

Now we want the NFS server to auto start on boot up

chkconfig nfs on 
service rpcbind start
service nfs start

2) Setup Shared Directory

The next step is to decide which directory we want to share with the client server. The chosen directory should then be added to the /etc/exports file, which specifies both the directory to be shared and the details of how it is shared.

Lets share the /var/www/ directory - Used when setting up Load Balancing between servers

vim /etc/exports

Now lets add the following line to the /etc/exports file

/var/www/          192.168.0.200(rw,sync,no_root_squash,no_subtree_check)

or if you want the entire 192.168.0 range

/var/www/          192.168.0.0/24(rw,sync,no_root_squash,no_subtree_check)

These settings let us do 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

Once you have entered in the settings for each directory, run the following command to export them:

exportfs -a

Seting up the NFS Client Server

1) Download Required Programs

Lets us yum to do this

yum install nfs-utils nfs-utils-lib nfs-common

2) Make the mount location

Now, lets create the mount location, since this is used for load balancing the apache root directory

mkdir -p /var/www/

3) Time to Mount

Now lets mount the remote directory

mount 192.168.0.100:/var/www /var/www

Now you check and make sure that is mounted by running

df -h

You will see your newly mounted NFS directory

Auto Mount NFS Partition

You can ensure that the mount is always active by adding the directory to the fstab file on the client node. This will make it mount on start up after the server boots

vim /etc/fstab

Now add the following

192.168.0.100:/var/www /var/www   nfs      auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0

How to remove a Mounted NFS Partition

unmount /var/www

Now you can run the df -h to see if the NFS partition has been removed

df -h