You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

This is a step-by-step guide on the installation of Distributed Replicated Block Device (DRBD) on CentOS 8 / RHEL 8 Linux servers. DRBD is a free and open source, software-based replicated storage solution used for mirroring the content of block devices such as disk partitions, hard disks and logical volumes between hosts in a network.

The core functionality of DRBD is implemented by a way of Linux kernel module with driver for a virtual block device. Because DRBD is located near the bottom of system’s I/O stack, it is extremely flexible and versatile which makes it an ideal solution for implementing a high available replication solution.

By installing DRBD you’ll get a set of administration tools which communicate with the kernel module in order to configure and administer DRBD resources.

  • drbdadm: This is the high-level administration tool of the DRBD program suite.
  • drbdsetup: This tool is used to configure the DRBD module loaded into the kernel
  • drbdmeta: Used to create, dump, restore, and modify DRBD meta data structures

How DRBD mirrors data:

  • in real time. Replication will happen continuously while applications modify the data stored in the device.
  • transparently. Applications are not aware that the data is stored on multiple hosts in the network.
  • synchronously or asynchronously. When synchronous mirroring is used applications are notified of write completions upon completion on all hosts. For asynchronous mirroring, applications are notified of write completions when the writes have completed locally, which usually is before they have propagated to the other hosts.

Step 1: Install DRBD on CentOS 8 | RHEL 8 Linux

The packages for DRBD needs to be installed manually on CentOS 8 / RHEL 8 Linux. For the installation we’ll use ELRepo repository which contains extra packages for Enterprise Linux.

Add ELRepo repository to your CentOS / RHEL 8 system by running the commands below.

sudo dnf -y install https://www.elrepo.org/elrepo-release-8.el8.elrepo.noarch.rpm

– With the repository added to the system you can import the public key:

sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

Confirm configuration by searching for DRBD packages.

$ sudo dnf search drbd
ELRepo.org Community Enterprise Linux Repository - el8                                                                            338 kB/s | 264 kB     00:00
================================================================== Name & Summary Matched: drbd ==================================================================
kmod-drbd90.x86_64 : drbd90 kernel module(s)
drbd90-utils.x86_64 : Management utilities for DRBD
drbd90-utils-sysvinit.x86_64 : The SysV initscript to manage the DRBD.

Now you can install DRBD with kernel module on CentOS 8 Linux.

sudo dnf install vim drbd90-utils kmod-drbd90

Accept installation in the prompt shown by command execution.

Dependencies resolved.
========================================================================================================================================================
 Package                                Arch                        Version                                           Repository                   Size
========================================================================================================================================================
Installing:
 kmod-drbd90                            x86_64                      9.0.21-3.el8_2.elrepo                             elrepo                      292 k
 drbd90-utils                           x86_64                      9.10.0-2.el8.elrepo                               elrepo                      753 k
Upgrading:
 dracut                                 x86_64                      049-70.git20200228.el8                            BaseOS                      365 k
 dracut-network                         x86_64                      049-70.git20200228.el8                            BaseOS                      100 k
 dracut-squash                          x86_64                      049-70.git20200228.el8                            BaseOS                       54 k
 iptables                               x86_64                      1.8.4-10.el8                                      BaseOS                      581 k
 iptables-ebtables                      x86_64                      1.8.4-10.el8                                      BaseOS                       70 k
 iptables-libs                          x86_64                      1.8.4-10.el8                                      BaseOS                      105 k
 kexec-tools                            x86_64                      2.0.20-14.el8                                     BaseOS                      485 k
 libnftnl                               x86_64                      1.1.5-4.el8                                       BaseOS                       83 k
 linux-firmware                         noarch                      20191202-97.gite8a0f4c9.el8                       BaseOS                       72 M
 systemd                                x86_64                      239-30.el8_2                                      BaseOS                      3.5 M
 systemd-libs                           x86_64                      239-30.el8_2                                      BaseOS                      1.1 M
 systemd-pam                            x86_64                      239-30.el8_2                                      BaseOS                      449 k
 systemd-udev                           x86_64                      239-30.el8_2                                      BaseOS                      1.3 M
Installing dependencies:
 kernel-core                            x86_64                      4.18.0-193.6.3.el8_2                              BaseOS                       28 M

Transaction Summary
========================================================================================================================================================
Install   3 Packages
Upgrade  13 Packages

Total download size: 109 M
Is this ok [y/N]: y

Under the default SELinux security policies DRBD mail fail to run and you may need to exempt DRBD processes from SELinux control:

sudo dnf -y install policycoreutils-python-utils
sudo semanage permissive -a drbd_t

Enable DRBD service ports on the firewall.

sudo firewall-cmd --add-port=6996-7800/tcp --permanent
sudo firewall-cmd --reload

Step 2: Preparing your lower-level storage

With the installation of DRBD done on CentOS / RHEL 8 Linux system we can proceed to configure replicated storage using DRBD across two servers.

We need to set aside a roughly identically sized storage area on both cluster nodes which used as lower-level device for your DRBD resource. Block devices that you can easily use are:

  • Hard drive partition (or a full physical hard drive)
  • Software RAID device
  • LVM Logical Volume
  • Any other block device type found on your system.

In my Setup I have two servers with below details.

Server NameServer IPRaw Disk Device
server-01.computingforgeeks.com192.168.20.11/dev/sdb
server-02.computingforgeeks.com192.168.20.12/dev/sdb

This is my servers disk layout:

$ lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0 19.1G  0 disk
├─sda1    8:1    0   19G  0 part /
├─sda14   8:14   0    1M  0 part
└─sda15   8:15   0   64M  0 part /boot/efi
sdb       8:16   0   50G  0 disk
sr0      11:0    1 1024M  0 rom

I’ll use LVM to create Volume group for DRBD to make it easy for later scaling. This is done on the server with raw disk and DRBD installed.

Create partition table in the disk.

sudo parted -s -a optimal -- /dev/sdb mklabel gpt
sudo parted -s -a optimal -- /dev/sdb mkpart primary 0% 100%
sudo parted -s -- /dev/sdb align-check optimal 1

Install LVM tools and create both PV, VG and LV for DRBD.

$ sudo dnf -y install lvm2
$ sudo pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
$ sudo vgcreate drbdpool /dev/sdb1
Volume group "drbdpool" successfully created
$ sudo lvcreate -n drbdata -l100%FREE drbdpool
Logical volume "drbdata" created.

Confirm LVM settings.

$ sudo pvs
  PV         VG       Fmt  Attr PSize   PFree
  /dev/sdb1  drbdpool lvm2 a--  <50.00g <50.00g

$ sudo vgs
  VG       #PV #LV #SN Attr   VSize   VFree
  drbdpool   1   0   0 wz--n- <50.00g <50.00g

Step 3: Configure DRBD resource

All aspects of DRBD are controlled in the /etc/drbd.conf configuration file which has the contents below.

$ cat /etc/drbd.conf
# You can find an example in  /usr/share/doc/drbd.../drbd.conf.example

include "drbd.d/global_common.conf";
include "drbd.d/*.res";

This is just a skeleton file which tells the service which directories to look for other config files.

I’ll create a new configuration file under /etc/drbd.d/r0.res

sudo vim /etc/drbd.d/resource0.res

With below contents:

resource resource0 {
  on server-01.computingforgeeks.com {
    device    /dev/drbd1;
    disk      /dev/mapper/drbdpool-drbdata;
    address   95.217.209.209:7789;
    meta-disk internal;
  }
  on server-02.computingforgeeks.com {
    device    /dev/drbd1;
    disk      /dev/mapper/drbdpool-drbdata;
    address   95.217.220.167:7789;
    meta-disk internal;
  }
}

Configuration summary:

  • Our cluster consists of two nodes, ‘server01‘ and ‘server02‘.
  • We have a resource arbitrarily named resource0 which uses /dev/mapper/drbdpool-drbdata as the lower-level device, and is configured with internal meta data.
  • The resource uses TCP port 7789 for its network connections, and binds to the IP addresses 192.168.20.11 and 192.168.20.12, respectively.
  • server-01.computingforgeeks.com and server-02.computingforgeeks.com are the correct server hostbnames as shown in uname -a

Step 4: Initialize DRDB resource

After you have completed initial resource configuration you can bring up your resource. This is only done once.

Each of the following steps must be completed on both nodes.

Initialize DRBD’s metadata – Syntax: drbdadm create-md <resource>

$ sudo drbdadm create-md resource0
initializing activity log
initializing bitmap (1600 KB) to all zero
Writing meta data...
New drbd meta data block successfully created.

Step 5: Enable DRBD resource

Once the resource has bee initialized you need to associates it with its backing device (or devices, in case of a multi-volume resource), sets replication parameters, and connects the resource to its peer:

$ sudo drbdadm up resource0
 --==  Thank you for participating in the global usage survey  ==--
The server's response is:

you are the 6934th user to install this version

Observe the status:

$ sudo drbdadm status resource0
resource0 role:Secondary
  disk:Inconsistent
  server-02.computingforgeeks.com role:Secondary
    peer-disk:Inconsistent

The Inconsistent/Inconsistent disk state is expected at this point.

Step 6: Initial device synchronization

DRBD has successfully allocated both disk and network resources and is ready for operation. The next action is to tell DRBD which of the nodes should be used as the source of the initial device synchronization.

We need to start the initial full synchronization (Only perform on one node). I’ll run mine on server-01.computingforgeeks.com

sudo drbdadm primary --force resource0

After issuing this command, the initial full synchronization will commence. It may take some time depending on the size of the device.

Check Status:

# On Primary
$ sudo drbdadm status
sudo drbdadm status resource0
resource0 role:Primary
  disk:UpToDate
  server-02.computingforgeeks.com role:Secondary
    peer-disk:UpToDate

# On Secondary
$ sudo drbdadm status resource0
resource0 role:Secondary
  disk:UpToDate
  server-01.computingforgeeks.com role:Primary
    peer-disk:UpToDate

Step 7: Using DRBD Device

We can now use DRBD Device as it is fully operational. We can create a filesystem on the device, use it as a raw block device, mount it, and perform any other operation you would with an accessible block device.

Get device mapping for name.

$ lsblk
NAME                 MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                    8:0    0 19.1G  0 disk
├─sda1                 8:1    0   19G  0 part /
├─sda14                8:14   0    1M  0 part
└─sda15                8:15   0   64M  0 part /boot/efi
sdb                    8:16   0   50G  0 disk
└─sdb1                 8:17   0   50G  0 part
  └─drbdpool-drbdata 253:0    0   50G  0 lvm
    └─drbd1          147:1    0   50G  0 disk
sr0                   11:0    1 1024M  0 rom

Let’s create a filesystem on DRBD device:

$ sudo mkfs.xfs /dev/drbd1
meta-data=/dev/drbd1             isize=512    agcount=4, agsize=3276442 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=13105767, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=6399, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

Let’s taste mounting:

sudo mkdir /mnt/mydrbd
sudo mount /dev/drbd1 /mnt/mydrbd

Confirmation:

$ df -hT /mnt/mydrbd/
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/drbd1     xfs    50G  390M   50G   1% /mnt/mydrbd

Check if you can write files.

for i in {1..10}; do
  sudo touch /mnt/mydrbd/${i}.txt
done

Confirm if files were created on the DRBD device:

$ ls -l /mnt/mydrbd
total 0
-rw-r--r--. 1 root root 0 Jul  7 00:36 10.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 1.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 2.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 3.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 4.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 5.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 6.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 7.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 8.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 9.txt

Step 8: Mounting DRBD device on the secondary Host:

First unmount on the primary node and get secondary role.

sudo umount /mnt/mydrbd
sudo drbdadm secondary resource0

Then on the secondary node run:

$ sudo drbdadm primary resource0
$ sudo drbdadm status
resource0 role:Secondary
  disk:UpToDate
  server-02.computingforgeeks.com role:Primary
    peer-disk:UpToDate

$ sudo mkdir  /mnt/mydrbd
$ sudo mount /dev/drbd1 /mnt/mydrbd
$ df -hT /mnt/mydrbd
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/drbd1     xfs    50G  390M   50G   1% /mnt/mydrbd

$ ls -lh /mnt/mydrbd/
total 0
-rw-r--r--. 1 root root 0 Jul  7 00:36 10.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 1.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 2.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 3.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 4.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 5.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 6.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 7.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 8.txt
-rw-r--r--. 1 root root 0 Jul  7 00:36 9.txt

In this guide we have learned how we can install and configure DRBD on CentOS / RHEL 8 Linux machine. For an in-depth learning of DRBD technology refer to the official documentation in the link below.

More on Storage:

Install Ceph 15 (Octopus) Cluster on CentOS 8

Install Ceph 15 (Octopus) Storage Cluster on Ubuntu 20.04

Setup GlusterFS Storage With Heketi on CentOS 8 / CentOS 7

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF