Share, , Google Plus, Pinterest,


Posted in:

DRBD – How to configure DRBD on CentOS 6

DRBD® refers to block devices designed as a building block to form high availability (HA) clusters – Distributed Replicated Block Device.

This is done by mirroring a whole block device via an assigned network.

Distributed Replicated Block Device can be understood as network based raid-1. So, Distributed Replicated Block Device is actually a network based RAID 1.

You are configuring DRBD on your system if you:

  • need to secure data on certain disk and are therefore mirroring your data to another machine via network.
  • configuring High Availability cluster or service.


  • additional disk for synchronization on BOTH MACHINES (preferably same size)
  • network connectivity between machines
  • working DNS resolution (can fix with /etc/hosts file)
  • NTP synchronized times on both nodes

I’ve had problems running drbd84 on CentOS 6.4 running kernel 2.6.32-358.6.1.el6.i686 so i used drbd83 package. Tell me how it works for you…

Let’s start our DRBD CentOS 6.x guide!

1. BOTH MACHINES: Install ELRepo repository

[root@foo1 ~]/bin/rpm -ivh

2. BOTH MACHINES: Install DRBD packages

Install Distributed Replicated Block Device utils and kmod packages from ELRepo (choose the version you prefer – drbd83 or drbd84  – i’ve had problems with drbd84 on kernel 2.6.32-358.6.1.el6.i686).

[root@foo1 ~]/usr/bin/yum install -y kmod-drbd83 drbd83-utils

3. BOTH MACHINES: Insert DRBD module

Insert drbd module manually or reboot both machines if you like.

[root@foo1 ~]/sbin/modprobe drbd

4. BOTH MACHINES: Create DRBD configuration file

Create the Distributed Replicated Block Device resource file (/etc/drbd.d/disk1.res) and transfer it to the other machine (these files need to be exactly the same on both machines!).


resource disk1
startup {
wfc-timeout 30;
outdated-wfc-timeout 20;
degr-wfc-timeout 30;

net {
cram-hmac-alg sha1;
shared-secret sync_disk;

syncer {
rate 100M;
verify-alg sha1;

on {
device minor 1;
disk /dev/sdb;
meta-disk internal;

on {
device minor 1;
disk /dev/sdb;
meta-disk internal;

5. BOTH MACHINES: Edit /etc/hosts file

Make sure that DNS resolution is working as expected! To quickly fix DNS resolution add IP addresses FQDN to /etc/hosts on both machines as follows:

/etc/hosts foo1 foo2

6. BOTH MACHINES: NTP synchronization

Make sure that both machines are using NTP for time synchronization! To quickly fix this add an entry to your /etc/crontab file as follows and choose your NTP sync server:


1 * * * * root ntpdate your.ntp.server

7. BOTH MACHINES: Initialize DRBD meta data

[root@foo1 ~]/sbin/drbdadm create-md disk1

8. BOTH MACHINES: Start DRBD service

Start the Distributed Replicated Block Device service on both nodes:

[root@foo1 ~]/etc/init.d/drbd start

9. Set primary node

On the node you wish to make a PRIMARY node run drbdadm command:

[root@foo1 ~]/sbin/drbdadm -- --overwrite-data-of-peer primary disk1

10. Wait to synchronize

Wait for the Distributed Replicated Block Device disk initial synchronization to complete (100%) and check to confirm you are on primary node:

[root@foo1 ~]cat /proc/drbd
version: 8.3.15 (api:88/proto:86-97)
GIT-hash: 0ce4d235fc02b5c53c1c52c53433d11a694eab8c build by phil@Build32R6, 2012-12-20 20:23:49
1: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r---n-
ns:1060156 nr:0 dw:33260 dr:1034352 al:14 bm:62 lo:9 pe:78 ua:64 ap:0 ep:1 wo:f oos:31424
[==================>.] sync'ed: 97.3% (31424/1048508)K
finish: 0:00:01 speed: 21,240 (15,644) K/sec

[root@foo1 ~]# cat /proc/drbd
version: 8.3.15 (api:88/proto:86-97)
GIT-hash: 0ce4d235fc02b5c53c1c52c53433d11a694eab8c build by phil@Build32R6, 2012-12-20 20:23:49
1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:1081628 nr:0 dw:33260 dr:1048752 al:14 bm:64 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

11. Create filesystem

Create desired filesystem on Distributed Replicated Block Device device:

[root@foo1 ~]/sbin/mkfs.ext4 /dev/drbd1


You can now mount DRBD device on your primary node! Want to learn how to manage DRBD from command line? Read “DRBD Management and Basic Command Usage on CentOS 6” post.

  • Pingback: DRBD Management and Basic Command Usage on CentOS 6 GeekPeek.Net()

  • mr.cavern

    Do you have to execute the script in both machines?

    By the way great Job i’ve never seen before such good scripts.

    • Mitch

      Hello mr.cavern! To answer your question – no, you do not have to execute the script on both machines. You only need to enable/allow root SSH access on the second machine and GeekPeek.Net bash script will configure both machines for DRBD.

      Thanks a lot for your support, it is very nice to hear that! You are welcome to put out a good work about GeekPeek.Net 🙂


  • danny magat

    Hi Mitch,
    how can i manually mount the node2 in case the node1 is having a problem, or run on a single node specially if the system hardware node1 is having a problem. basically my question is RUN the NODE without the other node.
    i dont know if my question is right.

    • Mitch

      Hi Danny and thanks for your question. You should disconnect node1 from your resource. The syntax is: drbdadm disconnect resource, ofcourse you need to do this on node1. Next is to put the node2 in primary mode. You can read more in my post on DRBD Management –

      Also, you could always just stop the drbd service on node1.


  • danny magat

    Thank you so much…

  • Muthu

    what if the resource is being held by some services.
    Can the fail-over be done manually by using disconnect/ discard-my-data?

    I assume we need to make sure that the resources were not held by any process.

    I used to get message as below mostly when i try to run the command as said>>

    /dev/drbd0: Failure: (125) Device has a net-config (use disconnect first)
    Command ‘drbdsetup /dev/drbd0 net C –set-defaults –create-device –max-buffers=2048 –ko-count=4 –discard-my-data’ terminated with exit code 10

  • Mitch

    Hi Muthu. First off i would like to know if you have a network connectivity between the nodes? Fail over can certainly be done manually. Read “DRBD Management and Basic Command Usage on CentOS 6” post, and next you definitely must make sure no services are holding the drbd partition as with normal partition.


  • kaak

    hi mitch its real helpful post.
    can you please tell me what should i change in the script to replicate a particular partition(ex. sda2) on centOS.
    or to be more precise i am trying to make an asterisk cluster, i have already configured network fail over on both nodes (heartbeat,vrrp)
    now i need to achieve disk replication..
    thanks in advance.

    • Mitch

      Hi Kaak! I think you should be able to do it with the existing script. You should enter “/dev/sda2” when the script asks you “Enter current machine disk intended for DRBD (example: /dev/sdb):” and of course again “/dev/sda2” when the script asks you “Enter second machine disk intended for DRBD (example: /dev/sdb):”. Have you already tried it? Rergards, Mitch

      • KAAK

        hi mitch thanks for the quick reply ,yes i have tried to change it to device”dev/sad2″ in the script for both nodes. Then i am able to create metadisk by “/sbin/drbdadm create-md disk1” command.
        But when i enter “/etc/init.d/drbd start” or “drbdadm attach disk1” it shows failure (104) cannot open backing device.
        for ur reference i have attached some show commands

        lvscan shows
        Active ‘/dev/VolGroup/Lv_root’ [18.05 Gib] inherit
        Active ‘/dev/VolGroup/Lv_swap’ [1.97 Gig] inherit

        pvscan shows
        PV /dev/sda2 VG VolGroup lvm2 [20.02 Gib /0 free]

        lsblk shows
        sda 20.5gig disk
        sda1 500M part/boot
        sda2 20gig part
        VolGroup-lv root 18G lvm/
        Volgroup-lv_swap 2G lvm [swap]

        any help will be greatly appreciated.
        Thank you.

  • Good informantion.
    Thank you so much.

    • Mitch

      Thanks Frank!

  • Tareq

    Hello, thank you for the tutorial, I did all these before and it worked perfectly, but when it comes to mounting, everything break.
    I just can’t find a good tutorial about mounting apache to drbd to make it replicated on the blocks, so is there a hope of doing that these days ??

    • Mitch

      Hi Tareq, i have successfully used apache from DRBD replicated partition so no problem there. Seems there must be some other problem – which mode are you running? Active/Passive? If so the drbd partition can only be mounted on the primary node not on both. If using Active/Active you need a filesystem that supports locking like GFS or similar. Regards, Mitch

      • Tareq

        Hi Mitch, thank you very much for your reply, well, I think it is Active/Active, but let’s say that I am having trouble in doing that configuration so if you can please tell me where I can find a good tutorial to configure apache with drbd from the scratch (not from the drbd conf, just at the mounting point and the FS point), all the tutorials I have found were too old.
        I am very desperate right now, every try I have made ended with errors, fails, and nothing works after that. Again, thank you for your helping. Regards, Tareq.

  • Pingback: DRBD + HearBeat + pacemaker()

  • Steph3000

    Thanks. Beside, DRBD Management and Basic Command Usage on CentOS 6 link is broken.

    • Steph3000

      Oops this wasn’t meant as a reply.

  • Pingback: How To Configure Drbd | Goods News()