Installing and Configuring DRBD for High Availability – DRBD for Apache Server

DRBD example setup and configuration

DRBD stands for Distributed Replicated Block Device. DRBD is a distributed replicated storage system for the Linux platform which is implemented as a kernel driver.

The main configuration file for DRBD is /etc/drbd.conf.

  include “drbd.d/global_common.conf”

  include “drbd.d/*.res”

DRBD configuration can be grouped into multiple configuration files and can be combined in drbd.conf using the include statements. There can be multiple “.res” resource configuration files for configuring resources under /etc/drbd.d/. There will also be a global_common.conf file for setting values parameters like usage-count.

OR, you can have a simple DRBD configuration structure, and you can use drbd.conf alone and place all the configuration information in this single file.

A very basic drbd.conf file would look like this:


This configuration file should be the same in both nodes you are trying to sync.

DRBD create a virtual disk (/dev/drbd0) using a kernel driver (drbd). This kernel driver should be loaded ($modprobe drbd) before activating DRBD (assuming you have already installed DRBD).

1)  $modprobe drbd

2)  $drbdadm create-md r0  -> create mirrored device

3)  $drbdadm up r0 -> start up the mirrored device

4)  $lsblk -> will display our new block device drbd0


Perform these 4 steps in both machines to make sure your mirrored device is up & running on both devices.

To see what is happening in DRBD, you can do $cat /proc/drbd

When we $cat /proc/drbd  we will see both machines are listed as secondary at this point.

To fix this, you need to go to the primary node and run this command:

$drbdadm overwrite-data-of-peer primary r0/0

Now you can run derby-overview to see the status.

You can also do $cat /proc/drbd

Now be careful! We need to create a filesystem on the primary because that is the only one you can actually write to DTBD device.

Don’t create the filesystem on the physical device, create the file system on the mirrored device (drbd0 – remember the configuration of the r0 resource).

$mkfs.ext4 /dev/drbd0

This filesystem will be replicated across to all the machines in our cluster (2 machines in this case).

Now you can do:

$mkdir -p /var/www/html

$mount /dev/drbd0 /var/www/html

Without a cluster manager we need to do everything manually (mounting-unmounting, changing the primary).

We need a cluster manager to automatically transition between nodes in our cluster.

A test scenario might be something like below to show that DRBD replication is working:

On current primary:

  • $touch /var/www/html/file1
  • $umount /var/www/html
  • $drbdadm secondary r0

On current secondary:

  • $drbdadm primary r0
  • $mkdir /var/www/html
  • $mount /dev/drbd0 /var/www/html

$ls -al /var/www/html will display file1 that we added on primary1 before making it secondary.

This shows that our DRBD configuration is ok.

DRBD 9.0 documentation:

A demo video:

Related: Installing and configuring Pacemaker

Hope this helps.
Good Luck,