Network RAID with DRBD on Ubuntu

In this tutorial i will show you how to setup drbd on two Ubuntu machines.
I used Ubuntu 12.04 and VirtualBox for this.

first, make sure that the two machines can resolve the hostnames.
You can do that by either using DNS or the “/etc/hosts” file.

Server 1&2 “/etc/hosts”:

127.0.0.1       localhost
192.168.1.116   server2
192.168.1.123   server1
192.168.1.70    cluster

You can check the hostname of your machine with

uname -u

or

hostname

Next, you have to install drbd and load the kernel module:

apt-get install drbd8-utils
modprobe drbd

If everything went fine,

lsmod | grep drbd

should output something like this:

drbd                  256171  4 
lru_cache              14379  1 drbd

Then edit “etc/drbd.conf” on both machines to look similiar to this:

global { usage-count no; }
common { syncer { rate 10M; } }
resource r0 {
        protocol C;
        startup {
                wfc-timeout  15;
                degr-wfc-timeout 60;
        }
        net {
                cram-hmac-alg sha1;
                shared-secret "putsupersecretpasswordhere";
        }
        on server1 {
                device /dev/drbd0;
                disk /dev/sdb1;
                address 192.168.1.123:7788;
                meta-disk internal;
        }
        on server2 {
                device /dev/drbd0;
                disk /dev/sdb1;
                address 192.168.1.116:7788;
                meta-disk internal;
        }
}

You have to fill in the correct hostnames of your machines instead of server1 & server2,
and the right disk and IP-addresses.

Again on both machines run:

drbdadm create-md r0

This creates meta data for the drbd resources.

Now we are ready to start drbd using

/etc/init.d/drbd start

Run the following only on the primary machine (the one which will be sending the data to the other)

drbdadm -- --overwrite-data-of-peer primary all

Again, only on the primary machine run:

mkfs.ext4 /dev/drbd0
mkdir /data
mount /dev/drbd0 /data

This creates a filesystem on the drbd0 block device and mounts it to “/data”.

Any files you place in “/data” should now be replicated to the other machine
and can be retrieved when mounting “/dev/drbd0” on the second machine.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: