()

Setup Linux NFS Server and Client

Network File Sharing (NFS) is a protocol that allows you to share directories and files with other Linux clients over a network. Shared directories are typically created on a file server, running the NFS server component. Users add files to them, which are then shared with other users who have access to the folder. An NFS file share is mounted on a client machine, making it available just like folders the user created locally. NFS is particularly useful when disk space is limited and you need to exchange public data between client computers.


Below are the high-level steps we will follow to set up our NFS.

1. Install and activate nfs server on NFS Server
2. Create the NFS Share Folder and export it
3. Install nfs client and mount the NFS Share Folder on Client


Below are setup details and the same will be used in this demonstration.

Sr. No.HostnameIPRole
1test-machine01192.168.114.177NFS Server
2test-machine02192.168.114.176NFS Client


Step 1. Install and activate NFS Server: Install NFS Server using OS yum command. Once installation is done enable nfs service and add port in firewall using below commands.

[root@test-machine01 u01]# yum -y install nfs-utils
Loaded plugins: langpacks, ulninfo
Repository ol7_UEKR5 is listed more than once in the configuration
Dependencies Resolved

==============================================================================================================================================================================================
 Package                                    Arch                                    Version                                                 Repository                                   Size
==============================================================================================================================================================================================
Updating:
 nfs-utils                                  x86_64                                  1:1.3.0-0.68.0.1.el7.1                                  ol7_latest                                  412 k

Transaction Summary
==============================================================================================================================================================================================
Upgrade  1 Package
Updated:
  nfs-utils.x86_64 1:1.3.0-0.68.0.1.el7.1

Complete!
[root@test-machine01 u01]#

[root@test-machine01 psql_backup]# systemctl enable nfs-server.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.

[root@test-machine01 psql_backup]# systemctl start nfs-server.service

[root@test-machine01 psql_backup]#
[root@test-machine01 psql_backup]# systemctl status nfs-server.service
â nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
   Active: active (exited) since Sun 2021-08-15 10:01:55 +03; 39s ago
  Process: 63520 ExecStartPost=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi (code=exited, status=0/SUCCESS)
  Process: 63506 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
  Process: 63504 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
 Main PID: 63506 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nfs-server.service

Aug 15 10:01:54 test-machine01 systemd[1]: Starting NFS server and services...
Aug 15 10:01:55 test-machine01 systemd[1]: Started NFS server and services.
[root@test-machine01 psql_backup]#

[root@test-machine01 psql_backup]# firewall-cmd --permanent --add-service=nfs
success
[root@test-machine01 psql_backup]# firewall-cmd --reload
success
[root@test-machine01 psql_backup]#


Step 2. Create the NFS Share Folder and export it on NFS Serve: We will be using /u01/psql_backup directory as our NFS share. Edit nfs configuration file: /etc/exports and add the below line.

*: This mount has access to any system in the Network
rw: Read Write
sync: Any update in file from the Client-side and it will update in Server also.

[root@test-machine01 psql_backup]# mkdir /u01/psql_backup
[root@test-machine01 psql_backup]#
[root@test-machine01 psql_backup]# chown postgres:postgres /u01/psql_backup
[root@test-machine01 psql_backup]#
[root@test-machine01 psql_backup]# vi /etc/exports
/u01/psql_backup *(rw,sync)
:wq!
[root@test-machine01 psql_backup]# cat /etc/exports
/u01/psql_backup *(rw,sync)
[root@test-machine01 psql_backup]#
[root@test-machine01 psql_backup]# exportfs -a
[root@test-machine01 psql_backup]#


Step 3. Install NFS client and mount the NFS Share Folder on NFS Client: Use OS yum command to install nfs package. Once the package is installed, you can use the command showmount to search for available NFS Server. Add NFS Share details in /etc/fstab so each time Server mount NFS drive automatically during server reboot.

[root@test-machine02 etc]# yum -y install nfs-utils
Loaded plugins: langpacks, ulninfo
Dependencies Resolved

==============================================================================================================================================================================================
 Package                                          Arch                                  Version                                               Repository                                 Size
==============================================================================================================================================================================================
Installing:
 nfs-utils                                        x86_64                                1:1.3.0-0.68.0.1.el7.1                                ol7_latest                                412 k
Installing for dependencies:
 gssproxy                                         x86_64                                0.7.0-30.el7_9                                        ol7_latest                                110 k
 keyutils                                         x86_64                                1.5.8-3.el7                                           ol7_latest       
Installed:
  nfs-utils.x86_64 1:1.3.0-0.68.0.1.el7.1
Transaction Summary
==============================================================================================================================================================================================
Install  1 Package (+10 Dependent packages)

Dependency Installed:
  gssproxy.x86_64 0:0.7.0-30.el7_9     keyutils.x86_64 0:1.5.8-3.el7     libbasicobjects.x86_64 0:0.1.1-32.el7  libcollection.x86_64 0:0.7.0-32.el7  libevent.x86_64 0:2.0.21-4.el7
  libini_config.x86_64 0:1.3.1-32.el7  libnfsidmap.x86_64 0:0.25-19.el7  libpath_utils.x86_64 0:0.2.1-32.el7    libref_array.x86_64 0:0.1.5-32.el7   libverto-libevent.x86_64 0:0.2.5-4.el7

Complete!
[root@test-machine02 etc]#

[root@test-machine02 etc]#
[root@test-machine02 etc]# showmount -e test-machine01
Export list for test-machine01:
/u01/psql_backup *
[root@test-machine02 etc]#

[root@test-machine02 u01]#
[root@test-machine02 u01]# vi /etc/fstab
test-machine01:/u01/psql_backup /u01/psql_backup nfs rw,sync,hard,intr 0 0
:wq!
[root@test-machine02 u01]#
[root@test-machine02 u01]# cat /etc/fstab
test-machine01:/u01/psql_backup /u01/psql_backup nfs rw,sync,hard,intr 0 0
[root@test-machine02 u01]#
[root@test-machine02 u01]# mkdir /u01/psql_backup
[root@test-machine02 u01]#
[root@test-machine02 u01]# chown postgres:postgres /u01/psql_backup
[root@test-machine02 u01]#
[root@test-machine02 u01]# mount /u01/psql_backup
[root@test-machine02 u01]#
[root@test-machine02 u01]# df -h /u01/psql_backup
Filesystem                       Size  Used Avail Use% Mounted on
test-machine01:/u01/psql_backup   60G   42G   19G  69% /u01/psql_backup
[root@test-machine02 u01]#

This document is just for learning purpose and always validate in the LAB environment first before applying in the LIVE environment.


Hope so you like this article
!
Please share your valuable feedback/comments/subscribe and follow us below and don’t forget to click on the bell icon to get the most recent update. Click here to understand more about our pursuit.


Related Article

Loading

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Jamsher Khan

Hello and welcome to DBsGuru,I’m Jamsher Khan working as Senior Oracle DBA based in KSA-Jeddah, I have working experience in Oracle DBA, SQL Server, MySql, PostgreSQL, Linux, Golden Gate, ODA.Thanks for the visits!Share Learn Grow!