Replicating block device with DRBD on Centos 6

Replicating block device with DRBD on Centos 6

drbd-logo

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.

 

Distributed Replicated Block Device is actually a network based RAID 1.

drbd-300x80

 

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.

REQUIREMENTS:

  • 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

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

1. BOTH MACHINES: Install ELRepo repository on your system.

rpm -Uvh http://elrepo.org/elrepo-release-6-4.el6.elrepo.noarch.rpm

2. Update both repo

yum update -y;

3. Install DRBD

[root@host1 ~]# yum -y install drbd83-utils kmod-drbd83
[root@host2 ~]# yum -y install drbd83-utils kmod-drbd83

4.  BOTH MACHINES: Insert drbd module manually or just reboot both machines.

/sbin/modprobe drbd

5. Partition DRBD

[root@host1 ~]# fdisk -cu /dev/sdb
[root@host2 ~]# fdisk -cu /dev/sdb

 

Screen-Shot-2556-08-21-at-11.54.46-AM

 

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

[root@host1 ~]# vi /etc/drbd.d/clusterdb_res.res
resource clusterdb_res {
protocol C;
handlers {
pri-on-incon-degr “/usr/lib/drbd/notify-pri-on-incon-degr.sh;/usr/lib/drbd/notifyemergency-reboot.sh;echo b > /proc/sysrq-trigger; reboot -f”;
pri-lost-after-sb “/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notifyemergency-reboot.sh; echo b > /proc/sysrq-trigger ;reboot -f”;
local-io-error “/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergencyshutdown.sh; echo o > /proc/sysrq-trigger ; halt -f”;fence-peer “/usr/lib/drbd/crm-fence-peer.sh”;
}

startup {
degr-wfc-timeout 120; # 2 minutes.
outdated-wfc-timeout 2; # 2 seconds.
}

disk {
on-io-error detach;
}

net {
cram-hmac-alg “sha1″;
shared-secret “clusterdb”;
after-sb-0pri disconnect;
after-sb-1pri disconnect;
after-sb-2pri disconnect;
rr-conflict disconnect;
}

syncer {
rate 10M;
al-extents 257;
on-no-data-accessible io-error;
}

on host1 {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.0.221:7788;
flexible-meta-disk internal;
}

on host2 {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.0.222:7788;
meta-disk internal;
}
}

7. BOTH MACHINES: 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

192.168.0.221 host1 host1.mzpeter.co.uk
192.168.0.222 host2 host2.mzpeter.co.uk

8. BOTH MACHINES: 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:

/etc/crontab

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

9. Copy DRBD configured to host2

[root@host1 ~]# scp /etc/drbd.d/clusterdb_res.res host2:/etc/drbd.d/clusterdb_res.res

10. BOTH MACHINES: Initialize the DRBD meta data storage:

[root@host1 ~]# drbdadm create-md clusterdb_res
[root@host2 ~]# drbdadm create-md clusterdb_res

11. BOTH MACHINES: Start the Distributed Replicated Block Device service on both nodes:

[root@host1 ~]# service drbd start
[root@host2 ~]# service drbd start

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

[root@host1 ~]# drbdadm primary –force data
[root@host1 ~]# drbdadm — –overwrite-data-of-peer primary all

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

[root@host1 ~] 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@host1 ~]# 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

14. Create desired filesystem on Distributed Replicated Block Device device:

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

15. You can now mount DRBD device on your primary node!

[root@host1 ~]# mkdir -p /home/peter
[root@host1 ~]# mount /dev/drbd0 /home/peter/

TIPS:

1. Switch Primary/Secondary

 [root@host1 ~]# drbdadm secondary clusterdb_res
 [root@host2 ~]# drbdadm — –overwrite-data-of-peer primary all

2.Firewall Open Port 7788

 

Thanks to Geekpeek.NET provide the automated install bash script for Centos 6 x86

Download here: Here