NFS Server and Client on CentOS

Assumptions:

NFS Server IP: 172.16.5.100
NFS Client Node1: 172.16.5.101
NFS Client Node2: 172.16.5.102
NFS Client Node3: 172.16.5.103
NFS Client Node4: 172.16.5.104

On the NFS Server & All Client machine as well:

yum install nfs-utils nfs-utils-lib

Edit the exports file that shows what to share and with whom. So run:nano /etc/exports

In my scenerio it was-

/share 172.16.5.101(rw,sync,no_root_squash,no_subtree_check)
/share 172.16.5.102(rw,sync,no_root_squash,no_subtree_check)
/share 172.16.5.103(rw,sync,no_root_squash,no_subtree_check)
/share 172.16.5.104(rw,sync,no_root_squash,no_subtree_check)

Apply the changes-

exportfs -a or /usr/sbin/exportfs -a

With a Restart of NFS Kernel Service-

/etc/init.d/nfs-kernel-server restart

The showmount command will tell you that all went well–for example,

root@share:~# showmount -e
 Export list for share:
 /share 172.16.5.101
 root@share:~#

On the Client Nodes:

We’re going to have to mount the remote shares, so let’s create some mount points. We’ll use the traditional /mnt as a starting point and create a directory called nfs under it to keep our shares consolidated.

The actual directories will correspond with their location on the host server. We can create each directory, and the necessary parent directories, by typing this:

mkdir -p /www

Now that we have some place to put our remote shares, we can mount them by addressing our host server, which in this guide is 1.2.3.4, like this:

mount 172.16.5.100:/share /www

These should mount the shares from our host computer onto our client machine. We can double check this by looking at the available disk space on our client server:

root@psc1:~# df -h
 Filesystem Size Used Avail Use% Mounted on
 /dev/sda1 323M 145M 162M 48% /
 tmpfs 1007M 0 1007M 0% /lib/init/rw
 udev 1002M 128K 1002M 1% /dev
 tmpfs 1007M 0 1007M 0% /dev/shm
 /dev/sda9 2.8G 69M 2.6G 3% /home
 /dev/sda8 234M 6.1M 216M 3% /tmp
 /dev/sda5 2.8G 520M 2.1G 20% /usr
 /dev/sda6 1.4G 173M 1.2G 14% /var
 172.16.5.100:/share 323M 145M 162M 48% /www

As you can see at the bottom, only one of our shares has shown up. This is because both of the shares that we exported are on the same filesystem on the remote server, meaning that they share the same pool of storage. In order for the Avail and Use% columns to remain accurate, only one share may be added into the calculations.

If you want to see all of the NFS shares that you have mounted, you can type:

mount -t nfs
root@psc1:~# mount -t nfs
 172.16.5.100:/share on /www type nfs (rw,addr=172.16.5.100)

Now it’s time to add fstab entry so that the mount becomes permanent even after rebooting-

nano /etc/fstab
172.16.5.100:/share /www nfs auto 0 0

Done!

Source:

https://www.howtoforge.com/setting-up-an-nfs-server-and-client-on-centos-6.3

http://tweenpath.net/nfs-server-and-client-on-debian-67/

Share

Leave a Reply