DRBD Active-Active on Ubuntu 18.04

A two-node DRBD 8.4.10 deployment on Ubuntu 18.04, replicating an LVM logical volume between hyp-lab and hyp2-lab. Both nodes operate as Primary, with /dev/drbd0 mounted at /mnt/drbd.

This example covers an existing resource with initialized backing volumes, DRBD metadata and a filesystem.


The Lab


Parameter hyb-lab hyp2-lab
Replication IP 10.10.100.1 10.10.100.2
Replication port TCP 7788 TCP 7788
Backing volume /dev/vg-storage/drbd /dev/vg-storage/drbd
DRBD resource r0 r0
DRBD device /dev/drbd0 /dev/drbd0
Mount point /mnt/drbd /mnt/drbd


Requirement: Concurrent read/write mounts require a clustered filesystem such as OCFS2 or GFS2, distributed locking and working fencing. Do not mount ext4 or XFS read/write on both hosts. Filesystem and fencing configuration must be handled separately from the DRBD configuration below. (DRBD 8.4 guide)

Configure Hostnames and Connectivity


Add these entries to /etc/hosts on both nodes:

10.10.100.1 hyp-lab
10.10.100.2 hyp2-lab


Configure DRBD


Use the same /etc/drbd.conf on both hosts:


global {
usage-count no;
}

common {
syncer {
rate 300M;
}
}

resource r0 {
startup {
become-primary-on both;
}

net {
after-sb-0pri discard-zero-changes;
after-sb-1pri discard-secondary;
after-sb-2pri disconnect;

protocol C;
allow-two-primaries yes;

max-buffers 36k;
sndbuf-size 1024k;
rcvbuf-size 2048k;
}

disk {
no-disk-flushes;
no-disk-barrier;

c-plan-ahead 10;
c-fill-target 24M;
c-min-rate 80M;
c-max-rate 720M;
}

on hyp-lab {
device /dev/drbd0;
disk /dev/vg-storage/drbd;
address 10.10.100.1:7788;
meta-disk internal;
}

on hyp2-lab {
device /dev/drbd0;
disk /dev/vg-storage/drbd;
address 10.10.100.2:7788;
meta-disk internal;
}
}


protocol C provides synchronous replication while connected. allow-two-primaries yes permits both nodes to be Primary, and become-primary-on both requests promotion through the DRBD startup script. (DRBD configuration reference)

The legacy syncer setting is retained from the existing configuration. With c-plan-ahead 10, resynchronization uses the dynamic controller and its c-* settings; c-max-rate 720M is an upper limit, not measured throughput. (DRBD 8.4 guide)

Storage note: no-disk-flushes and no-disk-barrier are deployment-specific settings. Disabling flushes requires verified power-loss protection across the storage write path, including controller and drive caches. Otherwise, retain disk flushing. (LINBIT storage tuning guidance)


Validate and Apply the Configuration


On both nodes, parse the file and preview the required changes:


drbdadm -c /etc/drbd.conf dump r0
drbdadm -c /etc/drbd.conf -d adjust r0


-d prints the backend commands without executing them. After reviewing the output and coordinating any changes with the cluster manager, apply the configuration on each node: (drbdadm reference)


drbdadm -c /etc/drbd.conf adjust r0


Verify Replication


On hyp-lab:


root@hyp-lab:~# cat /proc/drbd
version: 8.4.10 (api:1/proto:86-101)
srcversion: 9A7FB947BDAB6A2C83BA0D4
0: cs:Connected ro:Primary/Primary ds:UpToDate/UpToDate C r-----
ns:1754967499 nr:887191002 dw:1216804119 dr:928904918 al:40872858 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0


On hyp2-lab:

root@hyp2-lab:/mnt/drbd# cat /proc/drbd
version: 8.4.10 (api:1/proto:86-101)
srcversion: 7C5B8378BE913D722F67EFD
0: cs:Connected ro:Primary/Primary ds:UpToDate/UpToDate C r-----
ns:291096200 nr:1775816273 dw:2066912469 dr:101337024 al:37210 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0


Field Meaning
cs:Connected Replication connection established.
ro:Primary/Primary Both nodes are Primary.
ds:UpToDate/UpToDate DRBD reports both replicas current.
oos:0 No blocks recorded as out of sync.
wo:d Write ordering uses the drain method.


These values confirm the DRBD replication state at the time of the checks. They do not verify filesystem consistency or fencing. (DRBD status reference)


Verify Mounted Storage


Relevant excerpts from df -h:


# hyp-lab
Filesystem Size Used Avail Use% Mounted on
/dev/drbd0 1.4T 1.1T 379G 74% /mnt/drbd

# hyp2-lab
Filesystem Size Used Avail Use% Mounted on
/dev/drbd0 1.4T 1.1T 379G 74% /mnt/drbd


Check the filesystem type and mount options on both hosts:


findmnt -no SOURCE,FSTYPE,OPTIONS /mnt/drbd


df -h confirms the mount and capacity; it does not identify the filesystem type.


Split-Brain Behaviour


The configured policies apply when split brain is detected:


Policy Behaviour
after-sb-0pri discard-zero-changes With no Primary, resynchronize from the changed copy if only one side changed; disconnect if both changed.
after-sb-1pri discard-secondary With one Primary, discard the Secondary's divergent copy.
after-sb-2pri disconnect With two Primaries, disconnect without automatic resynchronization.


These policies do not provide fencing. For a dual-primary split brain, stop conflicting writes and identify the authoritative copy before recovery. (Split-brain policy reference)


Useful Troubleshooting Commands


watch -n 1 cat /proc/drbd
drbdadm role r0
drbdadm cstate r0
drbdadm dstate r0
journalctl -k | grep -i drbd


If the connection remains in WFConnection, check peer availability, replication IPs and TCP port 7788. If the kernel log reports split brain, follow the recovery procedure instead of forcing a reconnect. (DRBD 8.4 guide)