DRBD – Installation & Configuration

Posted on Posted in linux, Mysql
  • Hi, in this post I’ll splain how configure a DRBD infraestructure, but first, What’s 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.

 

Installation

The installation that I’ll do is in a RedHat system.

Download the software

To download the latest version, enter to this webpage or download with wget:

wget http://elrepo.org/linux/elrepo/el5/x86_64/RPMS/kmod-drbd84-8.4.1-1.el5.elrepo.x86_64.rpm
wget http://elrepo.org/linux/elrepo/el5/x86_64/RPMS/drbd84-utils-8.4.1-1.el5.elrepo.x86_64.rpm

Install DRBD

So easy than:

[root@nodo1 DRBD]# rpm -ivh *.rpm
warning: drbd84-utils-8.4.1-1.el5.elrepo.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID baadae52
Preparing...                ########################################### [100%]
   1:drbd84-utils           ########################################### [ 50%]
   2:kmod-drbd84            ########################################### [100%]
Working. This may take some time ...
Done.

In the other node

[root@nodo2 DRBD]# rpm -ivh *.rpm
warning: drbd84-utils-8.4.1-1.el5.elrepo.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID baadae52
Preparing...                ########################################### [100%]
   1:drbd84-utils           ########################################### [ 50%]
   2:kmod-drbd84            ########################################### [100%]
Working. This may take some time ...
Done.

Configuration

The official documentation
Copy the dist configuration

cp -pr /etc/drbd.conf /etc/drbd.conf-DIST

SHA1

To secure and trust the communication we’ll need a sha1 key, to generate one:

[root@nodo1 DRBD]# sha1sum /etc/drbd.conf
8a6cxxxxxxxxxxxxxxxxxxxxx49xxxxxxxxfb3  /etc/drbd.conf

DRBD.CONF

The /etc/drbd.conf is the configuration file for drbd, here my configuration:

# You can find an example in  /usr/share/doc/drbd.../drbd.conf.example

include "drbd.d/global_common.conf";

resource DISK1 {
    protocol C;
    net {
        cram-hmac-alg sha1;
        shared-secret "8a6cxxxxxxxxxxxxxxxxxxxxx49xxxxxxxxfb3";
        after-sb-0pri discard-zero-changes;
        after-sb-1pri discard-secondary;
        after-sb-2pri disconnect;
    }
    device    /dev/drbd0;
    disk      /dev/sdc1;
    meta-disk internal;
    on node1 {
        address   10.0.1.1:7789;
    }
    on node2 {
        address   10.0.1.2:7789;
    }
}

As you can see I specify this parameters:

  • RESOURCE: The name of the resource
  • PROTOCOL: In this case C means synchronous
  • NET: The SHA1 key, that have the same in the two nodes
    • after-sb-0pri : When a Split Brain ocurrs, and no data have changed, the two nodes connect normally.
    • after-sb-1pri : If some data have been changed, discard the secondary data and synchronize with the primary
    • after-sb-2pri : If the previous option is impossible disconnect the two nodes, in this case manually Split-Brain solution is required
  • DEVICE: Virtual device, the patch to the fisical device.
  • DISK: Fisical device
  • META-DISK: Meta data are stored in the same disk (sdc1)
  • ON <NODE>: The nodes that form the cluster

Creating the resource

This commands in the two nodes

Create partition

Create the partition without format

[root@node1 ~]# fdisk /dev/sdc
[root@node2 ~]# fdisk /dev/sdc

Create resource

[root@node1 ~]# drbdadm create-md DISK1
Writing meta data...
initializing activity log
NOT initializing bitmap
New drbd meta data block successfully created.
[root@node2 ~]# drbdadm create-md DISK1
Writing meta data...
initializing activity log
NOT initializing bitmap
New drbd meta data block successfully created.

Activate the Resource

Be sure that the drbd module is load (lsmod), if not load it:

[root@nodex ~]# modprobe drbd

Now activate the resource DISK1:

[root@node1 ~]# drbdadm up DISK1
[root@node2 ~]# drbdadm up DISK1

Synchronize

Only in the master node, we’ll say that the node1 is the primary:

/sbin/drbdadm -- --overwrite-data-of-peer primary DISK1

We’ll see that the disks synchronization are in progress, adn the state is UpToDate/Inconsistent

Every 2.0s: cat /proc/drbd                                                                                                           Wed Mar 28 13:51:50 2012

version: 8.4.1 (api:1/proto:86-100)
GIT-hash: 91b45df4f8g489w4er2b38we8r4w65ea80 build by dag@Build64R5, 2011-12-21 06:05:25
 0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----
    ns:17540416 nr:0 dw:0 dr:17547264 al:0 bm:1070 lo:0 pe:4 ua:7 ap:0 ep:1 wo:b oos:13917216
        [==========>.........] sync'ed: 55.8% (13588/30716)M
        finish: 0:02:25 speed: 95,716 (89,020) K/sec

When this is over we will see that the state change to UpToDate/UpToDate

Every 2.0s: cat /proc/drbd                                                                                                           Wed Mar 28 13:57:05 2012

version: 8.4.1 (api:1/proto:86-100)
GIT-hash: 91b45df4f8g489w4er2b38we8r4w65ea80 build by dag@Build64R5, 2011-12-21 06:05:25
 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
    ns:31454240 nr:0 dw:0 dr:31454240 al:0 bm:1920 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0

Format the Resource

Only in the master node:

[root@node1 ~]# mkfs.ext3 /dev/drbd0

Testing

Now test the DRBD software:

NODE1

  • In the primary/Master node mount the resource and copy some files:
[root@node1 ~]# mkdir -p /usr/local/drbd
[root@node1 ~]# mount /dev/drbd0 /usr/local/drbd
[root@node1 ~]# rsync -av /root/ /usr/local/drbd
  • Now umount and mark the node1 like secondary
[root@node1 ~]# umount /usr/local/drbd
[root@node1 ~]# drbdadm secondary DISK1

 NODE2

  • Mark this node like primary/master
[root@node2 ~]# drbdadm primary DISK1
  • And mount the resource
[root@node2 ~]# mount /dev/drbd0 /usr/local/drbd

In upcoming posts I’ll explain how configure a Mysql Cluster with Pacemaker, Stonith and DRBD software

One thought on “DRBD – Installation & Configuration

Leave a Reply

Your email address will not be published. Required fields are marked *