DRBD (Distributed Replicated Block Device) is a technology that is used to replicate data over TCP/IP. It is used to build HA Clusters and it can be seen as a RAID-1 implementation over the network.
As you may all know, the DRBD kernel module has now been included into Hardy Heron Server Edition’s kernel, so there is no more source downloading and compiling, which makes it easier to install and configure. Here I’ll show you how to install and and make a simple configuration of DRBD, using one resource (testing). I’ll not cover how to install and configure heartbeat for automatic failover (This will be showed in a next post).
First of all, we will have to install Ubuntu Hardy Heron Server Edition on to servers and manually edit the partition table. We do this to leave FREE SPACE that we will be used later on as the block device for DRBD. If you’ve seen the DRBD + NFS HowTo on HowToForge.com, creating the partitions for DRBD and leaving them unmounted will NOT work, and we won’t we able to create the resource for DRBD. This is why we leave the FREE SPACE, and we will create the partition later on, when the system is installed.
So, after the installation we will have to create the partition, or partitions (in case we are creating an external partition for the meta-data, but in this case it will be internal), that DRBD will use as a block device. For this we will use fdisk and do as follows:
fdisk /dev/sda
n (to create a new partition)
l83 (to create it as logical and format it as Filesystem # 83)
w (to write the changes)
After creating the partitions we will have to REBOOT both servers so that the kernel uses the new partition table. After reboot we have to install drbd8-utils on both servers:
sudo apt-get install drbd8-utils
Now that we have drbd8-utils installed, we can now configure /etc/drbd.conf, which we will configure a simple DRBD resource, as follows:
resource testing { # name of resources
protocol C;
on drbd1 { # first server hostname
device /dev/drbd0; # Name of DRBD device
disk /dev/sda7; # Partition to use, which was created using fdisk
address 172.16.0.130:7788; # IP addres and port number used by drbd
meta-disk internal; # where to store metadata meta-data
}
on drbd2 { # second server hostname
device /dev/drbd0;
disk /dev/sda7;
address 172.16.0.131:7788;
meta-disk internal;
}
disk {
on-io-error detach;
}
net {
max-buffers 2048;
ko-count 4;
}
syncer {
rate 10M;
al-extents 257;
}
startup {
wfc-timeout 0;
degr-wfc-timeout 120; # 2 minutos.
}
}
Note that we are using drbd1 and drbd2 as hostnames. This hostnames must be configured and the servers should be able to ping the other via those hostnames (that means we need to have a DNS server or configure hosts for both servers in /etc/hosts).
After creating the configuration in /etc/drbd.conf, we now can create the DRBD resources. For this we issue the following in both servers:
sudo drbdadm create-md testing
After issuing this, we will be asked for confirmation to create the meta-data in the block device.
Now we have to power off both servers. After powering them off, we start our first server and we will see something similar to this:
After confirming with ‘yes’, we can now start the second server. After the second server is running. both nodes resources are secondary, so we have to make one of them primary. For this, we issue the following on the server we would like to have the resource as primary:
drbdadm -- --overwrite-data-of-peer primary all
We verify this by issuing:
cat /proc/drbd
And this should show something like this:
Well, up to this point, i’ve have showed you how to install and configure DRBD on Hardy, and how to make one of the servers have its resource as primary. But, we still don’t have automatic failover or automatic mounting. In a next post I’ll show how to configure heartbeat to have automatic failover and to take control of the resources, aswell as configuring STONITH to use the meatware device, so that we won’t have a split-brain condition (or at least try). I’ll also show how to configure NFS and MySQL to use this DRBD resource.
BTW, if you have questions you know where to find me :).
August 1, 2008 at 12:23 am
Just to be I am speaking from personal experience here, not as a hater or anything. However I just want to say that DRBD has some really significant drawbacks in real world scenarios.
One sad part of life is that sometimes filesystems get corrupted — maybe bad hardware, some freak bug, whatever — the point is that when they do DRBD will happily replicate your corruption across the network. So at 3:00am when it breaks you have to inform your boss that your HA cluster is actually not so much HA after all. This might be OK for NFS if your data is easily recoverable from backup, but for a large database that is a very bad thing and painful to recover from.
That said, your tutorial is good. Much simpler now that the kmodule is in Hardy!
August 1, 2008 at 2:06 am
Why would you power servers down? Just start the drbd service. I would suggest using redhat-cluster-suite instead of HA. That gives you an option of using GFS on top of DRBD. And if you configure primary-primary DRBD with GFS, you could write on the same drbd disk at the same time from two different servers.
August 1, 2008 at 6:59 am
Great article! But, how do we remove DRBD and rebuild it with another machine?
August 1, 2008 at 8:45 am
Thank you so much! I am installing DRBD this month, and it’s so timely you wrote about this. Looking forward to your next installment on Shoot The Other Node In The Head!
August 1, 2008 at 8:24 pm
Ante: I’m not fan of redhat-cluster-suite, but HA also gives the option to have DRBD in a primary/primary configuration, by installing a Cluster FileSystem such as GFS or OCFS. But it guess it is just a little bit harder to configure.
Shang: the only thing you can remove is drbd8-utils package. Removing it won’t remove the kernel module, but it will remove all the DRBD config files and tools, and it would be as if there was nothing installed, because the DRBD’s kernel module won’t be used.
ryan: Surely DRBD has its drawbacks as every piece of software. On the other hand, DRBD have options to deal with data corruption and so on… Btw, DRBD has paid support. Linbit.com is the company behind DRBD, and, if it wasn’t a good alternative instead of having a SAN, Linbit wouldn’t have as many clients as they do around europe and the US. But well, as you said… it is all about personal experiences.
August 4, 2008 at 12:58 am
[…] DRBD on Hardy Part 2. As you know, in a previous post I showed how to install DRBD in Hardy Heron, in an active/passive configuration. Now, I’m […]
August 4, 2008 at 1:55 am
[…] you know, in a previous post I showed how to install DRBD in Hardy Heron, in an active/passive configuration. Now, I’m […]
August 10, 2008 at 2:42 pm
Slightly offtopic.
Could you please describe the machine that was running in the screenshots? I’m particularly interested in processor count.
August 11, 2008 at 1:23 pm
Well it is my Desktop:
Processor: AMD Athlon 64 X2 3000+
RAM: 2Gb Kingston (800Mhz)
HDD: Samsung 250GB 7200 rpm
MB: Asus M2N SLI
Video: nVidia 8500GT
I got running up to 6 VM’s simultaneously (2x64bit and 4x32bit Guests). Ubuntu Server, with 256 Ram each VM.
August 12, 2008 at 9:34 am
I found your site on technorati and read a few of your other posts. Keep up the good work. I just added your RSS feed to my Google News Reader. Looking forward to reading more from you down the road!
September 2, 2008 at 8:59 am
I disagree
Can you give more info?
September 4, 2008 at 10:13 am
More info about what?
October 16, 2008 at 2:23 pm
[…] as you may know, in previous posts (Post 1, Post 2) I’ve showed you how to install and configure DRBD in an active/passive configuration […]
March 2, 2009 at 4:32 pm
I’ve just recently started experimenting with DRBD and it is confusing! Your tutorial did help a little though. Thanks
March 2, 2009 at 5:55 pm
is my tutorial confusing, or is DRBD confusing?? You might want to test DRBD Management Console… it is out for beta testing 🙂 http://www.drbd.org/mc/management-console/
September 10, 2009 at 5:15 pm
Hi! I was surfing and found your blog post… nice! I love your blog. 🙂 Cheers! Sandra. R.
February 8, 2010 at 10:57 am
Thank you roaksoax. It was very helpfull.
One simple question. How can I automate to send me an email when it fails?…thats it, if ever the primary fails, and the secondary takes the control.
I do not mean the task of sending the mail with an MTA, which I know how to do it, but where can I put this script to send the mail or if there is any elegant way to do it. Thanks