DRBD in Action
What is DRBD?
DRBD refers to block devices designed as a building block to form high availability (HA) clusters. This is done by mirroring a whole block device via an assigned network. DRBD can be understood as network based raid-1.
In the illustration above, the two orange boxes represent two servers that form an HA cluster. The boxes contain the usual components of a Linux kernel: file system, buffer cache, disk scheduler, disk drivers, TCP/IP stack and network interface card (NIC) driver. The black arrows illustrate the flow of data between these components.
The orange arrows show the flow of data, as DRBD mirrors the data of a highly available service from the active node of the HA cluster to the standby node of the HA cluster.
DRBD got merged into Linux mainline since 2.6.33.
- Ubuntu 12.10 x86_64
- kernel 3.5.0
- DRBD 8.3.13
Distributed Replicated Block Device (DRBD) mirrors block devices between multiple hosts. The replication is transparent to other applications on the host systems. Any block device hard disks, partitions, RAID devices, logical volumes, etc can be mirrored.
To get started using drbd, first install the necessary packages
In single-primary mode, any resource is, at any given time, in the primary role on only one cluster member. Since it is thus guaranteed that only one cluster node manipulates the data at any moment, this mode can be used with any conventional file system (ext3, ext4, XFS etc.).
Deploying DRBD in single-primary mode is the canonical approach for high availability (fail-over capable) clusters.
- drbd1 10.1.1.11
- drbd2 10.1.1.12
Added a new HDD dedicated for DRBD on each box, in this case, both /dev/sdb.
To configure drbd, on drbd1 edit /etc/drbd.conf
Use scp or rsync to copy the file to drbd2 over ssh.
Use drbdadm utility to initialize the meta data storage. On each server execute
On both hosts, start (restart if already started) the drbd daemon
On the drbd1, or whichever host you wish to be the primary, run
After executing the above command, the data will start syncing with the secondary host. To watch the progress, on drbd1 enter the following
To stop watching, use Ctrl+c
Finally, create a file system out of /dev/drbd0 and mount it on drbd1
To test that the data is actually syncing between the hosts copy some files on the drbd01, the primary, to /drbd
Next, unmount /drbd
Demote the primary server (drbd1) to the secondary role
Now on the secondary server (drbd2) promote it to the primary role
Lastly, mount the partition
/drbd on drbd2 should be mirrored, it's been replicated from drbd1.