Configure DRBD CentOS 6

Configure DRBD CentOS 6

Configure DRBD CentOS 6

DRDB or Distributed Replicated Block Device is nice for HA situations of distributed block devices. This can be used for NAS, SAN, and a number of other use cases.

** NOTE THIS SETUP IS FOR ACTIVE/PASSIVE, NOT ACTIVE/ACTIVE” **

if you want to have Active/Active you need to use a filesystem such as GlusterFS that is capable of multi-writes.

For this blog, case we have 2 servers

nas5, nas6, they each have an 8GB /root partition, and 50GB for the drdb block-level replication. nas5 will be the primary

login, and su to root

Root shell prompt on nas5 before configuring DRBD replication
Root shell prompt on the second DRBD node before package install

from here we need to install the epel repo on each server

Installing the ELRepo RPM on nas5 with rpm -Uvh for DRBD packages

install the drdb packages on each server

Running yum install -y kmod-drbd83 drbd83-utils on the DRBD node

once these packages has been installed, reboot each machine so the proper modules load into the live kernel

now create the drdb configuration file on nas5 (primary) /etc/drbd.d/home.res

Opening vi /etc/drbd.d/home.res to create the DRBD resource file on nas5

customize the config for your environment, once customized, copy to your 2nd NAS

home.res DRBD resource with protocol C, syncer rate 100M, nas5 and nas6 addresses

in this case /dev/xvdb is our DRDR disk (XenServer) and the address of the localhost is specified

setup your /etc/hosts on each server, just in case DNS resolution fails

Editing /etc/hosts on nas5 with nas5 and nas6 IP-to-name mappings
Editing /etc/hosts on nas6 so both DRBD nodes resolve without DNS

the next step is to make sure all your servers time are in sync with each other, we use a universal NTP server for all, so our configuration is ready to go.

on BOTH machines, we need to enable the disks to start replicating metadata

Running drbdadm create-md home on nas5 writing DRBD metadata successfully
Running drbdadm create-md home on nas6 writing DRBD metadata successfully

set the service to run on startup, as well as now (start both services at the same time, they are looking for each other)

Running chkconfig drbd on and service drbd start on nas5

configure a primary node:

Forcing initial sync with drbdadm -- --overwrite-data-of-peer primary home

now we need to wait a bit for the disks to syncronize…

cat /proc/drbd during the first sync showing sync progress on nas5

it takes a while… even for just a 50GB filesystem…..

here’s what it looks like when it’s all done:

cat /proc/drbd after sync completes with UpToDate/UpToDate status

now we need to create a filesystem on the block device

before we can do so, we need to make sure we are on the primary server, verify with the following commands:

Secondary:

cat /proc/drbd on the secondary node confirming Secondary/Primary roles

Primary:

drbdadm role home showing Primary/Secondary on CentOS 6

to set a new primary:

Running drbdadm primary home on nas5 to take the primary role

create filesystem:

Formatting the DRBD device with mkfs -t ext4 /dev/drbd1 on nas5

once completed, mount the filesystem on both systems…

Mounting /dev/drbd1 on /home with mount -t ext4 on the primary

verify it’s the right size….

df or ls verifying the mounted /home filesystem size on nas5

now the true test….. add a file to /home and see if it replicates to NAS6

Creating test50.txt under /home on nas5 to test block replication

verify replication is up to date

cat /proc/drbd verifying replication is UpToDate after the test file

A Few Admin Commands:

drbd-overview output showing Primary/Secondary UpToDate on both nodes
Additional drbd-overview listing for the home resource status

disconnecting disk:

Running drbdadm disconnect home before a planned failover test

connecting disk:

Connecting the DRBD resource again with drbdadm connect home

Failover to secondary node:

The first thing we need to do is umount the active drdb1 disk ont he primary

Unmounting /dev/drbd1 on nas5 before demoting the primary

now we need to demote the local disk as the primary

Demoting nas5 with drbdadm secondary home during failover

login to node 2 (nas6)

Root shell on nas6 ready to promote the former secondary

now we should be able to mount our drbd on node 2

Mounting /dev/drbd1 on /home on nas6 after promoting it primary

in this case we had a “test50.txt” file created to verify block-level replication was working

ls on nas6 /home showing replicated test50.txt after failover

That’s it! you are a DRBD Master!

Hosted Linux Servers at www.zwiegnet.com/go

Related guides: Configure keepalived for ip failover CentOS 6 | Setup NFS Server on CentOS 6

Leave a Reply

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