You are on page 1of 10

[DRBD ] --

, 2008/03/25 - 21:17 yejr


/Email:

http://imysql.cn/

1.
DRBD PhilippReisner and LarsEllenberg Linux

(heartbeat,HB) Linux (HA)DRBD


RAID-1

(,primary)(,secondary)

DRBD MySQL (replication)

(HA) DRBD

DRBD :
+------------+
| |
+------------+
|
V
+---------------+
|
|
| (/dev/drbd1) |
+---------------+
|
|
|
|

V
V
+-------------+ +--------------+
| | | |
| (/dev/hdb1) | | (/dev/hdb1) |
+-------------+ +--------------+

[DRBD ] --
, 2008/03/25 - 21:29 yejr
/Email:

http://imysql.cn/

2.
2.1.
2 IP
drbd

IP

10.168.115.2 s1.yejr.c
1(primary) 50
om

10.168.115.2 s2.yejr.c
2(secondar 51
om
y)

2.2.
rpm

[root@s1.yejr.com ~]# tar zxf drbd-8.2.5.tar.gz

[root@s1.yejr.com ~]# cd drbd-8.2.5


[root@s1.yejr.com drbd-8.2.5]# make
[root@s1.yejr.com drbd-8.2.5]# make all install

drbd
[root@s1.yejr.com drbd-8.2.5]# lsmod | grep drbd
drbd
274312 4
2 /dev/sdc1

[DRBD ] --
, 2008/03/25 - 21:31 yejr
/Email:

http://imysql.cn/

3.
2
[root@s1.yejr.com drbd-8.2.5]# vi /etc/drbd.conf
global {
}
#
common {
syncer { rate 100M; }
}
#db
resource db {
# C.,
protocol
C;

startup { wfc-timeout 0; degr-wfc-timeout


disk { on-io-error detach; }
syncer { rate 100M; }

120; }

#
on s1.yejr.com {
#/dev/drbd0 /dev/sdc1
device
/dev/drbd0;
disk
/dev/sdc1;
#
address
10.168.115.250:7791;
# internal()
#
meta-disk
internal;
}
#
on s2.yejr.com {
device
/dev/drbd0;
disk
/dev/sdc1;
address
10.168.115.251:7791;
meta-disk
internal;
}
}

[DRBD ] -- DRBD
, 2008/03/25 - 21:36 yejr
/Email:

http://imysql.cn/

4.

4.1. drbd
2 /dev/sdc1

[root@s1.yejr.com ~]# drbdadm create-md db


[root@s2.yejr.com ~]# drbdadm create-md db
[root@s1.yejr.com ~]# drbdadm create-md db
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=17896845506599536970&ru=16979930778795935552&rs=288106882560
Enter 'no' to opt out, or just press [return] to continue:
success

drbd
[root@s1.yejr.com ~]# /etc/init.d/drbd start
Starting DRBD resources:
[ d(db) s(db) n(db) ].
[root@s2.yejr.com ~]# /etc/init.d/drbd start
Starting DRBD resources:
[ d(db) s(db) n(db) ].
drbd

[root@s1.yejr.com ~]# cat /proc/drbd


version: 8.2.5 (api:88/proto:86-88)
GIT-hash: 9faf052fdae5ef0c61b4d03890e2d2eab550610c build by
root@s1.yejr.com, 2008-03-11 17:09:17
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

[root@s1.yejr.com ~]# drbdadm primary db


State change failed: (-2) Refusing to be Primary without at least one
UpToDate disk
Command 'drbdsetup /dev/drbd0 primary' terminated with exit code 11
[root@s1.yejr.com ~]# drbdsetup /dev/drbd0 primary o
drbdadm drbdsetup
drbdadm
drbd
[root@s1.yejr.com ~]# cat /proc/drbd
version: 8.2.5 (api:88/proto:86-88)
GIT-hash: 9faf052fdae5ef0c61b4d03890e2d2eab550610c build by root@
s1.yejr.com, 2008-03-11 17:09:17
0: cs:SyncSource st:Primary/Secondary ds:UpToDate/Inconsistent C
r--ns:1239556 nr:0 dw:0 dr:1247616 al:0 bm:75 lo:1 pe:6 ua:252 ap:0
[>....................] sync'ed: 0.5% (273541/274751)M
finish: 6:42:27 speed: 11,580 (11,472) K/sec
resync: used:2/31 hits:77642 misses:77 starving:0 dirty:0
changed:77
act_log: used:0/127 hits:0 misses:0 starving:0 dirty:0
changed:0

drbd
[root@ s1.yejr.com ~]# mkfs.ext3 /dev/drbd0
mke2fs 1.35 (28-Feb-2004)
......

[root@ s1.yejr.com ~]# mount /dev/drbd0 /data


/data
secondary drbd
primary primary secondary
primary

[DRBD ] --
, 2008/03/25 - 21:39 yejr
/Email:

http://imysql.cn/

4.2.

s1.yejr.com primary
[root@s1.yejr.com ~]# ifdown eth1
[root@s1.yejr.com ~]# cat /proc/drbd
version: 8.2.5 (api:88/proto:86-88)
GIT-hash: 9faf052fdae5ef0c61b4d03890e2d2eab550610c build by
root@s1.yejr.com, 2008-03-11 17:09:17
0: cs:StandAlone st:Primary/Unknown ds:UpToDate/DUnknown
r--[root@s1.yejr.com ~]# drbdadm state db

Primary/Unknown
primary secondary secondary

[root@s1.yejr.com ~]# cat /proc/drbd


version: 8.2.5 (api:88/proto:86-88)
GIT-hash: 9faf052fdae5ef0c61b4d03890e2d2eab550610c build by
root@s1.yejr.com, 2008-03-11 17:09:17
0: cs:StandAlone st:Secondary/Unknown ds:UpToDate/DUnknown
[root@s1.yejr.com ~]# drbdadm state db
Secondary/Unknown

r---

secondary primary
prmary
[root@s1.yejr.com ~]# ifup eth1
[root@s1.yejr.com ~]# cat /proc/drbd
version: 8.2.5 (api:88/proto:86-88)
GIT-hash: 9faf052fdae5ef0c61b4d03890e2d2eab550610c build by
root@s1.yejr.com, 2008-03-12 13:59:38
0: cs:WFConnection st:Primary/Unknown ds:UpToDate/DUnknown C r--
primary
[root@s1.yejr.com ~]# drbdadmin connect db
drbd
[root@s1.yejr.com ~]# cat /proc/drbd
version: 8.2.5 (api:88/proto:86-88)
GIT-hash: 9faf052fdae5ef0c61b4d03890e2d2eab550610c build by
root@s1.yejr.com, 2008-03-12 13:59:38
0: cs:Connected st:Primary/Secondary ds:UpToDate/UpToDate C r--[root@s1.yejr.com ~]# drbdadm state db
Primary/Secondary


secondary primary

[root@s1.yejr.com ~]# drbdadmin -- --discard-my-data connect db


drbdsecondary primary
secondary primary
secondry
primary secondary
primary primary
secondary

[DRBD ] --
, 2008/03/25 - 21:41 yejr
/Email:

http://imysql.cn/

5.
primary
[root@s1.yejr.com ~]# cp mysql-6.0.3.tar.gz /data/
[root@s1.yejr.com ~]# ls l /data/

-rw-r--r-- 1 root root 56857784 Mar 13 16:41 mysql-6.0.3-alphalinux-x86_64-glibc23.tar.gz


primary secondary secondary primary
[root@s1.yejr.com ~]# umount /data
[root@s1.yejr.com ~]# drbdadm secondary db

primary umount
secondary
[root@s2.yejr.com ~]# drbdadm primary db
[root@s2.yejr.com ~]# mount /dev/drbd0 /data
[root@s2.yejr.com ~]# ls l /data

-rw-r--r-- 1 root root 56857784 Mar 13 16:41 mysql-6.0.3-alphalinux-x86_64-glibc23.tar.gz

drbd
FAQ drbd
mysql replication

drbd heartbeat

You might also like