Install and configure DRBD on CentOS 8 | RHEL 8

The
You can support us by downloading this article in PDF format via the link below.

Download the guide in PDF format

turn off
The

The
The

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

The core function of DRBD is realized by the Linux kernel module with a virtual block device driver. Because DRBD is located near the bottom of the system I/O stack, it is very flexible and versatile, making it an ideal solution for high-availability replication solutions.

After installing DRBD, you will get a set of management tools that communicate with the kernel module to configure and manage DRBD resources.

  • Debudam: This is an advanced management tool for the DRBD program suite.
  • drbdsetup: This tool is used to configure the DRBD module loaded into the kernel
  • b: Used to create, dump, restore and modify DRBD metadata structure

How DRBD mirrors data:

  • real time. When the application modifies the data stored in the device, the copy will continue.
  • Transparently. The application does not know that the data is stored on multiple hosts on the network.
  • Synchronously Or Asynchronously. When using synchronous mirroring, the application will be notified after writing is completed on all hosts. For asynchronous mirrors, when the write is completed locally (usually before they are propagated to other hosts), the application is notified that the write is complete.

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

The software package for DRBD needs to be manually installed on CentOS 8 / RHEL 8 Linux. During the installation process, we will use the ELRepo repository, which contains other software packages for Enterprise Linux.

Add the ELRepo repository to your CentOS/RHEL 8 system by running the following command.

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

– After adding the repository to the system, you can import the public key:

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

Confirm the configuration by searching the DRBD software package.

$ 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 the installation at the prompt displayed by the 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 policy, DRBD mail cannot be run. You may need to exempt the DRBD process from the SELinux control:

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

Enable the DRBD service port on the firewall.

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

Step 2: Prepare the lower storage

After installing DRBD on CentOS / RHEL 8 Linux system, we can continue to use DRBD to configure replication storage between the two servers.

We need to reserve a storage area of ​​approximately the same size on the two cluster nodes. These storage areas are used as low-level devices for DRBD resources. The block devices you can easily use are:

  • Hard drive partition (or full physical hard drive)
  • Software RAID device
  • LVM logical volume
  • Any other block device type found on the system.

In my installer, I have two servers with the following details.

server nicknameServer IPRaw disk device
server-01.computingforgeeks.com192.168.20.11/dev/sdb
server-02.computingforgeeks.com192.168.20.12/dev/sdb

This is my server 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 will use LVM to create a volume group for DRBD for future expansion. This is done on the server where the original disk and DRBD are installed.

Create a partition table on 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 tool and create 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 the 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 resources

All aspects of DRBD are in /etc/drbd.conf The content of the configuration file is as follows.

$ 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 framework file that tells the service which directory to look for other configuration files.

I will create a new profile below /etc/drbd.d/r0.res

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

Has the following content:

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 contains two nodes,server01'with'server02‘.
  • We have an arbitrarily named resource Resources 0 To use /dev/mapper/drbdpool-drbdata As a lower-level device, and equipped with Internal metadata.
  • Resource uses TCP port 7789 Used for its network connection and bound 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 host names, as shown below uname -a

Step 4: Initialize DRDB resources

After completing the initial resource configuration, you can start the resource. Can only be executed once.

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

Initialize the metadata of DRBD-syntax: drbdadm create-md

$ 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 resources

Once the resource is initialized, you need to associate it with its backup device (or multiple devices, if it is a multi-volume resource), set replication parameters, and connect 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 state:

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

At this time, the disk state is expected to be inconsistent/inconsistent.

Step 6: Initial device synchronization

DRBD has successfully allocated disk and network resources and can operate. The next step is to tell DRBD which node should be used as Resources Initial device synchronization.

We need to start the initial full synchronization (Only execute on one node). I will continue server-01.computingforgeeks.com

sudo drbdadm primary --force resource0

After issuing this command, the initial full synchronization will begin. 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: Use the DRBD device

Now, we can use the DRBD device because it can be fully operational. We can create a file system on the device, use it as a raw block device, mount it, and perform any other operations performed by an accessible block device.

Get the device map of the 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 file system on the 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 it:

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

confirm:

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

Check if the file can be written.

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

Confirm whether the file is 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: Mount the DRBD device on the secondary host:

First remove Master node And get the second role.

sudo umount /mnt/mydrbd
sudo drbdadm secondary resource0

Then run on the secondary node:

$ 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 learned how to install and configure DRBD on CentOS/RHEL 8 Linux machines. To learn more about DRBD technology, please refer to the official documentation at the link below.

More information about storage:

Install Ceph 15 (Octopus) cluster on CentOS 8

Install Ceph 15 (Octopus) storage cluster on Ubuntu 20.04

Setting up GlusterFS storage with Heketi on CentOS 8/CentOS 7

The
You can support us by downloading this article in PDF format via the link below.

Download the guide in PDF format

turn off
The

The
The

Sidebar