INSTALL & CONFIGURE NFS SERVER & CLIENT ON CENTOS 7

UPDATED!!!!

SCENARIO

We want to point Web1 and Web2 servers to the NFS (Network File System) Server. NFS keeps all the moodle data files and the web servers Web1 and Web2 point to the same storage.

Server: 10.10.4.30 (nfs)
Clients: 10.10.4.21 (Web1), 10.10.4.22 (Web2)


NFS SERVER (10.10.4.30)

install and start server
$ sudo yum update
$ sudo yum install net-tools
$ sudo yum install nfs-utils rpcbind

We’ll store the moodle files here on nfs server
$ sudo mkdir -p /home/msen/moodledata
$ sudo chmod 777 /home/msen/moodledata

FIREWALL
$ sudo firewall-cmd --permanent --zone=public --add-port=2049/tcp
$ sudo firewall-cmd --permanent --zone=public --add-port=111/tcp
$ sudo firewall-cmd --reload

make sure selinux is disabled
$ sudo vi /etc/sysconfig/selinux

SELINUX=disabled

define shared directories for clients web1 and web2 on server
$ sudo vi /etc/exports

/home/msen/moodledata 10.10.4.21(rw,no_root_squash)
/home/msen/moodledata 10.10.4.22(rw,no_root_squash)

export them
$ sudo exportfs -a
or
$ sudo systemctl start rpcbind nfs-server
$ sudo systemctl enable rpcbind nfs-server

check the nfs ports
$ sudo systemctl restart rpcbind
$ sudo rpcinfo -p | grep nfs

100003    3   tcp   2049  nfs
100003    4   tcp   2049  nfs
100227    3   tcp   2049  nfs_acl
100003    3   udp   2049  nfs
100003    4   udp   2049  nfs
100227    3   udp   2049  nfs_acl

check the portmap ports
$ rpcinfo -p | grep portmap

100000    4   tcp   111  portmapper
100000    3   tcp   111  portmapper
100000    2   tcp   111  portmapper
100000    4   udp   111  portmapper
100000    3   udp   111  portmapper
100000    2   udp   111  portmapper

if the system supports nfs
$ cat /proc/filesystems | grep nfs

nodev nfsd


 

NFS CLIENT WEB1 AND WEB2 (10.10.4.21 and 10.10.4.22)

install and mount
$ sudo yum install nfs-utils rpcbind
$ sudo systemctl start rpcbind
$ sudo systemctl enable rpcbind

test ports from client web1 and web2
$ rpcinfo -p 10.10.4.30

   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100005    1   udp  20048  mountd
    100005    1   tcp  20048  mountd
    100005    2   udp  20048  mountd
    100005    2   tcp  20048  mountd
    100005    3   udp  20048  mountd
    100005    3   tcp  20048  mountd
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    3   tcp   2049  nfs_acl
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    3   udp   2049  nfs_acl
    100021    1   udp  57646  nlockmgr
    100021    3   udp  57646  nlockmgr
    100021    4   udp  57646  nlockmgr
    100021    1   tcp  46794  nlockmgr
    100021    3   tcp  46794  nlockmgr
    100021    4   tcp  46794  nlockmgr

on web1 and web2
$ sudo vi /etc/hosts

10.10.4.30 nfs

re-test ports now with hostname
$ rpcinfo -p nfs

   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100005    1   udp  20048  mountd
    100005    1   tcp  20048  mountd
    100005    2   udp  20048  mountd
    100005    2   tcp  20048  mountd
    100005    3   udp  20048  mountd
    100005    3   tcp  20048  mountd
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    3   tcp   2049  nfs_acl
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    3   udp   2049  nfs_acl
    100021    1   udp  57646  nlockmgr
    100021    3   udp  57646  nlockmgr
    100021    4   udp  57646  nlockmgr
    100021    1   tcp  46794  nlockmgr
    100021    3   tcp  46794  nlockmgr
    100021    4   tcp  46794  nlockmgr

create the moodledata folder if not exists
$ sudo mkdir -p /var/moodledata
$ sudo chmod 777 /var/moodledata

finally let’s mount
$ sudo mount -v -t nfs -o proto=tcp,port=2049 nfs:/home/msen/moodledata /var/moodledata

mount.nfs: timeout set for Tue Oct 31 13:16:54 2017
mount.nfs: trying text-based options 'proto=tcp,port=2049,vers=4.1,addr=10.10.4.30,clientaddr=10.10.4.21'

check out the filesystem
$ df -hT

Filesystem              Type      Size  Used 	Avail 	Use% 	Mounted on
/dev/mapper/centos-root xfs       8.5G  2.3G  	6.2G  	27%	/
devtmpfs                devtmpfs  5.8G     0  	5.8G   	0% 	/dev
tmpfs                   tmpfs     5.8G     0  	5.8G   	0% 	/dev/shm
tmpfs                   tmpfs     5.8G   17M  	5.8G   	1% 	/run
tmpfs                   tmpfs     5.8G     0  	5.8G   	0% 	/sys/fs/cgroup
/dev/sda1               xfs       497M  152M  	345M  	31% 	/boot
tmpfs                   tmpfs     1.2G     0  	1.2G   	0% 	/run/user/1000
nfs:/home/msen/moodledata nfs4    198G  33M  	198G   	1%      /var/moodledata

198G is more than enough for our moodledata folder!

if needed later, for unmount, for future reference
$ sudo umount /var/moodledata

configure mount when system boots, add additional line
$ sudo vi /etc/fstab

#added by Mehmet Sen
nfs:/home/msen/moodledata            /var/moodledata        nfs             defaults                0 0

TEST IT

on client:
$ sudo touch /var/moodledata/NFS.test
on server
$ ls -l /var/moodledata
or vice versa


MOODLE COURSE BACKUP

ON NFS SERVER
create backup folder for courses
$ sudo mkdir -p /var/coursedata
$ sudo chmod 777 /var/coursedata/

point the clients to the shared folders
$ sudo vi /etc/exports

/home/msen/moodledata 10.10.4.21(rw,no_root_squash)
/home/msen/moodledata 10.10.4.22(rw,no_root_squash)
/var/coursedata 10.10.4.21(rw,no_root_squash)
/var/coursedata 10.10.4.22(rw,no_root_squash)

restart nfs
$ sudo systemctl restart rpcbind nfs-server


ON CLIENT WEB1 AND WEB2

create backup folder for courses
$ sudo mkdir -p /var/coursedata
$ sudo chmod 777 /var/coursedata/
$ sudo systemctl restart rpcbind

configure mount when system boots
$ sudo vi /etc/fstab

nfs:/home/msen/moodledata            /var/moodledata        	nfs             defaults             0 0
nfs:/var/coursedata             /var/coursedata 		nfs             defaults            0 0

let’s mount coursedata folder
$ sudo mount -v -t nfs nfs:/var/coursedata /var/coursedata

mount.nfs: timeout set for Tue Oct 31 13:32:29 2017
mount.nfs: trying text-based options 'vers=4.1,addr=10.10.4.30,clientaddr=10.10.4.21'

Only if unmount needed!
$ sudo umount /var/coursedata

re-check out the filesystem
$ df -hT

Filesystem               Type      Size   Used 	Avail 	Use% 	Mounted on
/dev/mapper/centos-root   xfs       8.5G  2.3G  6.2G  	27% 	/
devtmpfs                  devtmpfs  5.8G  0  	5.8G   	0% 	/dev
tmpfs                     tmpfs     5.8G  0  	5.8G   	0% 	/dev/shm
tmpfs                     tmpfs     5.8G  17M  	5.8G   	1% 	/run
tmpfs                     tmpfs     5.8G  0  	5.8G   	0% 	/sys/fs/cgroup
/dev/sda1                 xfs       497M  152M  345M  	31% 	/boot
tmpfs                     tmpfs     1.2G  0  	1.2G   	0% 	/run/user/1000
nfs:/home/msen/moodledata nfs4      198G  33M  	198G   	1% 	/var/moodledata
nfs:/var/coursedata       nfs4      50G  1.3G   49G   	3% 	/var/coursedata

Now we have additional 50G coursedata folder which is enough


AGAIN ON NFS

If you see error while mounting the /var/coursdata folder try run this on the NFS Server
$ sudo exportfs -f

YEEYYYYYY!!!

Advertisements

2 thoughts on “INSTALL & CONFIGURE NFS SERVER & CLIENT ON CENTOS 7

  1. I have a problem I have a setup for nfs client but the problems is that the automount is nowhhere its not in FSTAB or automount and its working even after reboot …

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s