DRBD Installation and Configuration

Step 1

Setting Up the Basics on Your Servers (server1 , server2)

Once you've made sure your machines are ready, you can go ahead and create an equal-sized partition on both machines. At this stage, you DO NOT need to create a filesystem on that partition and mount to OS, because you will do that only once it is running mirrored over DRBD.

fdisk -l

/dev/sda3 7916 8853 7534453+ 83 Linux

Note: type fdisk -l at your command prompt to view a listing of your partitions in a format similar to that shown here. Also, in my case, the partition table is identical on both redundant machines.

The next step after partitioning is getting the packages for Heartbeat version 1.2+ and DRBD version 0.8+ installed and the DRBD kernel module compiled. If you can get these prepackaged for your distribution, it will probably be easier,

[root@server1,2 ~]# yum install heartbeat
[root@server1,2 ~]# yum install kmod-drbd drbd

P.S.: For Centos 5, edit in /etc/yum.conf and append this:
exclude=drbd82 kmod-drbd82*

but if not, you can download them from


[root@server1,2 ~]# rpm -ivh ***.rpm

Now, Set up the LAN cable for HA and cross cable for DRBD for server1,2 netwotk. Then, go to both server /etc/hosts file and add a couple lines, one for your primary and another for your secondary redundant server. Call one server1, the other server2, and finally, call one mail, and set the IP addresses appropriately. It should look something like this:

[root@server1,2 ~]# vi /etc/hosts

## HA server1 server2

Finally, on both your master and slave server, make a folder called "/data", and add the following line to the /etc/fstab file:

(Skip this part if you use HA to auto mount /dev/drbd0 to /data)

[root@server1,2 ~]# vi /etc/fstab

/dev/drbd0 /data ext3 noauto 0 0

Step 2

Configuring DRBD

Editing server1 and server2 DRBD configuration:

[root@local ~]# vi /etc/drbd.conf resource drbd0 { protocol C; startup { degr-wfc-timeout 30; # 30 sec. wfc-timeout 30; # 30 sec. } disk { on-io-error detach; } net { cram-hmac-alg "sha1"; shared-secret "FooFunFactory"; } syncer { rate 100M; al-extents 257; } on server1 { device /dev/drbd0; disk /dev/sda3; address; meta-disk internal; } on server2 { device /dev/drbd0; disk /dev/sda3; address; meta-disk internal; } }

Now let's start the DRBD daemon on both nodes, but before this we want to start DRBD daemon on the next reboot. For this we will use the command chkconfig on both nodes.

[root@server1,2 ~]# drbdadm create-md drbd0
[root@server1,2 ~]# /etc/init.d/drbd start
[root@server1,2 ~]# chkconfig drbd on

** P.S. If you count the problem like this:
Device size would be truncated, which
would corrupt data and result in
'access beyond end of device' errors.
You need to either
   * use external meta data (recommended)
   * shrink that filesystem first
   * zero out the device (destroy the filesystem)
Operation refused.
Use this command to DESTROY the device which is mounted for drbd
dd if=/dev/zero bs=1M count=1 of=/dev/sdXYZ; sync

Step 3

Set primary node for server1 and secondary node for server2:

Make server1 to drbd primary node:

[root@server1 ~]# drbdsetup /dev/drbd0 primary -o [root@server1 ~]# cat /proc/drbd 0: cs:Connected st:Primary/Secondary ds:UpToDate/Inconsistent r--- ...

Make server2 to drbd secondary node:

[root@server2 ~]# drbdsetup /dev/drbd0 secondary [root@server2 ~]# cat /proc/drbd 0: cs:Connected st:Secondary/Primary ds:UpToDate/UpToDate r--- ...

Step 4

After drbd sync between server1 and server2 is completed (cat /proc/drbd).
Then make FileSystem of /dev/drbd0 (to avoid the problem of meta-data for first time.)
Then mount /dev/drbd0 to /data in primary node server1

[root@server1 ~]# mkfs.ext3 /dev/drbd0
[root@server1 ~]# mount /dev/drbd0 /data

Now you can put the files in /data in primary node server1 which is mounted to raw device /dev/drbd0.

Step 5

Configure HA

If you use HA to control DRBD , first dismount /dev/drbd0 before you done in step4 and 'chkconfig httpd off'

[root@server1 ~]# umount /dev/drbd0
[root@server1,2 ~]# chkconfig httpd off
[root@server1,2 ~]# chkconfig mysqld off

Refer to our site HA configuration

But little different in /etc/ha.d/haresources: (if you have services qmail,httpd,mysqld)

[root@server1,2 ~]# vi /etc/ha.d/haresources

server1 IPaddr:: drbddisk::drbd0 Filesystem::/dev/drbd0::/data::ext3 mysqld qmail httpd MailTo::abc@abc.com::Heartbeat_Notification

To avoid drbd fail and auto-reboot problem while hearbeat+drbd

[root@server1,2 ~]# vi /etc/ha.d/resource.d/drbddisk
replace all "exit 1" to "exit 0"

Start the heartbeat in server1,2, use command to check primary drbd and HA is available in server1:

[root@server1 ~]# df -h
[root@server1 ~]# /etc/init.d/drbd status
[root@server1 ~]# tail -f /var/log/ha-log

Try stop heartbeat in server1, wait few second for takeover, use back the command to check primary drbd and HA is available in server2. If OK sstart back heartbeat in server to takeover primary back

After all, HA and DRBD is running and install successful!

How to test change server2 to primary node and mount /dev/drbd0 manually??

(Skip this part if you use HA to auto take over and mount /dev/drbd0 to /data)

Umount DRBD's block device and make the primary node "secondary":

[root@server1 ~]# umount /data
[root@server1 ~]# drbdadm secondary all

Make the server2 primary and mount block device on /data:

[root@server2 ~]# drbdsetup /dev/drbd0 primary -o
[root@server2 ~]# mount /dev/drbd0 /data
[root@server2 ~]# ls -lah /data

Server is hosted by Alanstudio
Linux Operating System

Recommend screen resolution 1024 x 768 / IE / FireFox
Alan Studio © 2007 by Alan Cheung Hin Lun. All rights reserved.