Mysql HA-Install DRBD + HeartBeat + Mysql On Redhat 6.3, ha-installdrbd

Source: Internet
Author: User
Tags flushes rpmbuild

Mysql HA-Install DRBD + HeartBeat + Mysql On Redhat 6.3, ha-installdrbd

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

The procedure is as follows:
1. Install DRBD
2. Install Mysql
3. Test DRBD
4. Install Heartbeat
5. Test Heartbeat


1. Install DRBD
Download drbd:
Wget http://oss.linbit.com/drbd/8.4/drbd-8.4.0.tar.gz


In zbdba1 and zbdba2:
Add Disk

Disk /dev/sdb: 8589 MB, 8589934592 bytes255 heads, 63 sectors/track, 1044 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000
Install the dependency package:

yum install gcc flex rpm-build kernel-devel docbook-style-xsl -y
Create an rpm directory:

rpmbuild ~
Decompress and generate the rpm package:
Tar xvf drbd-8.4.0.tar.gz tried 8.4.3, version too new Linux kernel incompatible./configuremake rpm make km-rpm at this time has generated the drbd rpm package
Go to installation:
cd /root/rpmbuild/RPMS/x86_64yum install * -y
View the drbd module:
modprobe drbdlsmod |grep drbd
Configure DRBD:

[root@zbdba1 etc]# cat drbd.confinclude "drbd.d/drbd.conf.example";[root@zbdba1 etc]# cat drbd.d/drbd.conf.exampleresource zbdba {        options {                on-no-data-accessible suspend-io;        }        net {                cram-hmac-alg "sha1";                shared-secret "secret_string";        }        # The disk section is possible on resource level and in each        # volume section        disk {                # If you have a resonable RAID controller                # with non volatile write cache (BBWC, flash)                disk-flushes no;                disk-barrier no;                md-flushes no;        }        # volume sections on resource level, are inherited to all node        # sections. Place it here if the backing devices have 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[root@zbdba1 etc]# service drbd start[root@zbdba2 etc]# service drbd start
In zbdba1:

Drbdsetup/dev/drbd0 primary -- force monitoring transmission rate: [root @ Dbrd1 etc] # watch cat/proc/drbdEvery 2.0 s: cat/proc/drbd Mon Jan 19 07:27:45 2015 version: 8.4.0 (api: 1/proto: 86-100) GIT-hash: Pull build by root @ Dbrd1, 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 the role information: Primary/Secondary (representing this is the master node) Secondary/Primary (representing this is the Secondary node) ds IS the disk status: UpToDate/Inconsistent (synchronizing, data is not consistent.) UpToDate/UpToDate (synchronization is complete, data is consistent) ns is the data packet transmitted over the network: K-byte dw is disk write operation dr is disk read Operation Mount mysql directory: mkdir/mysqlmkfs. ext4/dev/drbd0mount/dev/drbd0/mysql
View the DRBD status:

[root@zbdba1 ~]# service drbd statusdrbd driver loaded OK; device status:version: 8.4.0 (api:1/proto:86-100)GIT-hash: 28753f559ab51b549d16bcf487fe625d5919c49c build by root@Dbrd1, 2015-01-19 03:52:17m:res    cs         ro                 ds                 p  mounted  fstype0:zbdba  Connected  Primary/Secondary  UpToDate/UpToDate  C  /mysql   ext4[root@zbdba2 ~]# service drbd statusdrbd driver loaded OK; device status:version: 8.4.0 (api:1/proto:86-100)GIT-hash: 28753f559ab51b549d16bcf487fe625d5919c49c build by root@Dbrd1, 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/cp support-files/my-default.cnf/etc/my. cnf in my. specify the basic database directory in cnf: [mysqld] basedir =/mysqldatadir =/mysql/data initialize Database: scripts/mysql_install_db -- user = mysqlcp support-files/mysql. server/etc/init. d/mysqlchkconfig mysql onservice mysql start modify the 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 successful
4. Install 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 configuration file is as follows:

[Root @ zbdba1 ha. d] # cat ha. cfdebugfile/var/log/ha-debuglogfile/var/log/ha-logfacility local0keepalive 2 deadtime 30 warntime 10 bcast eth0 # Linux # bcast eth1 eth2 # Linux # bcast le0 # Solaris # bcast le1 le2 # Solarisauto_failback onnode zbdba1node zbdba2 [root @ zbdba1 ha. d] # cat authkeysauth 11 crc [root @ zbdba1 ha. d] # cat haresourceszbdba1 192.168.56.225/24/eth0 drbddisk: zbdba Filesystem:/dev/drbd0:/mysql: ext4 mysqlservice heartbeat start check whether the vip is started: 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 tail-100f/var/log/ha-log configured successfully
5. Test Heartbeat:

1. Directly disable hearbeat

[Root @ zbdba1 ha. d] # service heartbeat stop monitoring ha-log on zbdba1: Jan 20 20:43:56 zbdba1 heartbeat: [1517]: info: Heartbeat shutdown in progress. (1517) Jan 20 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 mysqlResource Manager (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/mysql Filesystem (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/resource. d/drbddisk zbdba stopResourceManager (default) [2685]: 2015/01/20 _ 20:43:58 info: Running/etc/ha. d/resource. d/IP Addr 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 20:43:59 zbdba1 heartbeat: [1517]: WARN: 1 lost packet (s) for [zbdba2] [835: 837] Jan 20 20:43:59 Zbdba1 heartbeat: [1517]: info: No pkts missing from zbdba2! Jan 20 20:44:00 zbdba1 heartbeat: [1517]: info: killing HBFIFO process 1526 with signal 15Jan 20 20:44:00 zbdba1 heartbeat: [1517]: info: killing HBWRITE process 1527 with signal 15Jan 20 20:44:00 zbdba1 heartbeat: [1517]: info: killing HBREAD process 1528 with signal 15Jan 20 20:44:00 zbdba1 heartbeat: [1517]: info: core process 1526 exited. 3 remainingJan 20 20:44:00 zbdba1 heartbeat: [1517]: info: Core process 1528 exited. 2 remainingJan 20 20:44:00 zbdba1 heartbeat: [1517]: info: Core process 1527 exited. 1 remainingJan 20 20:44:00 zbdba1 heartbeat: [1517]: info: zbdba1 Heartbeat shutdown complete.
Monitor ha-log: Jan 20 20:43:58 zbdba2 heartbeat: [1573]: info: stored ed shutdown notice from 'zbdba1' on zbdba2 '. jan 20 20:43:58 zbdba2 heartbeat: [1573]: info: Resources being acquired from zbdba1.Jan 20 20:43:58 zbdba2 heartbeat: [1979]: info: acquire local HA resources (standby ). jan 20 20:43:58 zbdba2 heartbeat: [1980]: info: No local resources [/usr/share/heartbeat/ResourceManager listkeys zbdba2] to acquire. jan 20 20:43:58 zbdba2 heartbeat: [1979]: info: local HA resource acquisition completed (standby ). jan 20 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 (updated) [2164]: 2015/01/20 _ 20:43:59 INFO: Using calculated netmask for 192.168.56.225: Drawing (updated) [2164]: 2015/01/20 _ 20:43:59 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/01/20 _ 20:43:59 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: foreign resources acquiredmach_down (default) [2022]: 20:44:03 info: mach_down takeover complete for node zbdba1.Jan 20 20:44:03 zbdba2 heartbeat: [1573]: info: mach_down takeover complete. jan 20 20:44:30 zbdba2 heartbeat: [1573]: WARN: node zbdba1: is deadJan 20 20:44:30 zbdba2 heartbeat: [1573]: info: Dead node zbdba1 gave up resources. jan 20 20:44:30 zbdba2 heartbeat: [1573]: info: Link zbdba1: eth0 dead.

View the drbd role of zbdba1:
[root@zbdba1 ha.d]# service drbd statusdrbd driver loaded OK; device status:version: 8.4.0 (api:1/proto:86-100)GIT-hash: 28753f559ab51b549d16bcf487fe625d5919c49c build by root@Dbrd1, 2015-01-19 03:52:17m:res    cs         ro                 ds                 p  mounted  fstype0:zbdba  Connected  Secondary/Primary  UpToDate/UpToDate  C
View the drbd role of zbdba2:
[root@zbdba2 ~]# service drbd statusdrbd driver loaded OK; device status:version: 8.4.0 (api:1/proto:86-100)GIT-hash: 28753f559ab51b549d16bcf487fe625d5919c49c build by root@Dbrd1, 2015-01-19 03:52:17m:res    cs         ro                 ds                 p  mounted  fstype0:zbdba  Connected  Primary/Secondary  UpToDate/UpToDate  C  /mysql   ext4
View zbdba2 VIP:
[root@zbdba2 ~]# 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
Check whether mysql runs properly on zbdba2:
[root@zbdba2 ~]# 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 mysql[root@zbdba2 ~]# 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) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
Haha, the test is successful. heartbeat does not monitor whether the mysql service is normal. Therefore, you need to write a script to monitor the mysql service status.



















Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.