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

來源:互聯網
上載者:User

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

配置資訊:

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

主要分為如下步驟:
1、安裝DRBD
2、安裝Mysql
3、測試DRBD
4、安裝Heartbeat
5、測試Heartbeat


1、安裝DRBD
下載drbd:
wget http://oss.linbit.com/drbd/8.4/drbd-8.4.0.tar.gz


在zbdba1、zbdba2:
添加磁碟

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
安裝依賴包:

yum install gcc flex rpm-build kernel-devel docbook-style-xsl -y
建立rpm目錄:

rpmbuild ~
解壓並產生rpm包:
tar xvf drbd-8.4.0.tar.gz  嘗試了8.4.3,版本太新 linux核心不相容./configuremake rpm make km-rpm此時已經產生drbd的rpm包
進入安裝:
cd /root/rpmbuild/RPMS/x86_64yum install * -y
查看drbd模組:
modprobe drbdlsmod |grep drbd
配置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
在zbdba1:

drbdsetup /dev/drbd0  primary --force監控傳輸速率:[root@Dbrd1 etc]# watch cat /proc/drbdEvery 2.0s: cat /proc/drbd                                                                                                                     Mon Jan 19 07:27:45 2015version: 8.4.0 (api:1/proto:86-100)GIT-hash: 28753f559ab51b549d16bcf487fe625d5919c49c build by root@Dbrd1, 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其中:ro是角色資訊:Primary/Secondary(代表這個是主節點)                    Secondary/Primary(代表這個是副節點)      ds是磁碟狀態:UpToDate/Inconsistent(正在同步,資料還沒有一致)                    UpToDate/UpToDate    (同步完成,資料一致)      ns是網路傳輸的資料包:以K為位元組          dw是磁碟寫操作      dr是磁碟讀操作掛載mysql目錄:mkdir /mysqlmkfs.ext4 /dev/drbd0mount /dev/drbd0 /mysql
查看DRBD狀態:

[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、安裝Mysql:
tar -zxvf mysql-5.6.12-linux-glibc2.5-x86_64mv mysql-5.6.12-linux-glibc2.5-x86_64 /mysql添加使用者groupadd mysqluseradd mysql -g mysqlchown -R mysql.mysql mysql/cp support-files/my-default.cnf /etc/my.cnf在my.cnf中制定資料庫基本目錄:[mysqld]basedir =/mysqldatadir = /mysql/data初始化資料庫:scripts/mysql_install_db --user=mysqlcp support-files/mysql.server /etc/init.d/mysqlchkconfig mysql onservice mysql start修改環境變數:vi /root/.bash_profilePATH=$PATH:$HOME/bin:/mysql/bin
3、測試DRBD:

在zbdba1:service mysql stopumount /dev/drbd0drbdadm secondary zbdbascp /etc/my.cnf zbdba2:`pwd`在zbdba2:drbdadm primary zbdbamount /dev/drbd0 /mysqlcp support-files/mysql.server /etc/init.d/mysqlchkconfig mysql on啟動mysql:service mysql start測試成功
4、安裝Heartbeat:

在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
設定檔內容如下:

[root@zbdba1 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[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查看vip是否啟動: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配置成功
5、測試Heartbeat:

1、直接關閉hearbeat

[root@zbdba1 ha.d]# service heartbeat stop監控zbdba1上ha-log日誌: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 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/resource.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 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.
監控zbdba2上的ha-log:Jan 20 20:43:58 zbdba2 heartbeat: [1573]: info: Received shutdown notice from 'zbdba1'.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(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: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]:       2015/01/20_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.

查看zbdba1的drbd角色:
[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
查看zbdba2的drbd角色:
[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
查看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
查看zbdba2上mysql是否正常運行:
[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>
哈哈,終於測試成功,heartbeat不會監控mysql服務是否正常、所以需要自己寫指令碼監控mysql的服務狀態



















相關文章

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.