Configuration information:
Primary:Name:zbdba1OS:redhat 6.3ip:192.168.56.220drbd:8.4.0heartbeat:3.0.4standby:name:zbdba2os:redhat 6.3IP : 192.168.56.221drbd:8.4.0heartbeat:3.0.4
Mainly divided into the following steps:
1. Installing DRBD
2. Install MySQL
3. Test DRBD
4, installation Heartbeat
5. Test Heartbeat
1. Installing DRBD
Download DRBD:
wget http://oss.linbit.com/drbd/8.4/drbd-8.4.0.tar.gz
In Zbdba1, Zbdba2:
Add disk
disk/dev/sdb:8589 MB, 8589934592 bytes255 heads, sectors/track, 1044 cylindersunits = cylinders of 16065 * 512 = 8225 280 bytessector Size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): + bytes/512 Bytesdisk identi fier:0x00000000
To install a dependency package:
Yum install GCC flex rpm-build kernel-devel docbook-style-xsl-y
To set up the RPM directory:
Rpmbuild ~
Unzip and generate the RPM package:
Tar xvf drbd-8.4.0.tar.gz tried 8.4.3, version too new for the Linux kernel is incompatible./configuremake rpm make km-rpm the RPM package for DRBD has been generated
Enter the installation:
Cd/root/rpmbuild/rpms/x86_64yum Install *-y
To view the DRBD module:
Modprobe drbdlsmod |grep DRBD
To configure DRBD:
[[email protected] etc]# cat drbd.confinclude "Drbd.d/drbd.conf.example"; [[email protected] etc]# cat drbd.d/drbd.conf.exampleresource zbdba {options {On-no-data-acce Ssible Suspend-io; } NET {cram-hmac-alg "SHA1"; Shared-secret "Secret_string"; # The disk section was possible on resource level and in each # Volume section disk { # If you had a resonable RAID controller # with non volatile write cache (BBWC, flash) dis K-flushes No; Disk-barrier No; Md-flushes No; } # Volume sections on resource level, is inherited to all node # sections. Place it if the backing devices has the same # device names on all your nodes.# volume 1 {# Device minor 1;# disk/dev/sdb;# meta-disk internal;## Disk {# Resync-after example/0;#}#} on zbdba1 {address 192.168.56.220:7780; Volume 0 {device minor 0; Disk/dev/sdb; Meta-disk internal; }} on zbdba2 {address 192.168.56.221:7780; Volume 0 {device minor 0; Disk/dev/sdb; Meta-disk internal; }}}drbdadm CREATE-MD zbdba[[email protected] etc]# service DRBD start[[email protected] etc]# service Dr BD Start
In ZBDBA1:
DRBDSETUP/DEV/DRBD0 primary--force monitoring transfer rate: [[email protected] etc]# watch Cat/proc/drbdevery 2.0S:CAT/PROC/DRBD Mon Jan 07:27:45 2015version:8.4.0 (api:1/proto:86-100) git-hash:28753f559ab51b549d16bcf487fe625d5919c49c build by [email& Nbsp;protected], 2015-01-19 03:52:170:cs:syncsource ro:primary/secondary ds:uptodate/inconsistent C r-----ns:6976912 nr:0 dw:639076 dr:6339457 al:169 bm:400 lo:0 pe:4 ua:1 ap:0 ep:1 wo:d oos:1820288 [==============> ...] Sync ' ed:78.4% (1776/8188) M finish:0:00:41 speed:43,688 (29,716) k/sec1:cs:connected ro:secondary/secondary ds: Diskless/diskless C R-----ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0 Where: RO is role information: Primary/secondar Y (for this is the primary node) Secondary/primary (This is the secondary node) DS is the disk status: Uptodate/inconsistent (synchronizing, data is not consistent) Uptodate/uptodate (sameStep complete, data consistent) NS is a network-transmitted packet: A K-byte DW is a disk write operation Dr is a disk read operation mount MySQL directory: mkdir/mysqlmkfs.ext4/dev/drbd0mount/dev/drbd0 /mysql
To view the DRBD status:
[[Email protected] ~]# service DRBD STATUSDRBD driver loaded OK; Device status:version:8.4.0 (api:1/proto:86-100) git-hash:28753f559ab51b549d16bcf487fe625d5919c49c build by [email Protected], 2015-01-19 03:52:17m:res cs ro ds P mounted fstype0:zbdba Connected Primary/secondary uptodate/uptodate C /mysql ext4[[email protected] ~]# service DRBD STATUSDRBD Driver loaded OK; Device status:version:8.4.0 (api:1/proto:86-100) git-hash:28753f559ab51b549d16bcf487fe625d5919c49c build by [email Protected], 2015-01-19 03:52:17m:res cs ro ds P mounted fstype0:zbdba Connected secondary/primary uptodate/uptodate C
2. Install MySQL:
TAR-ZXVF mysql-5.6.12-linux-glibc2.5-x86_64mv mysql-5.6.12-linux-glibc2.5-x86_64/mysql Add user Groupadd Mysqluseradd Mysql-g mysqlchown-r mysql.mysql MYSQL/CP support-files/my-default.cnf/etc/my.cnf make a database base directory in MY.CNF: [Mysqld]basedir =/mysqldatadir =/mysql/data Initialization database: scripts/mysql_install_db--USER=MYSQLCP support-files/mysql.server/etc/init.d/ Mysqlchkconfig MySQL onservice mysql start modify environment variable: vi/root/.bash_profilepath= $PATH: $HOME/bin:/mysql/bin
3. Test DRBD:
In Zbdba1:service MySQL stopumount/dev/drbd0drbdadm secondary zbdbascp/etc/my.cnf zbdba2: ' pwd ' in Zbdba2:drbdadm primary ZBDBAMOUNT/DEV/DRBD0/MYSQLCP support-files/mysql.server/etc/init.d/mysqlchkconfig MySQL on start mysql:service MySQL Start Test succeeded
4, Installation Heartbeat:
In Zbdba1, zbdba2:cluster-glue-1.0.5-6.el6.x86_64cluster-glue-libs-1.0.5-6.el6.x86_64heartbeat-3.0.4-1.el6.x86_ 64heartbeat-libs-3.0.4-1.el6.x86_64perl-timedate-1.16-11.1.el6.noarchresource-agents-3.9.2-21.el6.x86_6yum Install *-ycp/usr/share/doc/heartbeat-3.0.4/ha.cf/etc/ha.d/ha.cfcp/usr/share/doc/heartbeat-3.0.4/authkeys/etc/ Ha.d/authkeyscp/usr/share/doc/heartbeat-3.0.4/haresources/etc/ha.d/haresources
The contents of the configuration file are as follows:
[email protected] ha.d]# cat ha.cfdebugfile/var/log/ha-debuglogfile/var/log/ha-loglogfacility local0keepalive 2deadtime 30warntime 10bcast eth0 # linux#bcast eth1 eth2 # linux#bcast le0 # Solaris#bcast le1 le2 # solarisauto_failback onnode zbdba1node zbdba2[[email protected] ha.d]# cat Authkeysauth 11 Crc[[email protected] ha.d]# cat haresourceszbdba1 192.168.56.225/24/eth0 drbddisk::zbdba filesystem::/dev/drbd0::/ MYSQL::EXT4 Mysqlservice Heartbeat start to see if the VIP starts: eth0:0 Link encap:ethernet HWaddr 08:00:27:eb:ce:6f inet addr:192.168.56.225 bcast:192.168.56.255 mask:255.255.255.0 up broadcast RUNNING multicast mtu:1500 metric:1tail- 100f /var/log/ha-log Configuration succeeded
5, Test heartbeat:
1. Close the Hearbeat directly
[[email protected] ha.d]# service heartbeat stop monitoring Zbdba1 on Ha-log log: Jan 20:43:56 zbdba1 Heartbeat: [1517]: Info:he Artbeat shutdown in progress. (1517) Jan 20:43:56 zbdba1 Heartbeat: [2672]: info:giving up all HA resources. ResourceManager (default) [2685]: 2015/01/20_20:43:56 info:releasing resource Group:zbdba1 192.168.56.225/24/eth0 DRBDDISK::ZBDBA FILESYSTEM::/DEV/DRBD0::/MYSQL::EXT4 Mysqlresourcemanager (default) [2685]: 2015/01/20_20:43:56 info : Running/etc/init.d/mysql Stopresourcemanager (default) [2685]: 2015/01/20_20:43:58 info:running/etc/ha.d/ Resource.d/filesystem/dev/drbd0/mysql ext4 Stopfilesystem (filesystem_/dev/drbd0) [2772]: 2015/01/20_20:43:58 INFO: Running Stop for/dev/drbd0 On/mysqlfilesystem (filesystem_/dev/drbd0) [2772]: 2015/01/20_20:43:58 info:trying to Unmount/mysqlfilesystem (FILESYSTEM_/DEV/DRBD0) [2772]: 2015/01/20_20:43:58 info:unmounted/mysql successfully/usr/ Lib/ocf/resource.d//heartbeat/filesystem (FILESYSTEM_/DEV/DRBD0) [2764]: 2015/01/20_20:43:58 info:successresourcemanager (default) [2685]: 2015/01/20_20:43:58 info:running/etc/ha.d/re Source.d/drbddisk zbdba Stopresourcemanager (default) [2685]: 2015/01/20_20:43:58 info:running/etc/ha.d/resource.d/ IPAddr 192.168.56.225/24/eth0 stopipaddr (ipaddr_192.168.56.225) [2929]: 2015/01/20_20:43:58 info:ifconfig eth0:0 down /USR/LIB/OCF/RESOURCE.D//HEARTBEAT/IPADDR (ipaddr_192.168.56.225) [2903]: 2015/01/20_20:43:58 Info:successjan 20 20:43:58 zbdba1 Heartbeat: [2672]: Info:all HA Resources relinquished. Jan 20:43:59 zbdba1 Heartbeat: [1517]: Warn:1 lost Packet (s) for [ZBDBA2] [835:837]jan 20:43:59 zbdba1 Heartbeat: [ 1517]: Info:no pkts missing from zbdba2! Jan 20:44:00 zbdba1 Heartbeat: [1517]: info:killing Hbfifo process 1526 with signal 15Jan 20:44:00 zbdba1 Heartbeat : [1517]: info:killing hbwrite process 1527 with signal 15Jan 20:44:00 zbdba1 Heartbeat: [1517]: info:killing hbread Process 1528 with signal 15Jan 20:44:00 ZBDBA1 HeArtbeat: [1517]: Info:core process 1526 exited. 3 Remainingjan 20:44:00 zbdba1 heartbeat: [1517]: Info:core process 1528 exited. 2 Remainingjan 20:44:00 zbdba1 heartbeat: [1517]: Info:core process 1527 exited. 1 Remainingjan 20:44:00 zbdba1 heartbeat: [1517]: Info:zbdba1 heartbeat shutdown complete.
Monitor Zbdba2 on Ha-log:jan 20:43:58 zbdba2 Heartbeat: [1573]: info:received shutdown notice from ' zbdba1 '. Jan 20:43:58 zbdba2 Heartbeat: [1573]: Info:resources being acquired from ZBDBA1. Jan 20:43:58 zbdba2 Heartbeat: [1979]: Info:acquire local HA resources (standby). Jan 20:43:58 zbdba2 Heartbeat: [1980]: Info:no local resources [/usr/share/heartbeat/resourcemanager Listkeys ZBDBA2] To acquire. Jan 20:43:58 zbdba2 Heartbeat: [1979]: Info:local HA Resource acquisition completed (standby). Jan 20:43:58 zbdba2 Heartbeat: [1573]: Info:standby resource acquisition Done [All].harc (default) [2005]: 2015/01/20 _20:43:58 info:running/etc/ha.d//rc.d/status Statusmach_down (default) [2022]: 2015/01/20_20:43:58 info:taking over Resource group 192.168.56.225/24/eth0resourcemanager (default) [2049]: 2015/01/20_20:43:58 info:acquiring Resource Group:zbdba1 192.168.56.225/24/eth0 drbddisk::zbdba FILESYSTEM::/DEV/DRBD0::/MYSQL::EXT4 mysql/usr/lib/ocf/ Resource.d//heartbeat/ipaddr(ipaddr_192.168.56.225) [2077]: 2015/01/20_20:43:58 info:resource is Stoppedresourcemanager (default) [2049]: 2015/01/20_20:43:58 info:running /etc/ha.d/resource.d/ipaddr 192.168.56.225/24/eth0 startipaddr (ipaddr_192.168.56.225) [2164]: 2015/01/20_20:43:59 Info:using calculated netmask for 192.168.56.225:255.255.255.0ipaddr (ipaddr_192.168.56.225) [2164]: 2015/01/20_20:43 : Info:eval ifconfig eth0:0 192.168.56.225 netmask 255.255.255.0 broadcast 192.168.56.255/usr/lib/ocf/resource.d//heartbeat/ipaddr (ipaddr_ 192.168.56.225) [2138]: 2015/01/20_20:43:59 info:successresourcemanager (default) [2049]: 2015/01/20_20:43:59 INFO: Running/etc/ha.d/resource.d/drbddisk zbdba Start/usr/lib/ocf/resource.d//heartbeat/filesystem (Filesystem_/dev/ DRBD0) [2300]: 2015/01/20_20:43:59 Info:resource is Stoppedresourcemanager (default) [2049]: 2015/01/20_20:43:59 INFO: Running/etc/ha.d/resource.d/filesystem/dev/drbd0/mysql ext4 Startfilesystem (filesystem_/dev/drbd0) [2379]: 2015/0 1/20_20:43: info:running start for/dev/drbd0 on/mysql/usr/lib/ocf/resource.d//heartbeat/filesystem (Filesystem_/dev/drbd0) [ 2371]: 2015/01/20_20:43:59 info:successresourcemanager (default) [2049]: 2015/01/20_20:43:59 info:running/etc/init.d /mysql Startmach_down (default) [2022]: 2015/01/20_20:44:03 info:/usr/share/heartbeat/mach_down:nice_failback:fore IGN Resources Acquiredmach_down (default) [2022]: 2015/01/20_20:44:03 Info:mach_down takeover complete for node ZBDBA 1.Jan 20:44:03 zbdba2 Heartbeat: [1573]: Info:mach_down takeover complete. Jan 20:44:30 zbdba2 Heartbeat: [1573]: Warn:node zbdba1:is Deadjan (20:44:30 zbdba2 heartbeat: [1573]: info:dead n Ode Zbdba1 gave up resources. Jan 20:44:30 zbdba2 Heartbeat: [1573]: Info:link zbdba1:eth0 dead.
To view the DRBD role for ZBDBA1:
[[Email protected] ha.d]# service DRBD STATUSDRBD driver loaded OK; Device status:version:8.4.0 (api:1/proto:86-100) git-hash:28753f559ab51b549d16bcf487fe625d5919c49c build by [email Protected], 2015-01-19 03:52:17m:res cs ro ds P mounted fstype0:zbdba Connected Secondary/primary uptodate/uptodate C
To view the DRBD role for ZBDBA2:
[[Email protected] ~]# service DRBD STATUSDRBD driver loaded OK; Device status:version:8.4.0 (api:1/proto:86-100) git-hash:28753f559ab51b549d16bcf487fe625d5919c49c build by [email Protected], 2015-01-19 03:52:17m:res cs ro ds P mounted fstype0:zbdba Connected Primary/secondary uptodate/uptodate C /mysql ext4
View Zbdba2 's VIP:
[Email protected] ~]# ifconfigeth0 Link encap:ethernet HWaddr 08:00:27:eb:ce:6f inet Addr : 192.168.56.221 bcast:192.168.56.255 mask:255.255.255.0 inet6 addr:fe80::a00:27ff:feeb:ce6f/64 Scope : Link up broadcast RUNNING multicast mtu:1500 metric:1 RX packets:906411 errors:0 dropped:0 Overruns : 0 frame:0 TX packets:396042 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1364740285 (1.2 GiB) TX bytes:26821136 (25.5 MiB) eth0:0 Link encap:ethernet HWaddr 08:00:27:eb: ce:6f inet addr:192.168.56.225 bcast:192.168.56.255 mask:255.255.255.0 up broadcast RUNNING Multicast mtu:1500 metric:1
To see if MySQL is working correctly on ZBDBA2:
[[email protected] ~]# ps-ef |grep mysqlroot 2508 1 0 20:43? 00:00:00/bin/sh/mysql/bin/mysqld_safe--datadir=/mysql/data--pid-file=/mysql/data/zbdba2.pidmysql 2647 2508 0 20: 44? 00:00:01/mysql/bin/mysqld--basedir=/mysql--datadir=/mysql/data--plugin-dir=/mysql/lib/plugin--user=mysql-- Log-error=/mysql/data/zbdba2.err--pid-file=/mysql/data/zbdba2.pidroot 2734 1824 0 20:46 pts/0 00:00:00 grep mys Ql[[email protected] ~]# mysqlwelcome to the MySQL Monitor. Commands End With; or \g.your MySQL connection ID is 1Server version:5.6.12 mysql Community Server (GPL) Copyright (c) +, Oracle and /or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.mysql>
Haha, finally test success, Heartbeat will not monitor the MySQL service is normal, so need to write their own scripts to monitor the status of MySQL service
Mysql Ha-install Drbd+heartbeat+mysql on Redhat 6.3