1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
3
"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
4
<!ENTITY % globalent SYSTEM "../../libs/global.ent">
6
<!ENTITY % gnome-menus-C SYSTEM "../../libs/gnome-menus-C.ent">
8
<!ENTITY % xinclude SYSTEM "../../libs/xinclude.mod">
10
<!ENTITY language "&EnglishAmerican;">
12
<chapter id="clustering" status="review">
13
<title>Clustering</title>
15
<sect1 id="drbd" status="review">
19
Distributed Replicated Block Device (DRBD) mirrors block devices between multiple hosts. The replication is
20
transparent to other applications on the host systems. Any block device hard disks, partitions, RAID devices,
21
logical volumes, etc can be mirrored.
25
To get started using <application>drbd</application>, first install the necessary packages. From a terminal enter:
29
<command>sudo apt-get install drbd8-utils</command>
33
This section covers setting up a <application>drbd</application> to replicate a separate <filename>/srv</filename>
34
partition, with an <application>ext3</application> filesystem between two hosts. The partition size is not
35
particularly relevant, but both partitions need to be the same size.
38
<sect2 id="drbd-configuration" status="review">
39
<title>Configuration</title>
42
The two hosts in this example will be called <emphasis>drbd01</emphasis> and <emphasis>drbd02</emphasis>.
43
They will need to have name resolution configured either through DNS or the <filename>/etc/hosts</filename>
44
file. See <xref linkend="dns"/> for details.
50
To configure <application>drbd</application>, on the first host edit <filename>/etc/drbd.conf</filename>:
54
global { usage-count no; }
55
common { syncer { rate 100M; } }
64
shared-secret "secret";
70
address 192.168.0.1:7788;
76
address 192.168.0.2:7788;
84
There are many other options in <filename>/etc/drbd.conf</filename>, but for this example their default
92
Now copy <filename>/etc/drbd.conf</filename> to the second host:
96
<command>scp /etc/drbd.conf drbd02:~</command>
103
And, on <emphasis>drbd02</emphasis> move the file to <filename>/etc</filename>:
107
<command>sudo mv drbd.conf /etc/</command>
114
Next, on both hosts, start the <application>drbd</application> daemon:
118
<command>sudo /etc/init.d/drbd start</command>
125
Now using the <application>drbdadm</application> utility initialize the meta data storage. On each server
130
<command>sudo drbdadm create-md r0</command>
137
On the <emphasis>drbd01</emphasis>, or whichever host you wish to be the primary, enter the following:
141
<command>sudo drbdadm -- --overwrite-data-of-peer primary all</command>
148
After executing the above command, the data will start syncing with the secondary host. To watch the progresss, on
149
<emphasis>drbd02</emphasis> enter the following:
153
<command>watch -n1 cat /proc/drbd</command>
157
To stop watching the output press <emphasis>Ctrl+c</emphasis>.
164
Finally, add a filesystem to <filename>/dev/drbd0</filename> and mount it:
168
<command>sudo mkfs.ext3 /dev/drbd0</command>
169
<command>sudo mount /dev/drbd0 /srv</command>
176
<sect2 id="drbd-testing" status="review">
177
<title>Testing</title>
180
To test that the data is actually syncing between the hosts copy some files on the <emphasis>drbd01</emphasis>, the
181
primary, to <filename>/srv</filename>:
185
<command>sudo cp -r /etc/default /srv</command>
189
Next, unmount <filename>/srv</filename>:
193
<command>sudo umount /srv</command>
197
<emphasis>Demote</emphasis> the <emphasis>primary</emphasis> server to the <emphasis>secondary</emphasis> role:
201
<command>sudo drbdadm secondary r0</command>
205
Now on the the <emphasis>secondary</emphasis> server <emphasis>promote</emphasis> it to the <emphasis>primary</emphasis> role:
209
<command>sudo drbdadm primary r0</command>
213
Lastly, mount the partition:
217
<command>sudo mount /dev/drbd0 /srv</command>
221
Using <emphasis>ls</emphasis> you should see <filename>/srv/default</filename> copied from the former <emphasis>primary</emphasis>
222
host <emphasis>drbd01</emphasis>.
226
<sect2 id="drbd-references" status="review">
227
<title>References</title>
232
For more information on <application>DRBD</application> see the <ulink url="http://www.drbd.org/">DRBD web site</ulink>.
237
The <ulink url="http://manpages.ubuntu.com/manpages/jaunty/en/man5/drbd.conf.5.html">drbd.conf man page</ulink> contains
238
details on the options not covered in this guide.
243
Also, see the <ulink url="http://manpages.ubuntu.com/manpages/jaunty/en/man8/drbdadm.8.html">drbdadm man page</ulink>.