• Webinars
  • Docs
  • Download
  • Blogs
  • Contact Us
Try Free
Show / Hide Table of Contents

Configure File Share on Linux

NCache Distributed Cache with Persistence allows you to backup data to persistence store. NCache Persistence requires a shared path that is accessible from all nodes. You need to make sure that all nodes have read and write access to the shared path.

Here, we guide how to configure file share using Network File Share (NFS) and CIFS protocols to set up a shared path while creating a Distributed Cache with Persistence in Linux.

Setup and Configuration of NFS on Linux

NFS is a distributed, client/server file system protocol through which remote directories can be shared by allowing local file systems to be mounted over a network. The clients can interact with such directories as they would with directories that are mounted locally. The setting up of NFS on Linux requires at least two machines, one to act as a server and others as clients.

Setup and Configure NFS Server

Here we explain the steps to setup and configure NFS Server on Ubuntu and RHEL.

Install NFS Server on Ubuntu

For the installation process enter the following commands in the terminal:

sudo apt install nfs-kernel-server

This will install all the required packages to run the NFS Server service. To start the NFS Server enter the following command in the terminal.

sudo systemctl start nfs-kernel-server.service

Install NFS Server on RHEL

For the installation process enter the following commands in the terminal:

dnf install nfs-utils

This will install all the required packages to run the NFS Server service. To start the NFS Server enter the following command in the terminal.

systemctl start nfs-server.service

Configure NFS Server

To share a particular directory, its path needs to be exported. This can be done by adding it to the file /etc/exports. For example, a directory with the path /home/nfsshare may be added along with the hostname/IP of client machine as shown below (make sure the directory you want to share, exists).

/home/nfsshare 192.168.1.2(rw,sync,no_subtree_check)
/home/nfsshare 192.168.1.3(rw,sync,no_subtree_check)

The above lines make the directory /home/nfsshare available to mount for client machines with IP’s 192.168.1.2 and 192.168.1.3.

Alternatively, it can also be written using a wildcard as

/home/nfsshare *(rw,sync,no_subtree_check)

Or using CIDR notation as

/home/nfsshare 192.168.1.0/24(rw,sync,no_subtree_check)
  • rw: This flag allows client to both read and write in the shared directory
  • sync: This flag confirms any requests to the directory only once all the changes are committed
  • no_subtree_check: This flag prevents subtree checking i.e it prevents NFS performing scans of all directories above it when verifying details and permissions
Note

Read man exports for more information and export options.

Once the above steps are complete, the service needs to be restarted.

The following command can be used for Ubuntu installation:

sudo systemctl restart nfs-kernel-server.service

The following command can be used for the RHEL installation:

sudo systemctl restart nfs-server.service
Note

If you have firewall running you may need to allow traffic to the NFS Services.

Allow NFS traffic through firewall on Ubuntu

Here is how you can allow NFS traffic through firewall on Ububtu

sudo ufw allow nfs

To view the firewall status, the following command can be used.

 sudo ufw status 

Allow NFS traffic through firewall on RHEL

To allow NFS traffic through a firewall, run the following commands

sudo firewall-cmd --permanent --add-service=nfs
sudo firewall-cmd --permanent --add-service=rpc-bind
sudo firewall-cmd --permanent --add-service=mountd

After running the above commands, the firewall will need to be reloaded. To do this run the following command

sudo firewall-cmd --reload

Setup and Configure NFS Client

Here we explain the steps to setup and configure NFS Client on Ubuntu and RHEL.

Install NFS Client on Ubuntu

To install NFS Client on a machine enter the following command into the terminal:

sudo apt install nfs-common

Install NFS Client on RHEL

To install NFS Client on a machine enter the following command into the terminal:

dnf install nfs-utils

Configure NFS Client

To determine what directories are being shared by an NFS Server the showmount command may be used. For example. If the NFS Server is started on machine 192.168.1.100, use it as follows

showmount -e 192.168.1.100

The mount command can be used to mount the NFS directory. For a shared directory /mnt/nfsshare on the server 192.168.1.100 the following command can be executed on the client machine to mount the directory.

mkdir /mnt/nfsshare
sudo mount 192.168.1.100:/home/nfsshare /mnt/nfsshare
Note

Make sure the mount point directory being used in the client machine exists.

The above command mounts nfsshare temporarily. To mount it permanently across reboots, add the following line in the file /etc/fstab

192.168.1.100:/home/nfsshare /mnt/nfsshare nfs defaults 0 0

After mounting, NCache will require permission to access and write to the newly mounted directory. This can be done using the following commands

sudo chown ncache /mnt/nfsshare
sudo chmod u+rw /mnt/nfsshare

With this the shared directory is now accessible by navigating to the /mnt/nfsshare folder. To verify that everything is functional, a simple file may be created in the directory.

touch test.file

This file should be visible across all the connected clients and servers, and depending on the configuration, readable and writable as well.

Mount Windows Share on Linux Using CIFS

CIFS is a network based file sharing protocol that enables users to share files, folders and data over different operating systems.

Here we explain the steps to install and Windows file share on Ubuntu and RHEL. Before starting the configuration on Linux make sure that a windows file share is set up and a user is set up with read and write permission.

Install Windows Share on Ubuntu

To mount the windows file share the following package will need to be installed “cifs-utils”. This can be done by entering the following commands in the terminal

sudo apt-get update
sudo apt-get install cifs-utils

Install Windows Share on RHEL

To mount the Windows file share on RHEL distributions the package cifs-utils needs to be installed first. This can be done by executing the following command in the terminal

sudo dnf -y install cifs-utils

Configuration/Mounting of Windows Share

Once the package is installed, the file share needs to be mounted. To do this a directory will be used as a mount point. If the directory does not exist it can be created as follows

sudo mkdir /mnt/winshare

Windows share can be mounted by providing cifs in the options parameter as follows

sudo mount -t cifs -o username=<WindowsUsername>,password=<WindowsUserPassword>,domain<Domain>,uid=<AllowAccessToUserWithID> //<FileShare hostname/IP>/<DirectoryName> <Linux mount point>
Note

If the file share is open for everyone, then username, password, and domain are not mandatory.

So as an example a Windows file share is set up on IP 192.168.1.100 in the directory MySharedFiles with the user john having read and write permission the mount command can be written as

sudo mount -t cifs -o username=john,password=password1,uid="$(id ncache -u)" //192.168.1.100/MySharedFiles /mnt/winshare

If this command is successful, the directory /mnt/winshare will be mounted. For verification, the user can navigate to the directory, view contents and create and edit files. A simple file can be created using the following command.

touch test.file1

See Also

Getting Started with Distributed Cache with Persistence Linux
Create a Distributed Cache with Persistence

Back to top Copyright © 2017 Alachisoft