Total Pageviews

Thursday, March 29, 2018

SQL Server on Linux – NFS share between two or more Linux Servers


We might need a network shared directory between two or more Linux Servers to move databases or log backups while configuring Log-shipping, Replication, AlwaysOn or simply restoring the database backup to another Linux server.

The Linux NFS is the easiest way to share files between one or more Linux Servers. In the following example we have three Servers, where Linux01 is the primary (or nfs) server, and the secondary (or client) servers are Linux03 and Linux05.

NFS Server: linux01 (192.168.0.155) - CentOS 7.4
NFS Client: linux03 (192.168.0.157) - CentOS 7.4
NFS Client: linux05 (192.168.0.159) - CentOS 7.4

Set-by-step guide:

On the linux01 Server, perform the following:

1.      Install the NFS library:
sudo yum -y install nfs-utils

2.      Create a directory:
sudo mkdir /sqlcommon

3.      Grant permission to the directory:
sudo chmod -R a+w /sqlcommon

4.      Edit the expots configuration file and add the shared folder information:
vi /etc/exports

/sqlcommon 192.168.0.157(rw,sync)
/sqlcommon 192.168.0.159(rw,sync)
           
Note that any one of the following entries can also be used to provide access to everyone:
/sqlcommon *(rw,sync)
/sqlscommon 192.168.0.0/24(rw,sync)

5.      Enable and start the NFS service:
sudo systemctl enable nfs-server
sudo systemctl start nfs-server

6.      Refresh the export tables:
sudo exportfs -avr

7.      Configure the firewall to allow NFS service:
sudo firewall-cmd --permanent --zone=public --add-service=nfs


On the secondary (NFS Client) servers Linux02 and linux05:

1.      Install the NFS library:
sudo yum -y install nfs-utils

2.      Create a mount point:
sudo mkdir /mnt/sqlmount

3.      (a). For a temporary mount, execute the following on both servers:
sudo mount -t nfs 192.168.0.155:/sqlcommon /mnt/sqlmount

(b)   To mount permanently, add an entry to the fstab file:
            sudo vi /etc/fstab

mount 192.168.0.155:/sqlcommon /mnt/sqlmount defaults  0 0

sudo mount –a
df -h

Testing the NFS share on linux03 or linux05:

Use the following command to access the network shared directory.

cd /mnt/sqlmount
ls -a

Browsing the NFS Share from linux05:

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.