It is a Distributed Replicated Block
Device which is software based, shares nothing, replicated storage solution,
mirroring the content of the block devices between the hosts.
For example: Hard Disks, Partitions
and Logical Volumes.
Why DRBD is Important?
- Real Time: Replication occurs continuously while application modifies the data on the service.
- Transparent: Applications need not to be aware that data is stored in multiple hosts.
- Synchronous/Asynchronous: In synchronous mirroring, a writing application is notified of write completion only after the write has been carried out on both computers. In asynchronous mirroring, the writing application is modified of write completion when the write has completed locally.
Pros and Cons of DRBD:
Pros:
DRBD constitutes a driver for virtual block device. It is situated bottom of
I/O stack. Because of this, DRBD is flexible and versatile which makes suitable
for adding high availability to any applications.
Cons:
DRBD cannot auto-detect file system corruption or cannot add active-active
clustering capability to file systems like ext3 or XFS.
User Administration
Tools:
These are the tools which communicates
with kernel module in order to configure and administrator DRBD resources.
There are 3 tools, namely
- drbdadm: It is a high level administration tool where all the configuration is setup in vi /etc/drbd.conf file. It also acts as front end for drbdsetup and drbdmeta.
The high-level administration tool
of the DRBD program suite. Obtains all DRBD configuration parameters from the
configuration file /etc/drbd.conf and acts as a
front-end for drbdsetup and drbdmeta. drbdadm has a dry-run mode, invoked with
the
-d option, that shows
which drbdsetup and drbdmeta calls drbdadm would issue
without actually calling those commands
- Drbdsetup: It is a low level tool in drbd. The program that allows users to configure DRBD module that has been loaded into running kernel.
drbdsetup. Configures the DRBD module
loaded into the kernel. All parameters to drbdsetup must be passed on
the command line. The separation between drbdadm and drbdsetup allows
for maximum flexibility. Most users will rarely need to
use drbdsetup directly, if at all.
- Drbdmeta: It allows users to create, dump, modify and restore metadata structures.
Allows to create, dump,
restore, and modify DRBD meta data structures. Like drbdsetup, most users
will only rarely need to use drbdmeta directly.
Replication modes
DRBD
supports three distinct replication modes, allowing three degrees of
replication synchronicity.
Protocol
A: Asynchronous
replication protocol: Local write operations on the primary node are considered
completed as soon as the local disk write has finished, and the replication
packet has been placed in the local TCP send buffer. In the event of forced
fail-over, data loss may occur. The data on the standby node is consistent
after fail-over; however, the most recent updates performed prior to the crash
could be lost. Protocol A is most often used in long distance replication
scenarios. When used in combination with DRBD Proxy it makes an effective
disaster recovery solution.
Protocol
B: Memory
synchronous (semi-synchronous) replication protocol:
Local write operations on the primary node are considered completed as soon as
the local disk write has occurred, and the replication packet has reached the
peer node. Normally, no writes are lost in case of forced fail-over. However,
in the event of simultaneous power failure on both nodes and concurrent,
irreversible destruction of the primary’s data store, the most recent writes
completed on the primary may be lost.
Protocol
C: Synchronous
replication protocol: Local write operations on the primary node are
considered completed only after both the local and the remote disk write have
been confirmed. As a result, loss of a single node is guaranteed not to lead to
any data loss. Data loss is, of course, inevitable even with this replication
protocol if both nodes (and their storage subsystems) are irreversibly
destroyed at the same time.
Preparing the servers
My local server setup on Centos 6:
Server1
= db1.example.com (192.168.1.70)
Server2
= db2.example.com (192.168.1.71)
Virtual
IP for cluster = 192.168.1.100
After we have the OS installed we will
disable SELINUX and IPTABLES and get CentOS /Redhat up to date by YUM UPDATE.
We can activate IPTABLES and SELINUX back again but for now we disabled it to
make things easier to troubleshoot in case we need.
#yum
update -y
#iptables
–F
#chkconfig
iptables off
#lokkit
–selinux=disabled
OR
#vim
/etc/sysconfig/selinux (change here)
Assuming that the network and hostname
has been setup during the OS installation. If you haven’t done that yet it is
probably a good time.
Server1:
#
vim /etc/sysconfig/network-scripts/ifcfg-eth0
#
ifconfig
Server2:
#vim
/etc/sysconfig/network-scripts/ifcfg-eth0
#ifconfig
We need to make sure that NTPD is
always running to keep both servers time synchronized.
#
date
#
ntpdate ntpserver/IP
On db1.example.com:
On db2.example.com:
Don’t forget to do the host entry in /etc/hosts file in both the systems:
#
vim /etc/hosts
Copy /etc/hosts file on db2.
#
scp /etc/hosts 192.168.1.71:/etc
On
Both servers:
We need to install gcc, make and other
dependencies in case we need to compile any code which is not available in rpm
packages.
# yum install gcc glibc
make flex OpenIPMI net-snmp python
Okay now to take affect some of the
configurations that we have done we will reboot the servers. This is only
necessary because we disabled SELINUX and updated the KERNEL; all the other
services could have been restarted without a server reboot.
# reboot
Installation of DRBD Package:
Note: As you probably know RHEL 6 / CentOS
6 does not have DRBD on any of the yum repository. You need a support
contract with RHEL to get DRBD (they partnered with LINBIT after it was decided
to not to support DRBD in EL6 because DRBD didn't get into the mainline kernel
until 2.6.33, and EL6 has 2.6.32. However you can alternatively install it from
source or rpm packages or use the yum ELRepo repository (http://elrepo.org).
You can download the source file from
below given command
# wget
http://oss.linbit.com/drbd/drbd-latest.tar.gz
ELRepo:
Install ELrepo package and configure
it for DRBD installation.
#
vi /etc/yum.repos.d/elrepo.repo
enabled=0
#
yum --enablerepo=elrepo install drbd83-utils kmod-drbd83
Note: For installing the packages
from elrepo, system should be register with RHN for dependencies.
Let’s now set up our DRBD
device. We will create a 20GB LVM to be used by DRBD.
Create the Logical Volume on both
servers: (In my case I am using KVM so disk is /dev/vda)
[root@db1~]#
pvcreate /dev/vda5
[root@db2~]#
pvcreate /dev/vda5
[root@db1~]#
vgcreate vg01 /dev/vda5
[root@db2~]#
vgcreate vg01 /dev/vda5
[root@db1~]#
lvcreate --name lv01 –-size 10G vg01
[root@db2~]#
lvcreate --name lv01 --size 10G vg01
Note: *** VERY
IMPORTANT – DON’T FORMAT AND MOUNT THE VOLUME ***
Now save the original global
configuration file on both servers:
#
mv /etc/drbd.d/global_common.conf /etc/drbd.d/global_common.sample
And create a new file:
#
vim /etc/drbd.d/global_common.conf
global { usage-count no; }
common {
syncer { rate 10M; }
}
Create a new resource file that I
called “main”, on both servers that have to be equal:
#
vim /etc/drbd.d/main.res
resource main {
protocol C;
startup { wfc-timeout 0;
degr-wfc-timeout 120; }
disk { on-io-error detach; }
on db1.example.com {
device /dev/drbd0;
disk /dev/vg01/lv01;
meta-disk internal;
address 192.168.1.70:7788;
}
on db2.example.com {
device /dev/drbd0;
disk /dev/vg01/lv01;
meta-disk internal;
address 192.168.1.71:7788;
}
}
Now we have to create the metadata on
both servers:
[root@db1~]#
drbdadm create-md main
[root@db2~]#
drbdadm create-md main
And we can now start DRBD on both servers
at the same time:
[root@db1
drbd.d]# /etc/init.d/drbd start
[root@bd2
drbd.d]# /etc/init.d/drbd start
You have two ways to verify that DRBD
is running properly:
#
service drbd status
OR
#
cat /proc/drbd
Version:
8.3.11 (api:88/proto:86-96)
GIT-hash:
0de839cee13a4160eed6037c4bddd066645e23c5 build by dag@Build64R6, 2011-08-08
08:54:05
0:
cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r-----
ns:0
nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:41941724
As you can see they say that it is
connected but “ro:Secondary/Secondary” meaning that we haven’t told the system
which one is the Primary server (master) that contains the block to be
replicated. Once we tell the system who is the master it will start the
synchronization.
We will tell DRBD that server db1.example.com
is the Primary server, Run the below command on the Server which you want to
make primary:
#
drbdsetup /dev/drbd0 primary –o
OR
#
drbdadm -- --overwrite-data-of-peer primary main
Note: ‘main’ is your
resource name
#
cat /proc/drbd
Version:
8.3.11 (api:88/proto:86-96)
GIT-hash:
0de839cee13a4160eed6037c4bddd066645e23c5 build by dag@Build64R6, 2011-08-08
08:54:05
0:
cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----
ns:503808
nr:0 dw:0 dr:504472 al:0 bm:30 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:41437916
[>....................]
sync'ed: 1.3% (40464/40956)M
Finish:
1:06:40 speed: 10,340 (10,280) K/sec
This output has so much information
about the connections and specifications:
- CS: Describes about the status of the connection state.
- ro: Describes about the roles of nodes. It displays the local 1st node followed 2nd.
- Ds: It is a disk states which shows the state of the disk.
- Ns: Volume of net data sent to the partner via network connection
- nr: Volume of net data received by the partner via network connection
- dw: Net data written on hard disk ( disk write )
- dr: Net data read from local hard disk ( disk read)
- al: Activity log. Number of updates of meta data
- lo: Number of open requests to the local I/O subsystem by drbd.
- Pe: Number of requests send to partner but not answered.
- Ua: Unacknowledged: number of requests recieved by partner but not answered
- ap: Application pending: Number of I/O req forwarded to drbd, but not answered.
The synchronization started and it
will take a little while to be completed. Please wait until it is done or for
below output and move to the next step.
#
cat /proc/drbd
0: cs:Connected ro:Primary/Secondary
ds:UpToDate/UpToDate C r-----
ns:41941724 nr:0 dw:0 dr:41942388 al:0
bm:2560 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
Now that our servers are in sync we
can format our /dev/drbd0 with our preferred file system. In my case I
will use ext4. Run the below command on db1.example.com
#
mkfs.ext4 /dev/drbd0
Configuring
NFS exports for Heartbeat integration:
Install NFS on server1 and server2. Or
check.
Let’s prepare our NFS first:
On both servers:
#
mkdir /drbd
#
vi /etc/exports
/drbd/main
*(rw)
On server1 only :
#
mount /dev/drbd0 /drbd
#
mkdir /drbd/main
NFS stores some information about
your NFS mounts at /var/lib/nfs and
since that information will have to be mirrored we will have to move them to
the DRBD device:
# mv /var/lib/nfs/ /drbd/
This might
give some errors such as:
but do not worry about it because
it will create the directories anyways.
#
mv /var/lib/nfs /var/lib/nfsBackup
Then symlink /var/lib/nfs to our
/drbd directory:
#
ln -s /drbd/nfs/ /var/lib/nfs
# umount /drbd
On server2 only:
# mv
/var/lib/nfs/ /var/lib/nfsBackup
# ln -s
/drbd/nfs/ /var/lib/nfs
The
symbolic link will be broken since the /dev/drbd0 is not mounted. This will
work in case of NFS fail-over
Heartbeat installation and configuration:
Last but not least configure the heartbeat
to control a Virtual IP address and failover NFS in the case of a node failure.
We will install
heartbeat from the EPEL repository:
# rpm -Uvh http://download.fedora.redhat.com/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm
# vi /etc/yum.repos.d/epel.repo
enabled=0
#
yum --enablerepo=epel install heartbeat*
Check on both servers:
#
rpm –qa heartbeat*
Create the following file on both
servers with the exact same content:
#
vi /etc/ha.d/ha.cf
keepalive 2
deadtime 30
bcast eth0
node db1.example.com db2.example.com
# same thing here for the node names
use the same hostname of your hosts… this needs to be whatever uname –n answers.
The next setp is to create the
resource file for heartbeat on both servers with exact same content again:
#
vi /etc/ha.d/haresources
db1.example.com IPaddr::192.168.1.100/24/eth0 drbddisk::main Filesystem::/dev/drbd0::/drbd::ext4
nfslock nfs
Note: This is just in 1 line.
# first word is the hostname of the primary
server then the IP 192.168.1.100 is the one I choose to be the virtual IP to be
moved to the slave in case of a failure.
The last thing is to create the
authentication file on both servers again with the same content:
#
vi /etc/ha.d/authkeys
auth 3
3 md5 redhat
This password file should only be
readable by the root user:
# chmod 600
/etc/ha.d/authkeys
Copy all file from db1 to db2 server.
#
cd /etc/ha.d/
#
scp ha.cf db2:/etc/ha.d/
#
scp authkeys db2:/etc/ha.d/
#
scp haresources db2:/etc/ha.d/
Testing the Cluster:
On both servers start heartbeat
service:
#
service heartbeat start
On server1;
[root@db1
~]# ifconfig
[root@db1
~]# df -h
Let’s test the DRBD/NFS fail over
now.
You can shut down server1… not a
problem or simply stop heartbeat service:
On
server1:
#
service heartbeat stop
On server2:
[root@db2 ~]#
ifconfig
[root@db2 ~]# df
–h
See
the Difference in case of failover.
Configure MySQL for heartbeat integration:
Before
make changes in servers, stop the heartbeat on both sites for safe.
Install mysql, mysql-server on both server
On db1.example.com:
#
yum install mysql mysql-server –y
On db2.example.com:
#
yum install mysql mysql-server –y
Now make directory /drbd/mysql on server1
#
mkdir /drbd/mysql
Change Owner ship of mysql directory
#
chown mysql:mysql /drbd/mysql
Do the changes in mysql configuration
file /etc/my.cnf on both servers.
Change data directory path
datadir=/var/lib/mysql
To
datadir=/drbd/mysql
Copy /etc/my.cnf file from db1 to db2
#
scp /etc/my.cnf db:/etc/
Heartbeat setup for MySQL:
Note: - Leave /etc/ha.d/ha.cf and /etc/ha.d/authkeys as it is, as we
configure earlier on both server.
Now make entry for heartbeat
configuration in /etc/ha.d/haresources
file on both servers.
#vim
/etc/ha.d/haresources
Copy file from db1 to db2 server
#
scp /etc/ha.d/haresources db:/etc/ha.d/
Testing of cluster:
Start heartbeat service on both the
servers.
#service
heartbeat start
#chkconfig
heartbeat on
On server 1
#/etc/init.d/mysqld
status
Check Failover:
Shutdown
server1 or stop heartbeat service on server1
#/etc/init.d/heatbeat stop
On server 2:
Check
mysql status should be running
#/etc/init.d/mysqld status
Reference document:
Hi, after reading this amazing paragraph i
ReplyDeleteam too delighted to share my know-how here with friends.
Hello, I think your site might be having browser compatibility issues.
ReplyDeleteWhen I look at your website in Opera, it looks fine
but when opening in Internet Explorer, it has some overlapping.
I just wanted to give you a quick heads up!
Other then that, wonderful blog!
I every time spent my half an hour to read this web site's content all the time along with a cup of coffee.
ReplyDeleteHello, just wanted to mention, I liked this blog post.
ReplyDeleteIt was practical. Keep on posting!
Just want to say your article is as surprising. The clearness in your post is just spectacular and i can assume you're an expert on this subject.
ReplyDeleteWell with your permission let me to grab your RSS feed to keep updated with forthcoming post.
Thanks a million and please continue the rewarding work.
I love what you guys tend to be up too. This type of clever work and coverage!
ReplyDeleteKeep up the great works guys I've incorporated you guys to my blogroll.
Hey I know this is off topic but I was wondering if you knew of any widgets I could add to
ReplyDeletemy blog that automatically tweet my newest twitter updates.
I've been looking for a plug-in like this for quite some time and was hoping maybe you
would have some experience with something like this. Please let me
know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.
Fantastic goods from you, man. I have understand your stuff
ReplyDeleteprevious to and you're just extremely excellent.
I actually like what you have acquired here, certainly like what
you are saying and the way in which you say it. You make it entertaining and you still take care of
to keep it wise. I can't wait to read far more from you.
This is actually a wonderful site.
If you would like to increase your know-how simply keep visiting this website and be updated with
ReplyDeletethe newest information posted here.
Woah! I'm really loving the template/theme of this site.
ReplyDeleteIt's simple, yet effective. A lot of times
it's hard to get that "perfect balance" between superb usability
and visual appeal. I must say you have done a amazing job with this.
Additionally, the blog loads super fast for me on Firefox.
Outstanding Blog!
Ahaa, its good dialogue about this article here at this website, I have read
ReplyDeleteall that, so now me also commenting here.
I really like it whenever people come together and share opinions.
ReplyDeleteGreat site, stick with it!
Hello to all, how is everything, I think every one is getting more
ReplyDeletefrom this site, and your views are good in favor of new visitors.
Great article, exactly what I was looking for.
ReplyDeleteUseful information. Fortunate me I found your web site unintentionally,
ReplyDeleteand I am shocked why this coincidence did not came about earlier!
I bookmarked it.
This paragraph will assist the internet users for
ReplyDeletebuilding up new weblog or even a blog from start to end.
I think this is among the most important info for
ReplyDeleteme. And i'm glad reading your article. But want to remark on some general things,
The web site style is wonderful, the articles is really excellent : D.
Good job, cheers
Write more, thats all I have to say. Literally,
ReplyDeleteit seems as though you relied on the video to make your point.
You clearly know what youre talking about, why
waste your intelligence on just posting videos to your site when you could
be giving us something enlightening to read?
Currently it seems like Wordpress is the preferred blogging platform out there right now.
ReplyDelete(from what I've read) Is that what you're using on your blog?
I used some strips of moleskin that I bought with the drugstore and applied them sparingly for
ReplyDeletethe problem area. Everybody needs some tips once and while, when your quality of life is a risk
then the stakes go higher. But, recall the key the following is moderation - while a drink a day is protective, excessive consumption of alcohol is
devastating to health.
site link
Normally I don't learn post on blogs, however I would like to say that this write-up
ReplyDeletevery pressured me to check out and do so! Your writing taste has been surprised me.
Thanks, quite nice post.
Hi, I do think this is a great web site. I stumbledupon it ;) I may
ReplyDeletecome back yet again since i have book marked it. Money and
freedom is the best way to change, may you be rich and continue to guide
others.
I ᴠisit daily a few websitеѕ and weƅsites too read articles orr reviews, Ьbut tһis blog gives feature based
ReplyDeletewrіting.
I'm not sure where you are getting your info, but good topic.
ReplyDeleteI needs to spend some time learning more or understanding more.
Thanks for wonderful info I was looking for this info for my mission.
Everything is very open with a very clear description of the issues.
ReplyDeleteIt was really informative. Your website is very helpful.
Thank you for sharing!
You should take part in a contest for one of the highest quality websites on the internet.
ReplyDeleteI will recommend this web site!
Howdy would you mind letting me know which web host you're utilizing?
ReplyDeleteI've loaded your blog in 3 different internet browsers and I
must say this blog loads a lot quicker then most.
Can you recommend a good web hosting provider at a fair price?
Many thanks, I appreciate it!
Hi there to all, the contents preesent at this wweb site
ReplyDeleteare truly awesome for people knowledge, well, keep up the good work fellows.
Magnificent goodds from you, man. I have understand your
ReplyDeletestuff previous to and you are just too great.
I actually like wha you've acquired here, certainly like what you're stating
and the way in which youu say it. You make it entertaining and youu stoll take care of to keep
it smart. I can not wait tto read far more from you.
Thiss iis actually a terrific website.
Very nice post. I just stumbled upon your blog and wanted to say that I've really enjoyed browsing your blog posts.
ReplyDeleteIn any case I will be subscribing to your feesd and I hope you write ahain soon!
Wonderful post! We are linking to this great article on our
ReplyDeletesite. Keep up the great writing.
Thank you, I've just been looking for information approximately this topic for a
ReplyDeletewhile and yours is the greatest I've came
upon till now. But, what in regards to the bottom line? Are you certain concerning the source?
A fascinating discussoon is worth comment. I do believe tha you ought to publidh more on this
ReplyDeletesubject matter, it may not be a taboo subject bbut usualoly
people don't discuss such topics. To the next!
Kind regards!!
Pretty! This has been an extremely wonderful post. Thank youu for supplying these details.
ReplyDeleteHello there, I do think your web site could possibly be having web browser compatibility problems.
ReplyDeleteWhen I look at youur website in Safari, it looks fine however,
if opening in I.E., it has sone overllapping issues. I simply wanted to provide you with
a quck heads up! Apart fro that, great blog!
I was ssuggested this web site via my cousin. I'm nott positive whetger or not this put up is
ReplyDeletewritten by way of him as nobody else recognize such
particular approximately my trouble. You're amazing!
Thanks!
Hey there, You've done a fantastic job. I'll certainly digg it and personally recommend to my
ReplyDeletefriends. I am sure they'll be benefited from this web site.
Hello there! I could have sworn I've been to your blog before but
ReplyDeleteafter browsing through a feww of the articles I realized it'snew to me.
Anyways, I'm definitely happy I found it and I'll be book-marking it and checking back frequently!
Currently it sounds like Wordpress is the top blogging platform out ther right now.
ReplyDelete(from what I've read) Is tht what you're using onn your blog?
I lioke the helpful info you provide on your articles.
ReplyDeleteI will bookmark your blog and chedk again here regularly.
I am fairly sure I'll learn a llot of nnew stuff right here!
Best of luck for the next!
Admiring thhe time and energy youu put into your blog and detailed information you offer.
ReplyDeleteIt's great to come across a blog every once in a while that isn't
the same outdated rehashed information. Great read! I've saved your site
and I'm adding your RSS feeds to my Google account.
I've been surfing online more than 3 hours today, yet I never found any interesting article like yours.
ReplyDeleteIt is pretty worth enough for me. Personally, if all webmasters and bloggers made good content as you did,
the net will be much more useful than ever before.
Hello there, just became aware of your blog through Google, and found that
ReplyDeleteit is truly informative. I am going to watch out for brussels.
I will appreciate if you continue this in future.
Lots of people will be benefited from your writing.
Cheers!
It's haqrd to come by experienced people in this particular topic,
ReplyDeletehowever, you sound like youu know what you're talkin about!
Thanks
Great beat ! I would like to apprentice at thhe same time as you amend your website,
ReplyDeletehow caan i subscribe for a blog site? The account aidxed me a appropriate deal.
I were tiny bit acquainted of this your broadcast provided bright clear concept
Wow, wonderful blog layout! How long have you been blogging for?
ReplyDeleteyou make blogfing look easy. The overall look of your site is wonderful,
let alone the content!
It's awesome in support of me to have a web page, which is good in favor of my knowledge.
ReplyDeletethanks admin
This is my first time visit at here and i am in fact pleassant to
ReplyDeleteread everthing at single place.