Contents
Abstract
The distributed replicated block device (DRBD*) allows you to create a mirror of two block devices that are located at two different sites across an IP network. When used with OpenAIS, DRBD supports distributed high-availability Linux clusters. This chapter shows you how to install and set up DRBD.
DRBD replicates data on the primary device to the secondary device in a way that ensures that both copies of the data remain identical. Think of it as a networked RAID 1. It mirrors data in real-time, so its replication occurs continuously. Applications do not need to know that in fact their data is stored on different disks.
![]() | Unencrypted Data |
|---|---|
The data traffic between mirrors is not encrypted. For secure data exchange, you should deploy a Virtual Private Network (VPN) solution for the connection. | |
DRBD is a Linux Kernel module and sits between the I/O scheduler at the lower end and the file system at the upper end, see Figure 15.1, “Position of DRBD within Linux”. To communicate with DRBD, users use the high-level command drbdadm. For maximum flexibility DRBD comes with the low-level tool drbdsetup.
DRBD allows you to use any block device supported by Linux, usually:
partition or complete hard disk
software RAID
Logical Volume Manager (LVM)
Enterprise Volume Management System (EVMS)
By default, DRBD uses the TCP ports 7788 and higher
for communication between DRBD nodes. Make sure that your firewall does
not prevent communication on the used ports.
You must set up the DRBD devices before creating file systems on them.
Everything pertaining to user data should be done solely via the
/dev/drbd_ device and
not on the raw device, as DRBD uses the last part of the raw device for
metadata. Using the raw device will cause inconsistent data.
N
With udev integration, you will also get symbolic links in the form
/dev/drbd/by-res/
which are easier to use and provide safety against misremembering the
devices' minor number.
RESOURCES
For example, if the raw device is 1024 MB in size, the DRBD device has
only 1023 MB available for data, with about 70 KB hidden and reserved for the
metadata. Any attempt to access the remaining kilobytes via
/dev/drbd
fails because it is not available for user data.
N
To install the needed packages for DRBD, install the High Availability Extension Add-On product on both SUSE Linux Enterprise Server machines in your networked cluster as described in Part I, “Installation and Setup”. Installing High Availability Extension also installs the DRBD program files.
If you do not need the complete cluster stack but just want to use DRBD,
refer to Table 15.1, “DRBD RPM Packages”. It contains a list of
all RPM packages for DRBD. Recently, the drbd
package has been split into separate packages.
Table 15.1. DRBD RPM Packages¶
|
Filename |
Explanation |
|---|---|
|
|
Convenience package, split into other |
|
|
Programmable bash completion support for drbdadm |
|
|
Heartbeat resource agent for DRBD (only needed for Heartbeat) |
|
|
Kernel module for DRBD (needed) |
|
|
Xen Kernel module for DRBD |
|
|
udev integration scripts for DRBD, managing symlinks to DRBD devices
in |
|
|
Management utilities for DRBD (needed) |
|
|
Pacemaker resource agent for DRBD |
|
|
Xen block device management script for DRBD |
|
|
YaST DRBD Configuration (recommended) |
To simplify the work with drbdadm, use the Bash
completion support in the RPM package
drbd-bash-completion. If you want to enable it
in your current shell session, insert the following command:
root # source /etc/bash_completion.d/drbdadm.sh
To use it permanently for root, create, or extend a file
/root/.bashrc and insert the previous line.
![]() | Adjustments Needed |
|---|---|
The following procedure uses the server names alice and bob, and the
cluster resource name | |
Before you start configuring DRBD, make sure the block devices in your
Linux nodes are ready and partitioned (if needed). The following
procedure assumes you have two nodes, alice and bob, and that they should use the
TCP port 7788. Make sure this port is open in your
firewall.
To set up DRBD manually, proceed as follows:
Procedure 15.1. Manually Configuring DRBD¶
Put your cluster in maintenance mode, if the cluster is already using DRBD:
root # crm configure property maintenance-mode=trueIf you skip this step when your cluster uses already DRBD, a syntax error in the live configuration will lead to a service shutdown.
Log in as user root.
Change DRBD's configuration files:
Open the file /etc/drbd.conf and insert the
following lines, if they do not exist yet:
include "drbd.d/global_common.conf"; include "drbd.d/*.res";
Beginning with DRBD 8.3 the configuration file is split into separate
files, located under the directory /etc/drbd.d/.
Open the file /etc/drbd.d/global_common.conf. It
contains already some pre-defined values. Go to the
startup section and insert these lines:
startup {
# wfc-timeout degr-wfc-timeout outdated-wfc-timeout
# wait-after-sb;
wfc-timeout 100;
degr-wfc-timeout 120;
}These options are used to reduce the timeouts when booting, see http://www.drbd.org/users-guide-emb/re-drbdconf.html for more details.
Create the file /etc/drbd.d/r0.res, change the
lines according to your situation, and save it:
resource r0 {
device /dev/drbd0;
disk /dev/sda1;
meta-disk internal;
on alice {
address 192.168.1.10:7788;
}
on bob {
address 192.168.1.11:7788;
}
syncer {
rate 7M;
}
}
Name that allows some association to the service that needs them.
For example, | |
The device name for DRBD and its minor number.
In the example above, the minor number 0 is used for DRBD.
The udev integration scripts will give you a symbolic link
| |
The raw device that is replicated between nodes. Note, in this example
the devices are the same on both nodes. If you need different
devices, move the | |
The meta-disk parameter usually contains the value
| |
The | |
The IP address and port number of the respective node. Each
resource needs an individual port, usually starting with
| |
The synchronization rate. Set it to one third of the lower of the disk- and network bandwidth. It only limits the resynchronization, not the replication. |
Check the syntax of your configuration file(s). If the following command returns an error, verify your files:
root # drbdadm dump allIf you have configured Csync2 (which should be the default), the DRBD configuration files are already included in the list of files which need to be synchronized. To synchronize them, use:
root # csync2 -xv /etc/drbd.d/If you do not have Csync2 (or do not want to use it), copy the DRBD configuration files manually to the other node:
root # scp /etc/drbd.conf bob:/etc/
scp /etc/drbd.d/* bob:/etc/drbd.d/Initialize the meta data on both systems by entering the following on each node:
root #drbdadm create-md r0root #rcdrbd start
If your disk already contains a file system that you do not need anymore, destroy the file system structure with the following command and repeat this step:
root # dd if=/dev/zero of=/dev/sda1 count=16 bs=1MWatch the DRBD status by entering the following on each node:
root # rcdrbd statusYou should get something like this:
[... version string omitted ...] m:res cs ro ds p mounted fstype 0:r0 Connected Secondary/Secondary Inconsistent/Inconsistent C
Start the resync process on your intended primary node (alice in this case):
root # drbdadm -- --overwrite-data-of-peer primary r0Check the status again with rcdrbd status and you get:
... m:res cs ro ds p mounted fstype 0:r0 Connected Primary/Secondary UpToDate/UpToDate C
The status in the ds row (disk status) must be
UpToDate on both nodes.
Create your file system on top of your DRBD device, for example:
root # mkfs.ext3 /dev/drbd/by-res/r0/0Mount the file system and use it:
root # mount /dev/drbd /mnt/Reset the cluster's maintenance mode flag:
root # crm configure property maintenance-mode=falseAlternatively, to use YaST to configure DRBD, proceed as follows:
Procedure 15.2. Using YaST to Configure DRBD¶
Start YaST and select the configuration module +. If you already have a DRBD configuration, YaST warns
you. YaST will change your configuration and will save your old DRBD
configuration files as *.YaSTsave.
Leave the booting flag in + as it is
(by default it is off);
do not change that as Pacemaker manages this service.
The actual configuration of the resource is done in (see Figure 15.2, “Resource Configuration”).
Press to create a new resource. The following parameters need to be set twice:
|
|
The name of the resource (mandatory) |
|
|
The host name of the relevant node |
|
|
The IP address and port number (default 7788) for the respective node |
|
|
The block device path that is used to access the
replicated data. If the device contains a minor number, the associated block device is
usually named |
|
|
The device that is replicated between both nodes. |
|
|
The is either set to the value
A real device may also be used for multiple drbd resources. For
example, if your is
|
All of these options are explained in the examples in the
/usr/share/doc/packages/drbd-utils/drbd.conf file
and in the man page of drbd.conf(5).
If you have configured Csync2 (which should be the default), the DRBD configuration files are already included in the list of files which need to be synchronized. To synchronize them, use:
root # csync2 -xv /etc/drbd.d/If you do not have Csync2 (or do not want to use it), copy the DRBD configuration files manually to the other node (here, another node with the name bob):
root # scp /etc/drbd.conf bob:/etc/
scp /etc/drbd.d/* bob:/etc/drbd.d/Initialize and start the DRBD service on both systems by entering the following on each node:
root #drbdadm create-md r0root #rcdrbrd start
Configure alice as the primary node by entering
the following on alice:
root # drbdsetup /dev/drbd0 primary --overwrite-data-of-peerCheck the DRBD service status by entering the following on each node:
rcdrbd status
Before proceeding, wait until the block devices on both nodes are fully synchronized. Repeat the rcdrbd status command to follow the synchronization progress.
After the block devices on both nodes are fully synchronized, format
the DRBD device on the primary with your preferred file system. Any
Linux file system can be used.
It is recommended to use the
/dev/drbd/by-res/
name.
RESOURCE
If the install and configuration procedures worked as expected, you are ready to run a basic test of the DRBD functionality. This test also helps with understanding how the software works.
Test the DRBD service on alice.
Open a terminal console, then log in as
root.
Create a mount point on alice, such as
/srv/r0:
root # mkdir -p /srv/r0Mount the drbd device:
root # mount -o rw /dev/drbd0 /srv/r0Create a file from the primary node:
root # touch /srv/r0/from_aliceUnmount the disk on alice:
root # umount /srv/r0Downgrade the DRBD service on alice by typing the following command on alice:
root # drbdadm secondaryTest the DRBD service on bob.
Open a terminal console, then log in as
root on bob.
On bob, promote the DRBD service to primary:
root # drbdadm primaryOn bob, check to see if bob is primary:
root # rcdrbd status
On bob, create a mount point such as
/srv/r0mount:
root # mkdir /srv/r0mountOn bob, mount the DRBD device:
root # mount -o rw /dev/drbd_r0 /srv/r0mountVerify that the file you created on alice exists:
root # ls /srv/r0
The /srv/r0mount/from_alice file should be
listed.
If the service is working on both nodes, the DRBD setup is complete.
Set up alice as the primary again.
Dismount the disk on bob by typing the following command on bob:
root # umount /srv/r0Downgrade the DRBD service on bob by typing the following command on bob:
root # drbdadm secondaryOn alice, promote the DRBD service to primary:
root # drbdadm primaryOn alice, check to see if alice is primary:
rcdrbd status
To get the service to automatically start and fail over if the server has a problem, you can set up DRBD as a high availability service with OpenAIS. For information about installing and configuring OpenAIS for SUSE Linux Enterprise 11 see Part II, “Configuration and Administration”.
There are several ways to tune DRBD:
Use an external disk for your metadata. This might help, at the cost of maintenance ease.
Create a udev rule to change the read-ahead of the DRBD device. Save
the following line in the file
/etc/udev/rules.d/82-dm-ra.rules and change the
read_ahead_kb value to your workload:
ACTION=="add", KERNEL=="dm-*", ATTR{bdi/read_ahead_kb}="4100"This line only works if you use LVM.
Tune your network connection, by changing the receive and send buffer settings via sysctl.
Change the max-buffers,
max-epoch-size or both in the DRBD
configuration.
Increase the al-extents value, depending
on your IO patterns.
If you have a hardware RAID controller with a BBU (Battery Backup Unit),
you might benefit from setting no-disk-flushes,
no-disk-barrier and/or no-md-flushes.
Enable read-balancing depending on your workload. See http://blogs.linbit.com/p/256/read-balancing/ for more details.
The DRBD setup involves many different components and problems may arise from different sources. The following sections cover several common scenarios and recommend various solutions.
If the initial DRBD setup does not work as expected, there is probably something wrong with your configuration.
To get information about the configuration:
Open a terminal console, then log in as root.
Test the configuration file by running drbdadm with the -d option. Enter the following command:
root # drbdadm -d adjust r0In a dry run of the adjust option, drbdadm compares the actual configuration of the DRBD resource with your DRBD configuration file, but it does not execute the calls. Review the output to make sure you know the source and cause of any errors.
If there are errors in the /etc/drbd.d/* and
drbd.conf files, correct them before continuing.
If the partitions and settings are correct, run drbdadm again without the -d option.
root # drbdadm adjust r0This applies the configuration file to the DRBD resource.
For DRBD, host names are case-sensitive (Node0
would be a different host than node0),
and compared to the host name as stored in the Kernel (see the
uname -n output).
If you have several network devices and want to use a dedicated network
device, the host name will likely not resolve to the used IP address. In
this case, use the parameter disable-ip-verification.
If your system cannot connect to the peer, this might be a problem
with your local firewall. By default, DRBD uses the TCP port
7788 to access the other node. Make sure that this
port is accessible on both nodes.
In cases when DRBD does not know which of the real devices holds the latest data, it changes to a split brain condition. In this case, the respective DRBD subsystems come up as secondary and do not connect to each other. In this case, the following message can be found in the logging data:
Split-Brain detected, dropping connection!
To resolve this situation, enter the following on the node which has data to be discarded:
root #drbdadm secondary r0root #drbdadm -- --discard-my-data connect r0
On the node which has the latest data enter the following:
root # drbdadm connect r0That resolves the issue by overwriting one node's data with the peer's data, therefore getting a consistent view on both nodes.
The following open source resources are available for DRBD:
The project home page http://www.drbd.org.
See Highly Available NFS Storage with DRBD and Pacemaker (↑Highly Available NFS Storage with DRBD and Pacemaker).
http://clusterlabs.org/wiki/DRBD_HowTo_1.0 by the Linux Pacemaker Cluster Stack Project.
The following man pages for DRBD are available in the distribution: drbd(8), drbddisk(8), drbdsetup(8), drbdsetup(8), drbdadm(8), drbd.conf(5).
Find a commented example configuration for DRBD at
/usr/share/doc/packages/drbd/drbd.conf
Furthermore, for easier storage administration across your cluster, see the recent announcement about the DRBD-Manager at http://blogs.linbit.com/p/666/drbd-manager.