Chapter 31. DRBD Replicated Block Storage
DRBD (Distributed Replicated Block Device) presents the same block device on
two Linux hosts. A write sent to the device on the primary host is forwarded
over a network link and written to the peer's backing storage. The filesystem,
the service, and the client see an ordinary block device such as /dev/drbd0;
the replication, role changes, and recovery logic live below that device. This
is useful when a service needs a filesystem that can move between two servers
without a shared storage fabric, and when the administrator can accept the
operational work of keeping the two copies consistent.
Replication is not the same as high availability. DRBD makes a second copy of the blocks and lets an administrator choose which node may write. It does not decide when to promote a node, move a client address, fence a failed host, or recover an application that was interrupted during a failover. Those decisions belong to a cluster manager or to a documented manual runbook. This chapter builds and operates a two-node DRBD resource, tests planned and unplanned role changes, and shows how the resource fits under a clustered service. The next chapter adds Pacemaker, fencing, and virtual addresses.
The examples use three Debian 13 guests on an isolated practice network:
| Role | Host | Practice address | Storage and services |
|---|---|---|---|
| DRBD node 1 | drbd1 |
192.168.231.11/24 on eth1 |
/dev/vdb as an LVM physical volume, /dev/vgdrbd/data as the DRBD backing device, /dev/vdc spare |
| DRBD node 2 | drbd2 |
192.168.231.12/24 on eth1 |
the same layout; /dev/vdc is used for the backing-device replacement exercise |
| Independent client | drbdclient |
192.168.231.13/24 on eth1 |
NFSv4 mount of the current primary's export |
Each host also has a management address on a separate network. The practice
addresses and the DRBD port are examples; use names and addresses that
match your own network. The data disks in these guests are small and
disposable, and the virtio device names /dev/vdb and /dev/vdc are stable
enough for this example. On physical hardware, use persistent paths such as
/dev/disk/by-id/ so that a replaced controller or reordered disk does not make
a node attach the wrong device.
Commands entered in john's ordinary shell begin with $; commands entered
in a root shell begin with #. The prompt marker is not typed. Most storage
commands in this chapter are run from john's shell with $ sudo command.
The practice account has passwordless sudo to keep the examples short; on a
production host sudo normally asks for a password, and the commands are
unchanged. If you enter a root shell with sudo -i, leave it with exit and
remember that root's ~ is not /home/john.
Keep the practice files under a named workspace in the reader account:
$ mkdir -p ~/debian-handbook/drbd
$ cd ~/debian-handbook/drbd
Neither command prints anything when it succeeds. Create the same workspace on
both DRBD nodes and on the client. The examples write preserved copies there;
they do not use /tmp, because a preserved split-brain copy must survive a
reboot until an administrator has examined it.
The topology has two distinct networks. The management network carries SSH and
package traffic. The practice network on eth1 carries DRBD
replication and NFS client traffic. Keeping them separate means a firewall
rule, a saturated link, or a deliberate isolation exercise on eth1 does not
cut the administrative session used to repair it.
Figure 31.1. Two DRBD nodes, an independent NFS client, and the separate management path. The replication link carries protocol C writes between the node addresses on TCP port 7789. The client reaches only the mounted filesystem on the current primary.
The example assumes the practice interfaces are already configured. If they
are not, an /etc/network/interfaces.d/eth1 file on drbd1 containing the
following is sufficient for this isolated network:
auto eth1
iface eth1 inet static
address 192.168.231.11
netmask 255.255.255.0
On drbd2, use 192.168.231.12; on drbdclient, use 192.168.231.13. The
interface configuration is covered in Chapter 17.
The resource file names the nodes drbd1 and drbd2, so each node's configured
hostname must match its on block and both names must resolve on both nodes. A
pair of /etc/hosts entries is enough for this example:
192.168.231.11 drbd1
192.168.231.12 drbd2
192.168.231.13 drbdclient