文档章节

Mysql MHA

b
 birdsdeng
发布于 2015/12/24 15:02
字数 1265
阅读 36
收藏 0

1环境准备

192.168.110.128 Master

192.168.110.129 Slave1

192.168.110.130 Slave2 也是manger

OS version: CentOS release 6.5 (Final)

Kernel 2.6.32-431.el6.x86_64

Mysql version: 5.6.19

/etc/hosts

192.168.110.128 master

192.168.110.129 slave1

192.168.110.130 slave2

192.168.110.130 manager

 

主机间互信

Master:

ssh-keygen -t rsa

ssh-copy-id -i /root/.ssh/id_rsa.pub 'root@192.168.110.129 -p25191'

ssh-copy-id -i /root/.ssh/id_rsa.pub 'root@192.168.110.130 -p25191'

slave1:

ssh-keygen -t rsa

ssh-copy-id -i /root/.ssh/id_rsa.pub 'root@192.168.110.128 -p25191'

ssh-copy-id -i /root/.ssh/id_rsa.pub 'root@192.168.110.130 -p25191'

slave2:

ssh-keygen -t rsa

ssh-copy-id -i /root/.ssh/id_rsa.pub 'root@192.168.110.128 -p25191'

ssh-copy-id -i /root/.ssh/id_rsa.pub 'root@192.168.110.129 -p25191'

ssh-copy-id -i /root/.ssh/id_rsa.pub 'root@192.168.110.130 -p25191'

2 下载mha

下载: mha4mysql-node-0.54-0.el6.noarch.rpm

https://code.google.com/p/mysql-master-ha/downloads/list

3,安装mha,所有节点都要安装

rpm -ivh mha4mysql-node-0.54-0.el6.noarch.rpm

4,管理节点安装

yum install -y perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes

rpm -ivh mha4mysql-manager-0.55-0.el6.noarch.rpm

5 创建管理账户

每台机器上:

grant all privileges on *.* TO mha@'192.168.%' IDENTIFIED BY 'test';

flush privileges;

 

6,配置管理端

编辑文件: /etc/mha/app1.cnf

[root@localhost 2015-12-24_11-35-23]# cat /etc/mha/app1.cnf

[server default]

manager_log=/var/log/mha/app1/manager.log

manager_workdir=/var/log/mha/app1.log

master_binlog_dir=/data/mysql

password=test

ping_interval=2

repl_password=123qwe

repl_user=backup

ssh_port=25191

ssh_user=root

user=mha

[server1]

hostname=master

port=3306

[server2]

candidate_master=1 #从的优先级,1优先级最大

check_repl_delay=0

hostname=slave1

port=3306

[server3]

check_repl_delay=0

hostname=slave2

port=3306

no_master=1 #永远不为master

 

7,检测ssh是否正常

[root@localhost ~]# masterha_check_ssh --conf=/etc/mha/app1.cnf

Thu Dec 24 14:37:59 2015 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.

Thu Dec 24 14:37:59 2015 - [info] Reading application default configurations from /etc/mha/app1.cnf..

Thu Dec 24 14:37:59 2015 - [info] Reading server configurations from /etc/mha/app1.cnf..

Thu Dec 24 14:37:59 2015 - [info] Starting SSH connection tests..

Thu Dec 24 14:38:00 2015 - [debug]

Thu Dec 24 14:37:59 2015 - [debug]  Connecting via SSH from root@master(192.168.110.128:25191) to root@slave1(192.168.110.129:25191)..

Thu Dec 24 14:37:59 2015 - [debug]   ok.

Thu Dec 24 14:37:59 2015 - [debug]  Connecting via SSH from root@master(192.168.110.128:25191) to root@slave2(192.168.110.130:25191)..

Thu Dec 24 14:38:00 2015 - [debug]   ok.

Thu Dec 24 14:38:00 2015 - [debug]

Thu Dec 24 14:38:00 2015 - [debug]  Connecting via SSH from root@slave1(192.168.110.129:25191) to root@master(192.168.110.128:25191)..

Thu Dec 24 14:38:00 2015 - [debug]   ok.

Thu Dec 24 14:38:00 2015 - [debug]  Connecting via SSH from root@slave1(192.168.110.129:25191) to root@slave2(192.168.110.130:25191)..

Thu Dec 24 14:38:00 2015 - [debug]   ok.

Thu Dec 24 14:38:01 2015 - [debug]

Thu Dec 24 14:38:00 2015 - [debug]  Connecting via SSH from root@slave2(192.168.110.130:25191) to root@master(192.168.110.128:25191)..

Thu Dec 24 14:38:00 2015 - [debug]   ok.

Thu Dec 24 14:38:00 2015 - [debug]  Connecting via SSH from root@slave2(192.168.110.130:25191) to root@slave1(192.168.110.129:25191)..

Thu Dec 24 14:38:01 2015 - [debug]   ok.

Thu Dec 24 14:38:01 2015 - [info] All SSH connection tests passed successfully.

 

8,检测mysql 复制是否正常

Thu Dec 24 14:39:43 2015 - [info] Checking replication health on slave1..

Thu Dec 24 14:39:43 2015 - [info]  ok.

Thu Dec 24 14:39:43 2015 - [info] Checking replication health on slave2..

Thu Dec 24 14:39:43 2015 - [info]  ok.

Thu Dec 24 14:39:43 2015 - [warning] master_ip_failover_script is not defined.

Thu Dec 24 14:39:43 2015 - [warning] shutdown_script is not defined.

Thu Dec 24 14:39:43 2015 - [info] Got exit code 0 (Not master dead).

 

MySQL Replication Health is OK.

[root@localhost ~]# masterha_check_repl --conf=/etc/mha/app1.cnf

 

 

9,启动监控并检测结果

1,启动监控

nohup masterha_manager --conf=/etc/mha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/mha/app1/manager.log 2>&1 &

2,检测状态是否正常

[root@localhost ~]# masterha_check_status --conf=/etc/mha/app1.cnf

app1 (pid:17595) is running(0:PING_OK), master:master

3 停止master mysql

4,查看slave1slave2上状态

Slave1上状态:

mysql> show slave status\G;

Empty set (0.00 sec)

 

ERROR:

No query specified

Slave2上状态:主已经变成slave1-192.168.110.129

mysql> show slave status\G;

*************************** 1. row ***************************

               Slave_IO_State: Waiting for master to send event

                  Master_Host: 192.168.110.129

                  Master_User: backup

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: mysql-bin.000012

          Read_Master_Log_Pos: 367

               Relay_Log_File: mysql-relay-bin.000002

                Relay_Log_Pos: 314

        Relay_Master_Log_File: mysql-bin.000012

             Slave_IO_Running: Yes

            Slave_SQL_Running: Yes

              Replicate_Do_DB:

5,启动master,现在让作为slave 来运行,则需要修改app1.conf文件

加入

[server1]

candidate_master=1

check_repl_delay=0

hostname=master

port=3306

 

master上需要配置主从,将master指向slave1

change master to master_host='192.168.110.129',master_user='backup',master_password='123qwe',master_auto_position=1;

start slave;

 

 

并重新启用监控

[root@localhost ~]# nohup masterha_manager --conf=/etc/mha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/mha/app1/manager.log 2>&1 &

[1] 18573

[root@localhost ~]#

[root@localhost ~]#

[root@localhost ~]#

[root@localhost ~]# tail -f /var/log/mha/app1/manager.log

slave1 (current master)

 +--master

 +--slave2

 

Thu Dec 24 14:50:20 2015 - [warning] master_ip_failover_script is not defined.

Thu Dec 24 14:50:20 2015 - [warning] shutdown_script is not defined.

Thu Dec 24 14:50:20 2015 - [info] Set master ping interval 2 seconds.

Thu Dec 24 14:50:20 2015 - [warning] secondary_check_script is not defined. It is highly recommended setting it to check master reachability from two or more routes.

Thu Dec 24 14:50:20 2015 - [info] Starting ping health check on slave1(192.168.110.129:3306)..

Thu Dec 24 14:50:20 2015 - [info] Ping(SELECT) succeeded, waiting until MySQL doesn't respond..

查看状态:

[root@localhost ~]# masterha_check_status --conf=/etc/mha/app1.cnf

app1 (pid:18573) is running(0:PING_OK), master:slave1

© 著作权归作者所有

b
粉丝 0
博文 1
码字总数 1265
作品 0
深圳
私信 提问
Mysql-MHA高可用实验测试

说明: centos 6.5 mysql 5.5.37 mha4mysql-manager-0.55 mha4mysql-node-0.54 manager 192.168.1.1 mha-manager管理端 db1 192.168.1.2 现有主库 db2 192.168.1.3 即将做双主的数据库 db3 ......

bbotte
2015/01/08
0
0
浅谈秒级故障切换!用MHA轻松实现MySQL高可用(一)

MHA简介 MHA是由日本人youshimaton(原就职于DeNA,现就职于FaceBook)开发的比较成熟的MySQL高可用方案。MHA能够在30秒内实现故障切换,并能在故障切换中,最大可能的保证数据一致性。目前淘...

凛冬一壶酒
2018/06/26
0
0
mysql高可用MHA部署全过程

部署计划 本次部署采用3台服务器,mha-manager不单独使用一台服务器安装,生产上可以单独出来,本次使用采用centos6.9系统(使用 http://youprince.blog.51cto.com/9272426/1974967 优化 ),...

ImPoorWretch
2017/11/03
0
0
MySQL高可用之MHA—MHA介绍

MHA简介 MHA是由日本人yoshinorim(原就职于DeNA现就职于FaceBook)开发的比较成熟的MySQL高可用方案。MHA能够在30秒内实现故障切换,并能在故障切换中,最大可能的保证数据一致性。目前淘宝...

844365389
2018/06/27
0
0
Step By Step 搭建 MySql MHA 集群

关于MHA    MHA(Master High Availability)是一款开源的mysql高可用程序,目前在mysql高可用方面是一个相对成熟的解决方案。MHA 搭建的前提是MySQL集群中已经搭建了MySql Replication环境...

Eumenides_s
2018/01/14
0
0

没有更多内容

加载失败,请刷新页面

加载更多

二进制位操作

单片机,或者一些模块的设置操作,都是由一个字节数据来完成,每位各有定义。就需进行位操作来组合需要的数字结果。 以JavaScript为例,编写位操作。 我们期望得到这样一个二进制数:0101101...

format
15分钟前
2
0
聊聊中国的通信行业:从“七国八制”到“中华”脊梁

本期文章和大家一起来聊一聊我曾经从事过的通信行业吧。最近各方面信息的泛滥,包括和华为的同学聊天,自己确实也感慨颇多。想想我自己本科主修通信工程,研究生再修信息与通信工程,从本科开...

CodeSheep
今天
5
0
MDK:ARM M451M:exceed the range of code meory, continue to erase or not?

问题: 代码空间超限 几天前就遇到:exceed the range of code meory, continue to erase or not? 如下所示: 解决过程 开始以为中MDK软件的128KB限制,如是就不能生成HEX文件,应该链接时有提...

SamXIAO
今天
1
1
OSChina 周六乱弹 —— 因违反《中华人民共和国治安管理处罚法》第四十四条之规定

Osc乱弹歌单(2019)请戳(这里) 【今日歌曲】 @xiaoshiyue :#今日歌曲推荐# 惊艳分享谷微的单曲《安守本份》(@网易云音乐) 《安守本份》- 谷微 手机党少年们想听歌,请使劲儿戳(这里) ...

小小编辑
今天
456
10
Angular 英雄编辑器

应用程序现在有了基本的标题。 接下来你要创建一个新的组件来显示英雄信息并且把这个组件放到应用程序的外壳里去。 创建英雄组件 使用 Angular CLI 创建一个名为 heroes 的新组件。 ng gener...

honeymoose
今天
8
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部