The cart is empty

This article will guide you through the step-by-step process of configuring a high availability NFS server on CentOS 7 using DRBD (Distributed Replicated Block Device) and Heartbeat. A high availability system ensures minimal downtime for your applications by automatically switching to a backup server in case of primary server failure.

Prerequisites

  • Two servers running CentOS 7, each with at least two network adapters (one for public network, another for private network).
  • DRBD and Heartbeat installed and configured.
  • Basic knowledge of Linux commands and vi or nano text editor.

DRBD Configuration

Step 1: Installing DRBD

Firstly, add the ELRepo repository containing DRBD by running the following commands:

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
yum install -y drbd84-utils kmod-drbd84

Step 2: Preparing Disk Partition for DRBD

Prepare an unused disk partition on both servers which will be used for DRBD. Assuming /dev/sdb is the available disk.

Step 3: Configuring DRBD

Create a DRBD configuration file on both servers at /etc/drbd.d/global_common.conf and add the following configuration:

global {
   usage-count no;
}

common {
   protocol C;

   syncer {
      verify-alg sha1;
      rate 40M;
   }
}

resource r0 {
   device /dev/drbd0;
   disk /dev/sdb;
   meta-disk internal;

   on server1 {
       address 192.168.1.1:7788;
   }
   on server2 {
       address 192.168.1.2:7788;
   }
}

Step 4: Initializing DRBD

On both servers, run the following commands to initialize DRBD:

drbdadm create-md r0
systemctl start drbd
drbdadm up r0

On the primary server, set DRBD to primary mode:

drbdadm primary --force r0

Heartbeat Configuration

Step 5: Installing Heartbeat

Install Heartbeat on both servers:

yum install -y heartbeat

Step 6: Configuring Heartbeat

Create a Heartbeat configuration file on both servers /etc/ha.d/ha.cf and add:

logfacility local0
ucast eth1 192.168.1.1
ucast eth1 192.168.1.2
auto_failback on
node server1
node server2

Also, set up the resource-sharing file /etc/ha.d/haresources:

server1 IPaddr::192.168.1.100/24/eth1 drbddisk::r0 Filesystem::/dev/drbd0::/mnt::ext4 nfs

Step 7: Starting Heartbeat

Start Heartbeat on both servers:

systemctl start heartbeat

You now have a configured high availability NFS server using DRBD and Heartbeat on CentOS 7. In case of primary server failure, Heartbeat will automatically migrate the NFS service to the backup server, ensuring uninterrupted access to your data. It's important to regularly test and verify the configuration to ensure everything is functioning as expected.