DRBD

From Leo's Notes
Revision as of 20:35, 31 March 2015 by Leo (talk | contribs) (→Configuration)
This page was last edited on 31 March 2015, at 20:35.

DRBD (Distributed Replicated Block Device) is a virtual block device that is distributed across two or more machines.

Installation

On a clean installation of RHEL 7 or equivalent, run updates, and ensure that you have NTP and a recent kernel installed.

From ElRepo

Get the DRBD packages from ELRepo:

rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
yum install drbd84-utils kmod-drbd84

From Source

Install prerequisites:

yum install gcc flex make autoconf m4

Get the source from their git repository. Releases from tarballs may fail depending on which kernel version you're using.

git clone git://git.drbd.org/drbd-8.4.git
cd drbd-8.4
make
make install

The make install should have loaded the module and you can verify this:

lsmod | grep drbd

If it isn't loaded, load it using modprobe

modprobe drbd

Compile the userspace utilities:

git clone git://git.drbd.org/drbd-utils.git
cd drbd-utils
./aclocal.sh
./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc
make
make install

Note: I got errors about man pages not being found. Ugh.


Configuration

This section will configure DRBD for use in a redundant MySQL setup.

DRBD syncs volumes. If you did not configure a partition or have a separate disk to mirror, you can create a file volume instead.

On all nodes:

mkdir /var/drbd
cd /var/drbd

# Create a 50GB volume
dd if=/dev/zero of=data_volume.dat bs=1024 count=52428800

# Create a partition
fdisk data_volume.dat

# Create a device
losetup /dev/loop0 /var/drbd/data_volume.dat
kpartx -v -a /var/drbd/data_volume.dat
ls /dev/mapper/

mkdir -p /mnt/drbd
echo "/dev/drbd0 /mnt/drbd ext4 noauto 0 0 " >>  /etc/fstab

On all nodes, configure the DRBD config in /etc/drbd.d/*conf. You may want to disable the survey.

On all nodes, configure DRBD by creating a file in /etc/drbd.d/mysql.res with:

resource mysql {
	disk {
		on-io-error detach;
	}

	device    /dev/drbd0;
	disk      /dev/mapper/loop0p1;
	meta-disk internal;

	on $hostname {
		address 172.20.10.10:7700;
	}

	on $hostname {
		address 172.20.10.9:7700;
	}
}

TODO: Can you just use /dev/loop0 instead?!

Be sure to rename the hostnames so that it matches the actual machine's hostname. Otherwise, when you try creating the resource, you will get an error like:

'mysql' not defined in your config (for this host).

On all nodes, create the resource:

drbdadm -v create-md mysql

If it complains about finding a filesystem, zero out the first few blocks using dd and try again.

On all nodes, start the resource:

drbdadm up mysql

On one of the nodes, force it to be the primary node for the resource:

drbdadm -- --force primary mysql

On the primary node, create a file system:

mkfs -t xfs /dev/drbd0

On the primary node, set it back to a secondary node:

drbadm secondary mysql

On all the nodes, verify the role. They should all be Secondary/Secondary.

drbadm role mysql

See Also