Setting Up Network RAID1 With DRBD On Debian Squeeze - Page 2

4 Install And Configure DRBD

server1/server2:

Now install DRBD on both nodes as follows:

apt-get install drbd8-utils

Load the DRBD kernel module:

modprobe drbd

To check if it is loaded, run:

lsmod | grep drbd

Output should be similar to this one:

[email protected]:~# lsmod | grep drbd
drbd                  193312  0
lru_cache               5042  1 drbd
cn                      4563  1 drbd
[email protected]:~#

Now we back up the original /etc/drbd.conf file and create a new one on both nodes as follows:

cp /etc/drbd.conf /etc/drbd.conf_orig
cat /dev/null > /etc/drbd.conf
vi /etc/drbd.conf

global { usage-count no; }
common { syncer { rate 100M; } }
resource r0 {
        protocol C;
        startup {
                wfc-timeout  15;
                degr-wfc-timeout 60;
        }
        net {
                cram-hmac-alg sha1;
                shared-secret "secret";
        }
        on server1.example.com {
                device /dev/drbd0;
                disk /dev/sdb1;
                address 192.168.0.100:7788;
                meta-disk internal;
        }
        on server2.example.com {
                device /dev/drbd0;
                disk /dev/sdb1;
                address 192.168.0.101:7788;
                meta-disk internal;
        }
}

Make sure you use the correct node names in the file (instead of server1.example.com and server2.example.com) - please make sure you use the node names that the command

uname -n

shows on both nodes. Also make sure you fill in the correct IP addresses in the address lines and the correct disk in the disk lines (if you don't use /dev/sdb1).

Now we initialize the meta data storage. On both nodes run:

drbdadm create-md r0

[email protected]:~# drbdadm create-md r0
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
[email protected]:~#

Then start DRBD on both nodes:

/etc/init.d/drbd start

[email protected]:~# /etc/init.d/drbd start
Starting DRBD resources:[ d(r0) s(r0) n(r0) ]....
[email protected]:~#

The next step has to be carried out on server1 only:

server1:

Now make server1 the primary node:

drbdadm -- --overwrite-data-of-peer primary all

Afterwards, data will start to synchronize between server1 and server2.

server2:

Take a look at

cat /proc/drbd

to see the synchronization progress:

[email protected]:~# cat /proc/drbd
version: 8.3.7 (api:88/proto:86-91)
srcversion: EE47D8BF18AC166BE219757
 0: cs:SyncTarget ro:Secondary/Primary ds:Inconsistent/UpToDate C r----
    ns:0 nr:15790400 dw:15790144 dr:0 al:0 bm:963 lo:9 pe:29622 ua:8 ap:0 ep:1 wo:b oos:15664096
        [=========>..........] sync'ed: 50.3% (15296/30716)M
        finish: 0:02:44 speed: 95,212 (85,352) K/sec
[email protected]:~#

(You can run

watch cat /proc/drbd

to get an ongoing output of the process. To leave watch, press CTRL+C.)

Wait until the synchronization has finished - output should be as follows:

[email protected]:~# cat /proc/drbd
version: 8.3.7 (api:88/proto:86-91)
srcversion: EE47D8BF18AC166BE219757
 0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r----
    ns:0 nr:31454240 dw:31454240 dr:0 al:0 bm:1920 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
[email protected]:~#

The snippet ro:Secondary/Primary tells you that this node is the secondary node.

server1:

On server1, the output of

cat /proc/drbd

is as follows (after the synchronization has finished):

[email protected]:~# cat /proc/drbd
version: 8.3.7 (api:88/proto:86-91)
srcversion: EE47D8BF18AC166BE219757
 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----
    ns:31454240 nr:0 dw:0 dr:31454440 al:0 bm:1920 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
[email protected]:~#

The snippet Primary/Secondary tells you that this is the primary node.

Now that we have our new network RAID1 block device /dev/drbd0 (which consists of /dev/sdb1 from server1 and server2), let's create an ext3 filesystem on it and mount it to the /data directory. This has to be done only on server1!

mkfs.ext3 /dev/drbd0
mkdir /data
mount /dev/drbd0 /data

Afterwards you should see /dev/drbd0 in the outputs of...

mount

[email protected]:~# mount
/dev/sda1 on / type ext3 (rw,errors=remount-ro)
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
udev on /dev type tmpfs (rw,mode=0755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)
/dev/drbd0 on /data type ext3 (rw)
[email protected]:~#

... and:

df -h

[email protected]:~# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              29G  775M   27G   3% /
tmpfs                 249M     0  249M   0% /lib/init/rw
udev                  244M  112K  244M   1% /dev
tmpfs                 249M     0  249M   0% /dev/shm
/dev/drbd0             30G  173M   28G   1% /data
[email protected]:~#

 

5 Test

server1:

Now let's create some files or directories in the /data directory and check whether they get replicated to server2.

touch /data/test1.txt
touch /data/test2.txt

ls -l /data/

[email protected]:~# ls -l /data/
total 16
drwx------ 2 root root 16384 Aug  8 12:45 lost+found
-rw-r--r-- 1 root root     0 Aug  8 12:48 test1.txt
-rw-r--r-- 1 root root     0 Aug  8 12:48 test2.txt
[email protected]:~#

Now let's unmount the /data directory on server1:

umount /data

Then assign the secondary role to server1:

drbdadm secondary r0

Now we go to server2, make it the primary node and check if we can see the files/directories we created on server1 in the /data directory on server2.

server2:

First we assign the primary role to server2:

drbdadm primary r0

Check the output of

cat /proc/drbd

... and you should see that server2 is the primary node now:

[email protected]:~# cat /proc/drbd
version: 8.3.7 (api:88/proto:86-91)
srcversion: EE47D8BF18AC166BE219757
 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----
    ns:4 nr:32083300 dw:32083304 dr:325 al:1 bm:1920 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
[email protected]:~#

Next we create the /data directory and mount /dev/drbd0 to it:

mkdir /data
mount /dev/drbd0 /data

Let's check the contents of the /data directory:

ls -l /data/

If everything went fine, it should contain the files/directories that we created on server1:

[email protected]:~# ls -l /data/
total 16
drwx------ 2 root root 16384 Aug  8 12:45 lost+found
-rw-r--r-- 1 root root     0 Aug  8 12:48 test1.txt
-rw-r--r-- 1 root root     0 Aug  8 12:48 test2.txt
[email protected]:~#

server1:

Now that we have switched roles, the output of

cat /proc/drbd

on server1 should show you that server1 has the secondary role:

[email protected]:~# cat /proc/drbd
version: 8.3.7 (api:88/proto:86-91)
srcversion: EE47D8BF18AC166BE219757
 0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r----
    ns:32083300 nr:4 dw:629064 dr:31454797 al:529 bm:2044 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
[email protected]:~#

 

Share this page:

2 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: Brian_H

Might be worthy to mention that this process can be automated with Heartbeat or Corosync and Pacemaker.  Additionally DRBD can be used on a non-partitioned block device, so you could use just /dev/sdb without partitioning it.  In some cases (not all) I've seen a partitioned device introduce a  performance penalty. 

 

Other than that, this article is point on.  Very easy to follow, good job!  :)

By:

I'd not run it from /dev/sdb ..

You'll get in trouble when you run out of space on the disc .. there will be no more room for your meta data and you'll end up with a corrupted disc, been there done that! ;)

Best practice is to always create a partition to sync, with internal metadata.