What is DRBD and Why Do You Need It?
Imagine running a production MySQL server processing 50,000 orders a day. Suddenly, a hard drive fries at 2:00 PM. Last night’s backup is intact, but every single transaction since morning has vanished into thin air. You lose half a day’s revenue and spend hours rebuilding the system.
To solve this challenge, sysadmins often rely on networked RAID 1. That is precisely what DRBD (Distributed Replicated Block Device) does. For every 4KB block written to Server A (Node 1), DRBD immediately mirrors it to Server B (Node 2) over the local network. If Node 1 loses power, Node 2 already has an identical byte-for-byte copy ready for an immediate takeover.
Our legacy infrastructure previously ran on CentOS 7. Last year, we wrapped up our migration to AlmaLinux and CentOS Stream 9. Taking advantage of this upgrade cycle, we rolled DRBD 9 straight into production to completely eliminate single points of failure (SPOF) at the storage tier.
Quick start: Spin Up a Working DRBD 9 Cluster in 5 Minutes
Prepare two CentOS Stream 9 servers with unrestricted connectivity across the same local network:
- node01:
192.168.1.101, with an additional unpartitioned drive/dev/sdb(e.g., 100GB SSD) - node02:
192.168.1.102, with an additional unpartitioned drive/dev/sdb(exact same capacity as node01)
Step 1: Enable ELRepo and Install the DRBD 9 Kernel Module (Run on Both Nodes)
# Import GPG key and add ELRepo for CentOS Stream 9
sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
sudo dnf install -y https://www.elrepo.org/elrepo-release-9.el9.elrepo.noarch.rpm
# Install the kmod-drbd90 kernel module and drbd-utils management tools
sudo dnf install -y kmod-drbd90 drbd-utils
# Load the module into the Linux kernel
sudo modprobe drbd
lsmod | grep -i drbd
Step 2: Open Firewall Ports for DRBD (Run on Both Nodes)
# DRBD communicates over TCP port 7788 by default
sudo firewall-cmd --permanent --add-port=7788/tcp
sudo firewall-cmd --reload
Step 3: Define the Resource Configuration File
Create an identical /etc/drbd.d/r0.res file on both node01 and node02:
resource r0 {
protocol C;
net {
csums-alg sha256;
verify-alg sha256;
}
on node01 {
node-id 0;
device /dev/drbd0;
disk /dev/sdb;
address 192.168.1.101:7788;
meta-disk internal;
}
on node02 {
node-id 1;
device /dev/drbd0;
disk /dev/sdb;
address 192.168.1.102:7788;
meta-disk internal;
}
connection {
host node01 port 7788;
host node02 port 7788;
}
}
Step 4: Initialize and Activate Data Synchronization
Initialize metadata and bring up the resource on both machines:
sudo drbdadm create-md r0
sudo drbdadm up r0
Promote node01 as the initial primary data source:
# Note: Run this command ONLY on node01:
sudo drbdadm primary --force r0
Monitor real-time synchronization progress:
drbdadm status r0
Synchronization is complete once both nodes report an UpToDate status. The virtual block device /dev/drbd0 is now ready to be formatted with XFS/EXT4 and mounted for your applications.
Under the Hood: DRBD 9 Technical Architecture
Where Does DRBD Sit in the I/O Stack?
DRBD operates at the block device layer, positioned directly beneath the filesystem and right above physical disk storage. When an application writes a file, the filesystem issues I/O requests to /dev/drbd0, and DRBD mirrors the stream across the network interface. It offers three primary replication protocols:
- Protocol A (Asynchronous): Write operations are acknowledged as completed as soon as packets reach the local network send buffer. This delivers maximum write performance and is ideal for high-latency WAN links. However, there is a risk of data loss if the source crashes while packets are in flight.
- Protocol B (Semi-synchronous): The primary node acknowledges the write once the secondary node confirms packet arrival at its network layer. A slight risk of data loss remains if the secondary crashes before flushing RAM buffers to disk.
- Protocol C (Fully Synchronous): The application only receives write confirmation once data is safely committed to non-volatile disk on both nodes. This is the gold standard for High Availability clusters requiring a zero Recovery Point Objective (RPO = 0).
Primary and Secondary Roles
Standard filesystems like XFS or EXT4 are not designed for concurrent multi-host writes. Consequently, DRBD enforces that only a single node holds the Primary role to mount the filesystem and handle read/write operations. The counterpart node must remain in the Secondary role, serving strictly as a replication target without being mounted.
Advanced Tuning: Optimizing Network I/O and Handling Split-Brain
DRBD’s default configuration prioritizes safety, but sync speeds are often throttled below 30 MB/s, failing to leverage modern network capabilities, which can often be improved alongside optimizing kernel parameters with sysctl.
1. Tuning the Resynchronization Rate
Add dynamic resync parameters to the disk { ... } block to maximize throughput across 1Gbps or 10Gbps NICs:
disk {
resync-rate 110M; # Cap at ~110 MB/s for 1Gbps network cards
c-plan-ahead 20; # Controller look-ahead time of 2 seconds
c-max-rate 700M; # Maximum bandwidth ceiling for 10Gbps networks
c-min-rate 20M; # Minimum bandwidth floor DRBD must sustain
}
2. Automating Split-Brain Recovery
Split-brain is the worst nightmare in HA clustering. If network connectivity drops between the two nodes, both may assume the peer has died. Both promote themselves to Primary and accept diverging writes. Once communication is restored, you face severe data divergence and conflicts.
Add the following directives to the net { ... } block to let DRBD automatically resolve conflicts by demoting the node with stale data and syncing from the newer primary:
net {
after-sb-0pri discard-younger-primary;
after-sb-1pri discard-secondary;
after-sb-2pri call-pri-lost-after-sb;
}
Battle-Tested Production Lessons
- Dedicate a separate network for DRBD: Never run replication traffic over public or shared interfaces. Jitter and latency fluctuations will severely degrade overall disk write performance. Use direct point-to-point 10GbE cables or an isolated VLAN.
- Never mount or format the Secondary node: Blocks are continuously mirrored from Primary to Secondary. Mounting or formatting the backing disk on the secondary node will corrupt the filesystem superblock and destroy data integrity.
- Pair with Pacemaker and Corosync: DRBD only handles data replication; it does not monitor node health or manage automated IP failover. To build a complete high-availability failover cluster, integrate it with Pacemaker and Corosync.
- Match partition sizes down to the sector: The backing storage device
/dev/sdbmust match identically across both machines. Even a single-sector discrepancy forces DRBD to truncate usable storage to the smaller device.

