Home » Centos/RHEL » Install and configure DRBD on Centos, RHEL

Install and configure DRBD on Centos, RHEL

DRBD (Distributed Replicated Block Device) is a Linux-based free open source software component
DRBD facilitates the replacement of shared storage systems by networked mirroring.
DRBD makes it possible to maintain consistency of data among multiple systems in a network.
Drbd is a block device which is planned to construct high availability clusters. This is finished by mirroring a whole block device via network. DRBD also ensures high availability (HA) for Linux applications.
DRBD was initially conceived and build in the late 1990s by Philipp Reisner and Lars Ellenberg.
The developers’ intention was to produce a Linux security standard that would suggest optimal reliability at minimum cost.
The DRBD software has always evolved since that time. The existing version of DRBD can be used with all general flavors of Linux for synchronous duplication or replication of stored data between a passive method and an active method.Data information be able to read from and written to both systems simultaneously. DRBD also supports resource-level fence.
DRBD workings in combination with a cluster management program known as Heartbeat and has been bundled into some flavors of Linux.Drbd is a block device which is planned to construct high availability clusters. This is finished by mirroring a whole block device via network.
In this tutorials we are going to discuss how to Install and configure DRBD on Centos, RHEL server.
How to install and configure HA linux Cluster with corosync and packemaker
Instal and configure LDAP server

Install and configure ELRepo repository on your both servers:

#rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm
After that install drbd-utils and kmod
#yum -y install drbd83-utils kmod-drbd83
insert drbd module on both server using following command.
#/sbin/modprobe drbd
#init 6

Create the Distributed Replicated Block Device resource file

#vi /etc/drbd.d/r0.res
resource r0 {

protocol C;
#syncer {
# rate 50M;
# }
on drbd1.linuxpcfix.com {
device /dev/drbd0;
disk /dev/sda3;
address 10.1.2.41:7788;
flexible-meta-disk internal;
}
on drbd2.linuxpcfix.com {
device /dev/drbd0;
disk /dev/sda3;
address 10.1.2.42:7788;
meta-disk internal;
}
}

Append the following lines in your hosts file to resolve the dns issue on both server.

10.1.2.42 drbd2.linuxpcfix.com
10.1.2.41 drbd1.linuxpcfix.com
10.1.2.41 drbd1
10.1.2.42 drbd2

copy the r0.res and hosts files on node2 also.
Initialize the DRBD meta data storage on both servers.

[root@node1 ~]# drbdadm create-md r0.res
[root@node2 ~]# drbdadm create-md r0.res
You want me to create a v08 style flexible-size internal meta data block.
There appears to be a v08 flexible-size internal meta data block
already in place on /dev/sdb1 at byte offset 2146430976
Do you really want to overwrite the existing v08 meta-data?
[need to type ‘yes’ to confirm] yes
Writing meta data…
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.

Start the drdb on both nodes:

[root@node1 ~]# service drbd start
[root@node2 ~]# service drbd start

On the PRIMARY node run drbdadm command:

[root@node1 ~]# drbdadm — –overwrite-data-of-peer primary r0

Check if Device disk initial synchronization to complete (100%) and check to confirm you are on primary node:

[root@node1 yum.repos.d]# cat /proc/drbd
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2014-11-24 14:51:37
0: cs:SyncTarget ro:Primary/Secondary ds:Inconsistent/UpToDate C r—–
ns:22727704 nr:64730004 dw:87457556 dr:349165 al:6189 bm:4146 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:40192664
[===========>……..] sync’ed: 63.1% (39248/106072)M
finish: 37:52:47 speed: 284 (288) want: 250 K/sec

Create filesystem on Distributed Replicated Block Device device:

[root@node1 yum.repos.d]# mkfs.ext4 /dev/drbd0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524007 blocks
26200 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

You can now mount DRBD device on your primary node:

[root@node1 ~]# mkdir /data-drbd
[root@node1 ~]# mount /dev/drbd0 /data-drbd

Check:

[root@node1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 87G 8.0G 75G 10% /
tmpfs 3.9G 1.9G 2.1G 48% /dev/shm
/dev/drbd0 102G 5.5G 92G 6% /data-drbd

Please note: You do not need to mount the disk from secondary server. All data you write on /data-drbd folder will be synced to node2.
if you want to make secondary as primary server then Unmount the /data-drbd folder from the primary node, make the secondary node as primary node, and mount back the /data-drbd on the second machine, then you will see the same contents in /data folder

Switch Primary/Secondary

[root@node1 ~]# drbdadm secondary clusterdb
[root@node2 ~]# drbdadm — –overwrite-data-of-peer primary all

Enjoy!

About

I am founder and webmaster of www.linuxpcfix.com and working as a Sr. Linux Administrator (Expertise on Linux/Unix & Cloud Server) and have been in the industry since more than 14 years.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

Time limit is exhausted. Please reload the CAPTCHA.

Categorized Tag Cloud