31.5. Integrating DRBD with Cluster Management

A cluster manager turns promotion, mounting, service startup, and address movement into an ordered policy. It also supplies the membership and fencing that DRBD 8.4 does not provide. The integration is only as safe as its weakest constraint: a promotable resource without fencing, or a filesystem colocated with the wrong clone instance, can still produce two writers. Dual-primary operation is a separate design that requires a cluster-aware filesystem.

31.5.1. Promotable Resources and Single-Primary Service Design

A cluster manager turns the manual operations in this chapter into policy. The DRBD resource is represented as a promotable resource: the manager may start it as a secondary on both nodes, but only one instance may be promoted to the primary role at a time. In Pacemaker's older terminology this was a master/slave resource; current configurations use the promotable meta-attribute and promotable clones. Debian's drbd-utils package ships the OCF agent at /usr/lib/ocf/resource.d/linbit/drbd, referenced as ocf:linbit:drbd. The agent wraps the same drbdadm operations used manually: configure the resource, monitor its connection and disk state, promote one instance, and demote it during a controlled stop.

The service design should keep a single active writer for a local filesystem. A typical stack is:

Order Resource Role
1 DRBD promotable clone Replicates the block device and elects one primary
2 Filesystem Mounts /dev/drbd0 on the promoted node only
3 NFS server or application service Serves the mounted filesystem
4 Virtual IP address Gives clients a stable address that moves with the service
5 Monitoring or health check Confirms the application, not just the process, is usable

The filesystem resource must be colocated with the promoted DRBD instance, not merely with "some" instance of the clone. If the filesystem starts on a secondary node, the mount fails or, worse, the manager might force a promotion for the wrong reason. The service must be colocated with the filesystem, and the virtual IP must be colocated with the service. This chain is what makes a single-primary service coherent.

A cluster manager does not make an unsafe application safe. A database that was in the middle of a transaction when the primary died still needs its own recovery. An NFS server still needs lock and grace-period handling. A web application with local session files still needs a plan for those files. DRBD replicates blocks; it does not replicate application memory, locks, or client connections. The cluster layer moves the service; the application must be able to recover on the new node.

31.5.2. Ordering Replication, Filesystem Mounts, Services, and Client Addresses

Ordering is the difference between a failover and an outage. The cluster manager must start the layers in dependency order and stop them in reverse:

  1. Configure DRBD and establish the replication link on both nodes.
  2. Promote exactly one DRBD instance.
  3. Mount the filesystem on the promoted node.
  4. Start the service that uses the mount.
  5. Move the client address to the promoted node.
  6. On shutdown, stop accepting client traffic, stop the service, unmount, and demote.

The virtual IP should move after the service is ready, not before. A client that connects to the new address while the filesystem is still mounting sees a connection refusal or an incomplete service. Conversely, stopping the address first drains new clients while existing requests finish. The NFS server needs its export to be present before the address accepts clients. The filesystem needs the DRBD device to be primary before it mounts.

A systemd-only arrangement can start DRBD at boot with drbd.service, but it does not provide membership, quorum, fencing, or ordered promotion across two hosts. Debian's drbd@.service configures one resource, and drbd-promote@.service can promote it, but enabling those units independently on both nodes creates exactly the two-writer risk the cluster manager is meant to prevent. Use systemd for host-local startup and a cluster manager for cross-host ownership. Chapter 32 shows a Pacemaker configuration that orders these resources.

The client address is part of the contract. In the manual example, drbdclient mounts drbd2:/srv/drbd-data; after a switchover it must unmount and mount the new primary. A production design should use a virtual IP or a DNS name that moves with the service, and the client should reconnect automatically. The server name must not be tied to the physical host that happens to be primary. Even with a virtual IP, an NFS client can experience a grace period and must be prepared to retry. Test the client behavior, not just the server's resource state.

31.5.3. Fencing, Loss of Quorum, and Preventing Two Active Writers

Fencing, also called STONITH (Shoot The Other Node In The Head), is the mechanism that makes a failed node stop writing before the survivor takes over. A power controller, an IPMI/BMC reset, a watchdog, or a hypervisor-level reset can all serve as a fence. The important property is that the fence is verified: the cluster must know that the old node is no longer running and no longer has the filesystem mounted before it promotes the new primary.

Without fencing, a network partition can produce two nodes that each believe the other is dead. DRBD's single-primary rule stops normal dual writes while the link is connected, but it cannot stop an administrator or an unmanaged script from force-promoting both sides after a disconnect. The result is split brain. The manual procedure in section 31.4.3 preserves data for a human decision; a cluster manager should prevent the situation instead.

Quorum is the cluster's agreement about which nodes are allowed to act. In a two-node cluster, losing the heartbeat link leaves each node without a majority. A quorum device on a third host can break the tie, or the cluster can be configured to stop resources rather than risk two writers. The exact policy belongs to the cluster manager and must be tested by cutting the heartbeat link, not just by stopping a service. DRBD 8.4 does not provide a DRBD-level quorum that could substitute for this; section 31.4.4 explains the version boundary.

A safe failover sequence is therefore: detect the failure, fence the old node, confirm that the fence succeeded, promote the surviving DRBD instance, mount the filesystem, start the service, and move the address. If fencing fails, the cluster should not promote. A temporary outage is preferable to two nodes writing the same ext4 filesystem. The same rule applies to manual operations: do not use drbdadm primary --force on a node until you have established that the old primary is stopped.

31.5.4. Dual-Primary Configurations and Cluster-Aware Filesystem Requirements

DRBD 8.4 can be configured with allow-two-primaries in the net section. That option permits both nodes to have the primary role while connected. It does not make a local filesystem safe. Ext4, XFS, and similar filesystems assume a single writer and will corrupt metadata if both nodes mount the same device. The DRBD manual is explicit that dual-primary is intended for a shared-storage filesystem such as OCFS2 or GFS2, which coordinate locking through a distributed lock manager.

A dual-primary design therefore needs all of the following:

  • A cluster-aware filesystem such as GFS2 or OCFS2, formatted on the DRBD device and configured with its cluster locking service.
  • A cluster manager that maintains membership and fencing for the filesystem's lock manager, not just for DRBD.
  • A workload that can actually run on both nodes without corrupting application state, such as a service designed for shared storage.
  • Testing of lock recovery, node loss, and the interaction between DRBD and the filesystem's recovery, not just a successful mount on two nodes.

Dual-primary is not a shortcut for active-active NFS. NFS servers sharing a filesystem need lock coordination and a service design such as CTDB, and the underlying filesystem must support the required locking. A single-primary DRBD resource with one NFS server is simpler and is the correct baseline for this chapter. This chapter uses ext4 with a single primary; a dual-primary or cluster-aware filesystem is a separate design with its own failure testing.