Disk Mirroring with DRBD2010/05/05 |
Install DRBD(Distributed Replicated Block Device) and set Disk mirroring. This example based on my environment below. I used hda6 that is empty partition for this config. (1) www.server-linux.info[192.168.0.18] (2) www2.server-linux.info[192.168.0.21] |
|
[1] | Install and configure DRBD on both Host. Configure the same settings on them. For installing, Specify "kmod-drbd", the DRBD is also installed. Following example I did is specified "kmod-drbd-xen" because I did it on Xen-kernel environment. |
[root@www ~]# yum -y install kmod-drbd-xen [root@www ~]# vi /etc/drbd.conf
resource r0 { # Specify A or B or C protocol C; syncer { # band width rate 300M; } disk { on-io-error detach; } on www.server-linux.info { # DRBD device device /dev/drbd0; # phisical device disk /dev/hda6; # IP address:port address 192.168.0.18:7788; meta-disk internal; } on www2.server-linux.info { device /dev/drbd0; disk /dev/hda6; address 192.168.0.21:7788; meta-disk internal; } } [root@www ~]# modprobe drbd # load module [root@www ~]# lsmod | grep drbd drbd 185096 0 # just loaded [root@www ~]# dd if=/dev/zero of=/dev/hda6 bs=1M count=128 128+0 records in 128+0 records out 134217728 bytes (134 MB) copied, 2.39478 seconds, 56.0 MB/s [root@www ~]# drbdadm create-md r0 # create meta-data v08 Magic number not found v07 Magic number not found v07 Magic number not found v08 Magic number not found Writing meta data... initialising activity log NOT initialized bitmap New drbd meta data block sucessfully created. --== Creating metadata ==-- As with nodes we count the total number of devices mirrored by DRBD at at http://usage.drbd.org. The counter works completely anonymous. A random number gets created for this device, and that randomer number and the devices size will be sent. http://usage.drbd.org/cgi-bin/insert_usage.pl?nu=5112098206248082396&ru=12990301505065341479&rs=1073741824 Enter 'no' to opt out, or just press [return] to continue: success [root@www ~]# /etc/rc.d/init.d/drbd start [root@www ~]# cat /proc/drbd # show status version: 8.0.11 (api:86/proto:86) GIT-hash: b3fe2bdfd3b9f7c2f923186883eb9e2a0d3a5b1b build by buildsvn@c5-i386-build, 2008-03-09 10:26:43 0: cs:Connected st: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 resync: used:0/31 hits:0 misses:0 starving:0 dirty:0 changed:0 act_log: used:0/127 hits:0 misses:0 starving:0 dirty:0 changed:0
|
[2] | Make a Host you set primary first. Then mirroring is started. |
[root@www ~]# drbdsetup /dev/drbd0 primary -o # make it primary drbd0: Forced to consider local data as UpToDate! [root@www ~]# cat /proc/drbd version: 8.0.11 (api:86/proto:86) GIT-hash: b3fe2bdfd3b9f7c2f923186883eb9e2a0d3a5b1b build by buildsvn@c5-i386-build, 2008-03-09 10:26:43 0: cs:SyncSource st:Primary/Secondary ds:UpToDate/Inconsistent C r--- # changed ns:77968 nr:0 dw:0 dr:85524 al:0 bm:4 lo:111 pe:259 ua:1999 ap:0 [>...................] sync'ed: 7.5% (971572/1048508)K finish: 0:00:37 speed: 25,644 (25,644) K/sec resync: used:2/31 hits:40719 misses:6 starving:0 dirty:0 changed:6 act_log: used:0/127 hits:0 misses:0 starving:0 dirty:0 changed:0 [root@www ~]# mkfs -t ext3 /dev/drbd0 [root@www ~]# mkdir /mnt/drbd [root@www ~]# mount /dev/drbd0 /mnt/drbd [root@www ~]# touch /mnt/drbd/test.txt # make test file [root@www ~]# ll /mnt/drbd total 16 drwx------ 2 root root 16384 May 11 02:18 lost+found -rw-r--r-- 1 root root 0 May 11 02:22 test.txt |
[3] | If you'd like to mount DRBD device on secondary Host, unmount DRBD device on primary Host first and make primary Host secondary first. Next make secondary Host primary and mount DRBD device. |
########### on primary host ########### [root@www ~]# umount /mnt/drbd [root@www ~]# drbdadm secondary r0 # make it secondary ########### on secondary host ########### [root@www2 ~]# drbdadm primary r0 # make it primary [root@www2 ~]# mkdir /mnt/drbd [root@www2 ~]# mount /dev/drbd0 /mnt/drbd [root@www2 ~]# ll /mnt/drbd total 16 drwx------ 2 root root 16384 May 11 02:18 lost+found -rw-r--r-- 1 root root 0 May 11 02:22 test.txt # just exist
|