Saturday, December 28, 2024
Google search engine
HomeGuest BlogsInstall and Configure NFS Server on Rocky Linux 8

Install and Configure NFS Server on Rocky Linux 8

.tdi_3.td-a-rec{text-align:center}.tdi_3 .td-element-style{z-index:-1}.tdi_3.td-a-rec-img{text-align:left}.tdi_3.td-a-rec-img img{margin:0 auto 0 0}@media(max-width:767px){.tdi_3.td-a-rec-img{text-align:center}}

There are 3 storage formats i.e files, blocks, and object storage each with different ways on how they hold, organize and present data.

  • Object storage – can also be referred to as object-based storage. Here, files are broken/chopped into discrete units known as objects and spread out among hardware. This basically manages data and links it to associated metadata.
  • Block storage – Data is chopped into blocks and saved as separate pieces. Each piece is give a unique identifier, which allows a storage system to place the smaller pieces of data wherever is most convenient. This is often used to spread data across multiple environments. Here, data is chunked into arbitrarily organized, evenly sized volumes.
  • File storage – This is also referred to as file-level or file-based storage .File storage is basically defined as storing data as a single piece of information inside a folder. To access the data, the computer needs to know the exact path to find it. Data stored is retrieved using some metadata that tells the system where exactly it can find the data. Here, data is represented as a hierarchy of files in folders.

NFS is an acronym for the network file system. This is system enables one to store and retrieve data from several disks and directories across a network. This distributed file system was developed by Sun Microsystems in 1984. This system works using the client/server model where the NFS server manages the authorization and management of the clients and also stores the shared data. On successful authentication, the clients can view and access the data just like any other local file system.

The Network File System service offers the following features:

.tdi_2.td-a-rec{text-align:center}.tdi_2 .td-element-style{z-index:-1}.tdi_2.td-a-rec-img{text-align:left}.tdi_2.td-a-rec-img img{margin:0 auto 0 0}@media(max-width:767px){.tdi_2.td-a-rec-img{text-align:center}}

  • NFS Version 2 Protocol which is widely used.
  • NFS Version 3 Protocol, this was a new features of the Solaris 2.5 release with several interoperability and performance improvements and can handle files that are larger than 2 Gbytes
  • NFS Version 4 Protocol – represents the user ID and the group ID as strings.
  • Network Lock Manager and NFS
  • Large File support with the added ability to manipulate files larger than 2 Gbytes.
  • Kerberos support
  • WebNFS support
  • NFS Over TCP/UDP support
  • NFS Server Logging – a record of file operations that have been performed on its file systems are kept.
  • Security Negotiation for the WebNFS Service – The client is able to negotiate a security mechanism with an NFS server.
  • Several extensions for NFS Mounting with the automountd command.

This guide aims to help you install and configure the NFS Server on Rocky Linux 8.

Setup Pre-requisites

We will do the configuration using the servers below:

Task Host Name IP Address
NFS server(Rocky Linux 8) nfs.geeksforgeeks.org 192.168.205.2
NFS Client nfsclient1.geeksforgeeks.org 192.168.205.4

Ensure that the above servers have sudo access and the hostnames configured appropriately.

Step 1 – Install and Configure NFS Server

NFS packages are available in the default Rocky Linux repositories and can be installed using the command:

sudo dnf install nfs-utils

Dependency Tree:

....
Transaction Summary
================================================================================
Upgrade  1 Package

Total download size: 499 k
Is this ok [y/N]: y

Once complete, make the domain name configurations to the NFS server in the /etc/idmapd.conf file. The idmapd is the daemon responsible for providing the NFSv4 kernel client and server functionality. It translates user and group IDs to names, and vice versa thus ensuring Server client communication.

sudo sed -i '/^#Domain/s/^#//;/Domain = /s/=.*/= geeksforgeeks.org/' /etc/idmapd.conf

Remember to replace geeksforgeeks.org with your domain name.

Step 2 – Define NFS Server Share Directories

This is configured in the /etc/exports file. This file contains the table of physical file systems that can be accessed by the NFS client(s). SO we are required to edit and add the file system to be shared/exported to the NFS client.

The added file system should observe the below structure:

export host(options)

In the command:

  • export refers to the file system or directory to be mounted on remote host
  • host is the NFS client allowed to access the exported file. It can either be a single host(domain name, IPv4 or IPv6 address), IP network, wildcards, netgroups, anonymous.
  • optionsthis is a list of options separated with commas, they include; all_squash, no_root_squash, root_squash, secure, rw, ro, async, sync, subtree_check, no_wdelay, wdelay e.t.c

More can be found using the man exports command.

In this guide, we will export the /home and /var/nfs/share to the host 192.168.205.12 as below.

Create the directory with the right permissions;

sudo mkdir /var/nfs/share -p
sudo chown nobody:nobody /var/nfs/share

So we will add the directories as below.

$ sudo vim /etc/exports
/home 192.168.205.4(rw,sync,no_root_squash,no_subtree_check)
/var/nfs/share 192.168.205.4(rw,sync,no_subtree_check)

We have added the read and write permissions for users on the remote host. Save the file and allow the service through the firewall.

sudo firewall-cmd --add-service={nfs,nfs3,mountd,rpc-bind} --permanent
sudo firewall-cmd --reload

Now start and enable the NFS service to run automatically on boot.

sudo systemctl enable --now nfs-server rpcbind

Check the status of the NFS server service.

$ 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 2022-01-23 03:50:10 EST; 6s ago
  Process: 32547 ExecStart=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi (code=exited, status=0/SUCCES>
  Process: 32535 ExecStart=/usr/sbin/rpc.nfsd (code=exited, status=0/SUCCESS)
  Process: 32533 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
 Main PID: 32547 (code=exited, status=0/SUCCESS)

Jan 23 03:50:10 nfs.geeksforgeeks.org systemd[1]: Starting NFS server and services...
Jan 23 03:50:10 nfs.geeksforgeeks.org systemd[1]: Started NFS server and services.

Step 3 – Install and Configure the NFS Client

The NFS client can be any system added in the /etc/exports and has the file system mounted on it.

First, begin by installing the NFS packages on the client as below:

##On Debian/Ubuntu
sudo apt install nfs-common

##On RHEL/CentOS/Rocky Linux/ Alma Linux
sudo dnf install nfs-utils -y

Similarly, edit the domain name in the /etc/idmap.conf as we did for the NFS server.

sudo sed -i '/^#Domain/s/^#//;/Domain = /s/=.*/= geeksforgeeks.org/' /etc/idmapd.conf

Verify if the shared directories are discoverable on your NFS client before you can proceed and mount them.

sudo showmount -e nfs.geeksforgeeks.org
sudo showmount -e 192.168.205.4

Sample Output:

Export list for nfs.geeksforgeeks.org:
/var/nfs/share 192.168.205.4
/home          192.168.205.4

Create mount points:

sudo mkdir /mnt/home
sudo mkdir /mnt/share

Now you can mount the shared directory.

sudo mount -t nfs nfs.geeksforgeeks.org:/home /mnt/home
sudo mount -t nfs nfs.geeksforgeeks.org:/var/nfs/share /mnt/share

Verify if the directory has been mounted.

$ df -h
Filesystem                                Size  Used Avail Use% Mounted on
udev                                      2.9G     0  2.9G   0% /dev
tmpfs                                     595M  1.3M  593M   1% /run
/dev/vda1                                  39G  5.2G   32G  15% /
tmpfs                                     3.0G   16K  3.0G   1% /dev/shm
tmpfs                                     5.0M     0  5.0M   0% /run/lock
tmpfs                                     595M   84K  595M   1% /run/user/115
tmpfs                                     595M   56K  595M   1% /run/user/1000
nfs.geeksforgeeks.org:/home            36G  5.1G   30G  15% /mnt
nfs.geeksforgeeks.org:/var/nfs/share   36G  5.1G   30G  15% /mnt/share

Configure permanent Mount points on the NFS Client.

The above method temporarily mounts the directory and will need remounting after boot. To make the mounting persistent, we need to add an fstab entry as below.

$ sudo vim /etc/fstab
nfs.geeksforgeeks.org:/var/nfs/share      /mnt/share     nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0
nfs.geeksforgeeks.org:/home               /mnt/home      nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0

Remember to replace nfs.geeksforgeeks.org with the NFS server domain name/IP address.

Step 4 – Test NFS Access

Now we will try and write to the shared directory from the NFS client as below.

sudo touch /mnt/share/test.txt

View the permissions:

$ ls -l /mnt/share/test.txt
-rw-r--r-- 1 nobody nogroup 0 Jan 23 04:22 /mnt/share/test.txt

Conclusion

In this guide, we have systematically walked through how to install and configure NFS Server on Rocky Linux 8. We have demonstrated how to access the shared NFS file remotely using the NFS client. I hope this was helpful.

Related posts:

.tdi_4.td-a-rec{text-align:center}.tdi_4 .td-element-style{z-index:-1}.tdi_4.td-a-rec-img{text-align:left}.tdi_4.td-a-rec-img img{margin:0 auto 0 0}@media(max-width:767px){.tdi_4.td-a-rec-img{text-align:center}}

RELATED ARTICLES

Most Popular

Recent Comments