NFS Server and NFS Client installation on CentOS 7

In this tutorial, we will see, NFS server and NFS Client installation steps on CentOS 7 and RHEL 7. Lets start step by step installation. First of all we should know what is NFS? Then we will see step by step NFS installation and configuration on NFS server and NFS client.

What is NFS?

NFS stand for Network File System. Network File System is a way of mounting Linux disk and directories over a network. NFS server can export one or more directories that can be mounted on a remote Linux machine. Network file system works on all IP-based networks. It uses TCP and UDP for data access and delivery, depending on the version in use.

Now let’s start NFS Server and Client installation and configuration.

Prerequisite

We need two host to installation and configuration NFS server and NFS client:-

  1. NFS Server:- IP 192.168.43.95 and Hostname:- urclouds.local
  2. NFS Client:- IP 192.168.43.96 and Hostname:- urcloudclient.local

We are assuming that you have already running CentOS7 or RHEL7 in order to setup NFS server and Client.

NFS Server Installation and Configuration

You have to run this command to install NFS server on NFS server.

[[email protected] ~]# yum install nfs-utils libnfsidmap

These are the important NFS services which we need to install.

rpcbind : The rpcbind server converts RPC program numbers into universal addresses.

nfs-server : It enables the clients to access NFS shares.

nfs-lock / rpc-statd : NFS file locking. Implement file lock recovery when an NFS server crashes and reboots.

nfs-idmap : It translates user and group ids into names, and to translate user and group names
into ids

Now we need to create directory which we want to share with NFS Client server. We can also share our existing directory.

[[email protected] ~]# mkdir /root/nfsshare

We need to allow for client servers to read and write to the created directory.

[[email protected] ~]# chmod 777 /root/nfsshare/

Then we need to edit /etc/exports file to export NFS directory to the client server. Your /etc/exports file should be like this:-

[[email protected] ~]# vi /etc/exports
/root/nfsshare 192.168.43.96(rw,sync,no_root_squash)

~

wq!


[[email protected] ~]# cat /etc/exports
/root/nfsshare 192.168.43.96(rw,sync,no_root_squash)
[[email protected] ~]#

/root/nfsshare :– shared directory

192.168.43.96 :- This is  client machine. We can also use the hostname instead of an IP address. It is also possible to define the range of clients with subnet like 192.168.43.0/24.

rw :- Its gives writable permission to shared folder

sync :-  All changes to the according filesystem are immediately flushed to disk the respective write operations are being waited for.

no_root_squash :- By default, any file request made by user root on the client machine is treated as by user nobody on the server.

We need to configure firewall on NFS server to allow client servers to access NFS shares. We can use this commands.

[[email protected] ~]# firewall-cmd --permanent --zone public --add-service mountd
success
[[email protected] ~]# firewall-cmd --permanent --zone public --add-service rpc-bind
success
[[email protected] ~]# firewall-cmd --permanent --zone public --add-service nfs
success
[[email protected] ~]# firewall-cmd --reload
success
[[email protected] ~]#

Now we need to start and enable NFS services

[[email protected] ~]# systemctl enable rpcbind
[[email protected] ~]# systemctl enable nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[[email protected] ~]# systemctl start rpcbind
[[email protected] ~]# systemctl start nfs-server
[[email protected] ~]# systemctl start rpc-statd
[[email protected] ~]# systemctl start nfs-idmapd
[[email protected] ~]#

We can check running status of all these services using below commands. All services should be properly running like this:-

[[email protected] ~]# systemctl status rpcbind
rpcbind.service - RPC bind service

   Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; indirect; vendor preset: enabled)
   Active: active (running) since Sun 2018-05-20 09:57:34 CEST; 1min 29s ago
  Process: 3976 ExecStart=/sbin/rpcbind -w $RPCBIND_ARGS (code=exited, status=0/SUCCESS)
 Main PID: 3977 (rpcbind)
   CGroup: /system.slice/rpcbind.service
           └─3977 /sbin/rpcbind -w

May 20 09:57:34 urclouds.local systemd[1]: Starting RPC bind service...
May 20 09:57:34 urclouds.local systemd[1]: Started RPC bind service.
[[email protected] ~]# systemctl status nfs-server
nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
  Drop-In: /run/systemd/generator/nfs-server.service.d
           └─order-with-mounts.conf
   
  Active: active (exited) since Sun 2018-05-20 09:57:46 CEST; 1min 37s ago
  Process: 3999 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
  Process: 3994 ExecStartPre=/bin/sh -c /bin/kill -HUP `cat /run/gssproxy.pid` (code=exited, status=0/SUCCESS)
  Process: 3993 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
 Main PID: 3999 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nfs-server.service
May 20 09:57:46 urclouds.local systemd[1]: Starting NFS server and services...
May 20 09:57:46 urclouds.local systemd[1]: Started NFS server and services.
[[email protected] ~]# systemctl status rpc-statd
rpc-statd.service - NFS status monitor for NFSv2/3 locking.
   Loaded: loaded (/usr/lib/systemd/system/rpc-statd.service; static; vendor preset: disabled)
   Active: active (running) since Sun 2018-05-20 09:57:41 CEST; 1min 49s ago
  Process: 3988 ExecStart=/usr/sbin/rpc.statd $STATDARGS (code=exited, status=0/SUCCESS)
 Main PID: 3990 (rpc.statd)
   CGroup: /system.slice/rpc-statd.service
           └─3990 /usr/sbin/rpc.statd
May 20 09:57:40 urclouds.local systemd[1]: Starting NFS status monitor for NFSv2/3 locking....
May 20 09:57:41 urclouds.local rpc.statd[3990]: Version 1.3.0 starting
May 20 09:57:41 urclouds.local rpc.statd[3990]: Flags: TI-RPC
May 20 09:57:41 urclouds.local rpc.statd[3990]: Initializing NSM state
May 20 09:57:41 urclouds.local systemd[1]: Started NFS status monitor for NFSv2/3 locking..
[[email protected] ~]# systemctl status nfs-idmapd
nfs-idmapd.service - NFSv4 ID-name mapping service
   Loaded: loaded (/usr/lib/systemd/system/nfs-idmapd.service; static; vendor preset: disabled)
   Active: active (running) since Sun 2018-05-20 09:57:46 CEST; 1min 57s ago
  Process: 3987 ExecStart=/usr/sbin/rpc.idmapd $RPCIDMAPDARGS (code=exited, status=0/SUCCESS)
 Main PID: 3992 (rpc.idmapd)
   CGroup: /system.slice/nfs-idmapd.service
           └─3992 /usr/sbin/rpc.idmapd

May 20 09:57:40 urclouds.local systemd[1]: Starting NFSv4 ID-name mapping service...
May 20 09:57:46 urclouds.local systemd[1]: Started NFSv4 ID-name mapping service.
[[email protected] ~]#

NFS Client Installation and Configuration

Now we need to install NFS packages on NFS client-server to mount remote filesystem. We can install NFS packages using below command.

[[email protected] ~]# yum -y install nfs-utils libnfsidmap

After packages installation, we can enable and start NFS services.

[[email protected] ~]# systemctl enable rpcbind

[[email protected] ~]# systemctl start rpcbind

NFS shares directory mount on NFS Clients server.

Before mounting the NFS share, we need to check that our NFS share is available for NFS client or not?  We can check with showmount command on NFS Client server. Like this:-

[[email protected] ~]# showmount -e 192.168.43.95
Export list for 192.168.43.95:
/root/nfsshare 192.168.43.96
[[email protected] ~]#

You can see here the /root/nfsshare is available on 192.168.43.96

We need to create a mount point /mnt/nfsclient on NFS Client to mount the shared folder.

[[email protected] ~]# mkdir /mnt/nfsclient

We can use below command to mount a shared directory on NFS client server. /root/nfsshare from NFS server 192.168.43.95 will be mount on /mnt/nfsclient on client server 192.168.43.96

[[email protected] ~]# mount 192.168.43.95:/root/nfsshare /mnt/nfsclient
[[email protected] ~]#

Verify the mounted share on client server using mount command. You will see like below in bold.

[[email protected] ~]# mount | grep nfs
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
192.168.43.95:/root/nfsshare on /mnt/nfsclient type nfs4 (rw,relatime,vers=4.1,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.43.96,local_lock=none,addr=192.168.43.95)
[[email protected] ~]#

We can also use df -h command to check the mounted NFS share drive on client server and you will see here in bold our NFS share drive has been successfully mounted.

[[email protected] ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/centos-root        13G  5.2G  7.8G  40% /
devtmpfs                      904M     0  904M   0% /dev
tmpfs                         920M     0  920M   0% /dev/shm
tmpfs                         920M  8.9M  911M   1% /run
tmpfs                         920M     0  920M   0% /sys/fs/cgroup
/dev/sda1                     497M  214M  283M  44% /boot
tmpfs                         184M  4.0K  184M   1% /run/user/42
tmpfs                         184M   24K  184M   1% /run/user/0
192.168.43.95:/root/nfsshare   13G  5.2G  7.8G  40% /mnt/nfsclient
[[email protected] ~]#

Now we can create a test file on the mounted directory to verify the read and write access on NFS share. After successfully run this commands we will see here test file has been successfully created in /mnt/nfsclient directory. Like this:-

[[email protected] ~]# touch /mnt/nfsclient/test
[[email protected] ~]# cd /mnt/nfsclient/
[[email protected] nfsclient]# ls -l
-rw-r--r-- 1 root root 0 May 20 11:07 test
[[email protected] nfsclient]#

Configuring Auto mount NFS Share in NFS Client.

Now we have a configured NFS Server and NFS Client. Next we need to add additional settings such as server persistence and permanent client mount using /etc/fstab. In order to have our NFS exports permanently available after the NFS server system reboot we need to make sure that nfs service auto starts after reboot:-

To mount the shares automatically on every reboot, we need to modify /etc/fstab file in our client server like below in bold.

[[email protected] ~]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Sep 26 12:44:35 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=9b1b6c8c-a702-4654-8b65-3ea79c368a84 /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
192.168.43.95:/root/nfsshare/ /mnt/nfsclient    nfs   rw,sync,hard,intr 0 0
~
:wq!
[[email protected] ~]#

Now save this file and reboot the client server and check the share mount point is automatically mounted or not?

[[email protected] ~]# reboot

Verify the mounted share on client server using mount command after rebooted your client server and see your share mount point automatically mounted or not?

[[email protected] ~]# reboot
login as: root
[email protected]'s password:
Last login: Sun May 20 11:59:06 2018
[[email protected] ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/centos-root        13G  5.2G  7.8G  40% /
devtmpfs                      904M     0  904M   0% /dev
tmpfs                         920M     0  920M   0% /dev/shm
tmpfs                         920M  8.8M  911M   1% /run
tmpfs                         920M     0  920M   0% /sys/fs/cgroup
/dev/sda1                     497M  214M  283M  44% /boot
192.168.43.95:/root/nfsshare   13G  5.2G  7.8G  40% /mnt/nfsclient
tmpfs                         184M   16K  184M   1% /run/user/0
[[email protected] ~]# mount | grep nfs
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
192.168.43.95:/root/nfsshare on /mnt/nfsclient type nfs4 (rw,relatime,sync,vers=4.1,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.43.96,local_lock=none,addr=192.168.43.95)
[[email protected] ~]#

Here we can see our NFS share drive has been automatically mounted after reboot our NFS client server. 

Now we have completed installation and configuration NFS Server and NFS Client server.

6 thoughts on “NFS Server and NFS Client installation on CentOS 7

  1. I’m gone to convey my little brother, that he
    should also visit this website on regular basis to get updated from most up-to-date reports.

  2. Hey there just wanted to give you a quick heads up.
    The text in your post seem to be running off the screen in Firefox.
    I’m not sure if this is a formatting issue or something to do
    with web browser compatibility but I figured I’d post to let you
    know. The layout look great though! Hope you get the problem resolved soon. Thanks

  3. Hi, I log on to your blogs on a regular basis. Your humoristic style is awesome, keep up the good
    work!

  4. You’re so awesome! I don’t believe I have read through anything like that before.
    So good to discover another person with original thoughts on this topic.
    Really.. thank you for starting this up. This site is something that is required on the internet,
    someone with a bit of originality!

  5. Quality articles or reviews is the crucial to be a focus for the people to
    pay a visit the website, that’s what this website is providing.

  6. This post will help the internet users for building up new webpage or even a weblog from start to
    end.

Leave a Reply

Your email address will not be published. Required fields are marked *