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.

[root@urclouds ~]# 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.

[root@urclouds ~]# mkdir /root/nfsshare

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

[root@urclouds ~]# 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:-

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

~

wq!


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

/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.

[root@urclouds ~]# firewall-cmd --permanent --zone public --add-service mountd
success
[root@urclouds ~]# firewall-cmd --permanent --zone public --add-service rpc-bind
success
[root@urclouds ~]# firewall-cmd --permanent --zone public --add-service nfs
success
[root@urclouds ~]# firewall-cmd --reload
success
[root@urclouds ~]#

Now we need to start and enable NFS services

[root@urclouds ~]# systemctl enable rpcbind
[root@urclouds ~]# 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.
[root@urclouds ~]# systemctl start rpcbind
[root@urclouds ~]# systemctl start nfs-server
[root@urclouds ~]# systemctl start rpc-statd
[root@urclouds ~]# systemctl start nfs-idmapd
[root@urclouds ~]#

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

[root@urclouds ~]# 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.
[root@urclouds ~]# 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.
[root@urclouds ~]# 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..
[root@urclouds ~]# 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.
[root@urclouds ~]#

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.

[root@urcloudsclient ~]# yum -y install nfs-utils libnfsidmap

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

[root@urcloudsclient ~]# systemctl enable rpcbind

[root@urcloudsclient ~]# 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:-

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

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.

[root@urcloudsclient ~]# 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

[root@urcloudsclient ~]# mount 192.168.43.95:/root/nfsshare /mnt/nfsclient
[root@urcloudsclient ~]#

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

[root@urcloudsclient ~]# 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)
[root@urcloudsclient ~]#

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.

[root@urcloudsclient ~]# 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
[root@urcloudsclient ~]#

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:-

[root@urcloudsclient ~]# touch /mnt/nfsclient/test
[root@urcloudsclient ~]# cd /mnt/nfsclient/
[root@urcloudsclient nfsclient]# ls -l
-rw-r--r-- 1 root root 0 May 20 11:07 test
[root@urcloudsclient 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.

[root@urcloudsclient ~]# 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!
[root@urcloudsclient ~]#

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

[root@urcloudsclient ~]# 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?

[root@urcloudsclient ~]# reboot
login as: root
root@192.168.43.96's password:
Last login: Sun May 20 11:59:06 2018
[root@urcloudsclient ~]# 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
[root@urcloudsclient ~]# 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)
[root@urcloudsclient ~]#

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.

This Post Has 6 Comments

  1. Situs Judi QQ Minimal Deposit 10rb

    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. maytinhban

    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. giàn phơi thông minh quần áo sankaku

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

  4. gianphoithongminhgiasi.net

    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. scooter neuf

    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. Situs Judi QQ Minimal Deposit 10rb

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

Leave a Reply