DRBD + heartbeat + mysql

1.
A. B. CentOS 5.5 x86 ( Kernel-2.6.18-194.e15 ) Node hostname & IP a. primary : node1 b. 192.168.0.43

secondary : node2 192.168.0.44

c.

Virtual ip : 192.168.0.79

2. DRBD

q

1) RPM q - Centos yum . - http://mirror.centos.org/centos/5/extras/x86_64/RPMS/ - node1, node2 .

[root@node1drbd]# yum install *-drbd83* [root@node1 ~]# rpm -qa |grepdrbd drbd83-8.3.8-1.el5.centos kmod-drbd83-xen-8.3.8-1.el5.centos kmod-drbd83-8.3.8-1.el5.centos kmod-drbd83-PAE-8.3.8-1.el5.centos

2) (/etc/drbd.conf) /etc/drbd.conf - /dev/hda5 /dev/sda9

. .

# please have a a look at the example configuration file in # /usr/share/doc/drbd83/drbd.conf # global { usage-count yes; } resource "database" { protocol C; handlers { pri-on-incon-degr "echo 'pri-on-incon-degr'"; pri-lost-after-sb "echo 'pri-lost-after-sb'"; local-io-error "echo 'local-io-error'"; } startup { wfc-timeout 300; degr-wfc-timeout 120; } disk { on-io-error detach; } net { timeout 60; connect-int 10; ping-int 10;

max-buffers 20000; max-epoch-size 20000; unplug-watermark 20000; } syncer { rate 512M; verify-alg md5; } on node1 { device /dev/drbd0; disk /dev/sdb; address 192.168.0.164:7791; meta-disk internal; } on node2 { device /dev/drbd0; disk /dev/sdb; address 192.168.0.165:7791; meta-disk internal; } }

- Hostname [root@node1 ~]# cat /etc/hosts node1 node2 192.168.0.43 192.168.0.44

- Meta Data

. (Master / Secondary

)

Meta Data ??? , r . . . (Index) . . [root@node1 ~]# drbdadm create-md all --== Thank you for participating in the global usage survey The server's response is: you are the 7602th user to install this version md_offset 53687087104 al_offset 53687054336 bm_offset 53685415936 Found ext3 filesystem 52428800 kB data area apparently used 52427164 kB left usable by current configuration Device size would be truncated, which would corrupt data and result in ==-9 q , , , . 9 ,

'access beyond end of device' errors. You need to either * use external meta data (recommended) * shrink that filesystem first * zero out the device (destroy the filesystem) Operation refused. Command 'drbdmeta 0 v08 /dev/sdb internal create-md' terminated with exit code 40 drbdadm create-md database: exited with code 40

. . * use external meta data (recommended) * shrink that filesystem first * zero out the device (destroy the filesystem)

/dev/hda5 umount dd

ext3 . zero out the device meta data overwirte . . .

[root@node1 ~]# vim /etc/fstab [root@node1 ~]# umount /dev/sdb [root@node1 ~]# dd if=/dev/zero of=/dev/sdbbs=1M count=128 128+0 records in 128+0 records out 134217728 bytes (134 MB) copied, 4.78162 seconds, 28.1 MB/s [root@node1 ~]# drbdadm create-md all Writing meta data... initializing activity log NOT initialized bitmap New drbdmeta data block successfully created. success dd if=FILE read from FILE instead of stdin . of=FILE write to FILE instead of stdout . bs=BYTES force ibs=BYTES and obs=BYTES . count=BLOCKS copy only BLOCKS input blocks ibs .

3)

(

)

[root@node1 ~]# /etc/init.d/drbd start Starting DRBD resources: [ database Found valid meta data in the expected location, 53687087104 bytes into /dev/sdb.

d(database) s(database) n(database) ].......... [root@node2 ~]# /etc/init.d/drbd start Starting DRBD resources: [ database Found valid meta data in the expected location, 53687087104 bytes into /dev/sdb. d(database) s(database) n(database) ].

4)

SYNC .. HDD SYNC , node1 . node2 .

/proc/drbd

.

[root@node1 ~]# drbdadm -- --overwrite-data-of-peer primary all [root@node1 ~]# cat /proc/drbd version: 8.3.8 (api:88/proto:86-94) GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16 0: cs:SyncSourcero:Primary/Secondary ds:UpToDate/Inconsistent C r---ns:305780 nr:0 dw:0 dr:385760 al:0 bm:18 lo:1 pe:84 ua:2500 ap:0 ep:1 wo:b oos:52124060 [>....................] sync'ed: 0.6% (50900/51196)Mdelay_probe: 19

finish: 0:41:45 speed: 20,576 (27,552) K/sec [root@node2 ~]# cat /proc/drbd version: 8.3.8 (api:88/proto:86-94) GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16 0: cs:SyncTargetro:Secondary/Primary ds:Inconsistent/UpToDate C r---ns:0 nr:1411296 dw:1409184 dr:0 al:0 bm:85 lo:68 pe:15466 ua:66 ap:0 ep:1 wo:b oos:51017980 [>....................] sync'ed: 2.7% (49820/51196)Mqueue_delay: 6.6 ms

finish: 0:19:01 speed: 44,624 (41,444) want: 524,288 K/sec

3. Heartbeat
1)

q

Heartbeat q [root@node1 ~]# yum install heartbeat

2)

heartbeat .

[root@node1 ~]#cd /etc/ha.d/ [root@node1 ha.d]#vi authkeys [root@node1 ha.d]#chmod 600 authkeys [root@node1 ha.d]#cat authkeys auth 2 2 sha1 difficultp@ssw0rd

-

ha.cf ha.cf

. .

[root@node1 ~]#cd /etc/ha.d/ [root@node1 ha.d]#vi ha.cf [root@node1 ha.d]#cat ha.cf debugfile /var/log/ha-debug logfile /var/log/ha-log logfacility local0 keepalive 1 deadtime 10 warntime 4 initdead 60 udpport 694 ucast eth0 192.168.0.44 ping 192.168.0.44 respawnhacluster /usr/lib/heartbeat/ipfail auto_failback off node node1 node node2

[root@node2 ha.d]#cat ha.cf debugfile /var/log/ha-debug logfile /var/log/ha-log logfacility local0

keepalive 1 deadtime 10 warntime 4 initdead 60 udpport 694 ucast eth0 192.168.0.43 ping 192.168.0.43 respawnhacluster /usr/lib/heartbeat/ipfail

auto_failback off

node node2 node node1

3)

haresources

. failover .

[root@node1 ha.d]#vi haresources [root@node1 ha.d]#cat haresources node1drbddisk::database \ Filesystem::/dev/drbd0::/database::ext3::noatime,nodiratime \ Delay::2::0 \ IPaddr::192.168.0.79/24/eth0

[root@node2 ha.d]#vi haresources [root@node2 ha.d]#cat haresources node2drbddisk::database \ Filesystem::/dev/drbd0::/database::ext3::noatime,nodiratime \ Delay::2::0 \ IPaddr::192.168.0.79/24/eth0

heartbeat haresources . /database

.

.

[root@node1 ~]#mkdir /database [root@node1 ~]#mkfs -t ext3 /dev/drbd0

heartbeat

.

[root@node1 ~]#/etc/init.d/heartbeat start Starting High-Availability services: Done.

[root@node2 ~]#/etc/init.d/heartbeat start Starting High-Availability services: Done.

. .

eth0:0

192.168.0.79

virual IP

[root@node2 ~]#ifconfig eth0:0inet addr:192.168.0.79 eth0 inet addr:192.168.0.44

heartbeat

. .

[root@node2 ~]#/etc/init.d/heartbeat stop Stopping High-Availability services: Done.

.

[root@node1 ~]#ifconfig eth0:0inet addr:192.168.0.79 eth0 inet addr:192.168.0.43

4) q [root@node1 ~]# mkfs -t ext3 -j /dev/drbd0 [root@node1 ~]# mount /dev/drbd0 /database [root@node1 test]# du -sh * 861M TestFile 0 aaa 0 bbb 0 ccc 16K lost+found [root@node1 /]# umount /test/ [root@node1 /]# drbdsetup /dev/drbd0 secondary [root@node2 home]# drbdsetup /dev/drbd0 primary [root@node2 home]# mount /dev/drbd0 /database [root@node2 home]# du -sh * 861M TestFile 0 aaa 0 bbb 0 ccc 16K lost+found ... .....

1 /proc/drbd 800 4. Mysql q 1) Mysql Mysql 2) Node1 º

. . .

q node1

q

.

[root@node1 etc]# ln s /usr/local/mysql/share/mysql/mysql.server/etc/ha.d/resource.d/mysql ### heartbeat msyql resource . [root@node1 ha.d]#vi haresources [root@node1 ha.d]#cat haresources node1drbddisk::database \ Filesystem::/dev/drbd0::/database::ext3::noatime,nodiratime \ Delay::2::0 \ mysql \ IPaddr::192.168.0.79/24/eth0

3)

Node2

[root@node2~]# scp r 192.168.0.43:/usr/local/mysql /usr/local/ [root@node2~]# scp r 192.168.0.43:/etc/my.cnf /etc/ [root@node2~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/ [root@node2~]# ln -s /usr/local/mysql/bin/mysqldump /usr/bin/ [root@node2~]# ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/ [root@node2~]# ln s /usr/local/mysql/share/mysql/mysql.server/etc/ha.d/resource.d/mysql [root@node2 ha.d]#vi haresources [root@node2 ha.d]#cat haresources node2drbddisk::database \ Filesystem::/dev/drbd0::/database::ext3::noatime,nodiratime \ Delay::2::0 \ mysql \ IPaddr::192.168.0.79/24/eth0