一、Mysql MMM 高可用概况:

mmm_mond  负责所有的监控工作的监控守护进程,决定节点的移除等;

mmm_agentd  运行在mysql服务器上的代理守护进程,通过简单远程服务集提供给监控节点;

mmm_control  命令行管理mmm_mond进程;

Monitor:192.168.209.18

DB1:192.168.209.19

DB2:192.168.209.20

DB3:192.168.209.21

 

virtual write ip:192.168.209.4

virtual read ip:192.168.209.5

virtual read ip:192.168.209.6

 

数据库为:test1

数据库用户为:repl

replication_user        repl

agent_user              mmm_agent

monitor_user        mmm_monitor

架构:

DB1,DB2互为主从,DB3为DB1的从服务

此类架构,在DB1正常的时候,DB3是与DB1同步数据,在DB1的mysql服务不可用时,DB3将与DB2同步数据.

二、安装mysql ,参见:《以普通用户权限安装mysql》,http://www.cnblogs.com/krainbow/p/3894154.html

三、mysql主从配置及状态检查

安装好mysql之后,需要配置各服务之间的主从关系

3.1 编辑修改mysql配置文件my.cnf,如下:

Db1:

cat  /etc/my.cnf | grep -v "#"

[mysqld]

log_bin=mysql-bin

server-id=19

replicate-do-db = test1

auto-increment-increment = 3

auto-increment-offset = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

Db2:

[mysqld]

log_bin=mysql-bin

server-id=20

replicate-do-db = test1

auto-increment-increment = 3

auto-increment-offset = 2

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

Db3:

[mysqld]

log_bin=mysql-bin

server_id=21

replicate-do-db = test1

auto-increment-increment = 3

auto-increment-offset = 3

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

3.2 配置主从关系:

db1和db2配置成主主模式,db3配置为db1的从,用户为repl

在db1上执行:

grant replication slave on *.* to repl@'192.168.209.%' identified by "123456";

flush privileges;

db2上执行:

grant replication slave on *.* to repl@'192.168.209.%' identified by "123456";

flush privileges;

db3上执行:

grant replication slave on *.* to repl@'192.168.209.%' identified by "123456";

flush privileges;

配置db2和db3都与db1数据同步,在db2和db3上面执行:

change master to master_host='192.168.209.19', master_port=3306, master_user='repl', master_password='123456';

start slave;

配置db1为db2的从库,在db1上面执行:

change master to master_host='', master_port=3306, master_user='repl', master_password='123456';

start slave;

以上均为简略写法,只有关键部分,详细的授权和主从配置命令,需要根据实际情况进行修改。

3.3 在主从没有问题之后,需要检查三台db服务器的slave状态是否正确。

DB1

mysql> show slave status\G

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

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.209.20

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000010

Read_Master_Log_Pos: 444

Relay_Log_File: cdn19-relay-bin.000024

Relay_Log_Pos: 607

Relay_Master_Log_File: mysql-bin.000010

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB: test1

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 444

Relay_Log_Space: 780

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 0

Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id: 20

Master_UUID: 318ae305-235a-11e4-aeb7-c81f66ec516e

Master_Info_File: /mysql/mysql-5.6/data/master.info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp:

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position: 0

1 row in set (0.00 sec)

Db2

mysql> show slave status\G

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

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.209.19

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000012

Read_Master_Log_Pos: 120

Relay_Log_File: cdn20-relay-bin.000023

Relay_Log_Pos: 283

Relay_Master_Log_File: mysql-bin.000012

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB: test1

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 120

Relay_Log_Space: 619

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 0

Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id: 19

Master_UUID: 2f276e4a-235a-11e4-aeb7-b8ca3af2484f

Master_Info_File: /mysql/mysql-5.6/data/master.info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp:

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position: 0

1 row in set (0.00 sec)

Db3

mysql> show slave status\G

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

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.209.19

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000012

Read_Master_Log_Pos: 120

Relay_Log_File: cdn21-relay-bin.000002

Relay_Log_Pos: 283

Relay_Master_Log_File: mysql-bin.000012

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB: test1

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 120

Relay_Log_Space: 456

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 0

Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id: 19

Master_UUID: 2f276e4a-235a-11e4-aeb7-b8ca3af2484f

Master_Info_File: /mysql/mysql-5.6/data/master.info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp:

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position: 0

1 row in set (0.00 sec)

四、安装配置mysql-mmm软件

4.1 软件安装

monitor

yum install -y mysql-mmm*

all db

yum install -y mysql-mmm-agent*

4.2 数据库授权

all db

grant super, replication client, process on *.* to 'mmm_agent'@'192.168.209.%' identified by '123456';

grant replication client on *.* to 'mmm_monitor'@'192.168.209.%' identified by '123456';

flush privileges;

4.3 配置文件修改

all 服务器

四台服务器完全一致的配置

[root@cdn18 ~]# vi /etc/mysql-mmm/mmm_common.conf

active_master_role      writer

<host default>

cluster_interface       eth0

pid_path                /var/run/mysql-mmm/mmm_agentd.pid

bin_path                /usr/libexec/mysql-mmm/

replication_user        repl

replication_password    123456

agent_user              mmm_agent

agent_password          123456

</host>

<host db1>

ip      192.168.209.19

mode    master

peer    db2

</host>

<host db2>

ip      192.168.209.20

mode    master

peer    db1

</host>

<host db3>

ip      192.168.209.21

mode    slave

peer    db3

</host>

<role writer>

hosts   db1, db2

ips     192.168.209.4

mode    exclusive

</role>

<role reader>

hosts   db3

ips     192.168.209.5,192.168.209.6

mode    balanced

</role>

peer的表示等同,表示db1与db2同等。

ips指定VIP

mode有两种模式:exclusive排他,此模式下任何时候只能一个host拥有该角色

balanced模式可以有多个host同时拥有此角色。一般writer是exclusive,reader是balanced

修改每台db的agent配置,标注对应的数据库id

vim /etc/mysql-mmm/mmm_agent.conf

db1,db2,db3对应修改为:

this db1、this db2、this db3

形如:

[root@cdn19 ~]# cat /etc/mysql-mmm/mmm_agent.conf

include mmm_common.conf

# The 'this' variable refers to this server.  Proper operation requires

# that 'this' server (db1 by default), as well as all other servers, have the

# proper IP addresses set in mmm_common.conf.

this db1

修改monitor服务器配置

[root@cdn18 ~]# cat /etc/mysql-mmm/mmm_mon.conf

include mmm_common.conf

<monitor>

ip                  127.0.0.1

pid_path            /var/run/mysql-mmm/mmm_mond.pid

bin_path            /usr/libexec/mysql-mmm

status_path         /var/lib/mysql-mmm/mmm_mond.status

ping_ips            192.168.209.19,192.168.209.20

auto_set_online     60

# The kill_host_bin does not exist by default, though the monitor will

# throw a warning about it missing.  See the section 5.10 "Kill Host

# Functionality" in the PDF documentation.

#

# kill_host_bin     /usr/libexec/mysql-mmm/monitor/kill_host

#

</monitor>

<host default>

monitor_user        mmm_monitor

monitor_password    123456

</host>

debug 0

六、启动服务

6.1 启动agent服务

db服务器:/etc/init.d/mysql-mmm-agent restart

6.2 启动monitor服务

monitor服务器:/etc/init.d/mysql-mmm-monitor restart

6.3 状态检查

monitor服务器

[root@cdn18 ~]# mmm_control checks all

db2  ping         [last change: 2014/08/19 13:50:08]  OK

db2  mysql        [last change: 2014/08/19 13:51:36]  OK

db2  rep_threads  [last change: 2014/08/19 13:51:30]  OK

db2  rep_backlog  [last change: 2014/08/19 13:51:36]  OK: Backlog is null

db3  ping         [last change: 2014/08/19 13:50:08]  OK

db3  mysql        [last change: 2014/08/19 13:50:08]  OK

db3  rep_threads  [last change: 2014/08/19 13:50:08]  OK

db3  rep_backlog  [last change: 2014/08/19 13:50:08]  OK: Backlog is null

db1  ping         [last change: 2014/08/19 13:50:08]  OK

db1  mysql        [last change: 2014/08/19 13:50:08]  OK

db1  rep_threads  [last change: 2014/08/19 13:50:08]  OK

db1  rep_backlog  [last change: 2014/08/19 13:50:08]  OK: Backlog is null

[root@cdn18 ~]# mmm_control show

db1(192.168.209.19) master/ONLINE. Roles: writer(192.168.209.4)

db2(192.168.209.20) master/ONLINE. Roles:

db3(192.168.209.21) slave/ONLINE. Roles: reader(192.168.209.5), reader(192.168.209.6)

6.4 vip切换

停掉db1,看192.168.209.4是否会切换到192.168.209.20(db2)服务器,同时,192.168.209.21(db3)的mysql是否会将master服务器切换为192.168.209.20(db2)

登录db1

执行:service mysql stop

停止db1的mysql服务

在monitor服务器执行:

[root@cdn18 ~]# mmm_control show

db1(192.168.209.19) master/HARD_OFFLINE. Roles:

db2(192.168.209.20) master/ONLINE. Roles: writer(192.168.209.4)

db3(192.168.209.21) slave/ONLINE. Roles: reader(192.168.209.5), reader(192.168.209.6)

[root@cdn18 ~]# mmm_control checks all

db2  ping         [last change: 2014/08/19 13:50:08]  OK

db2  mysql        [last change: 2014/08/19 13:51:36]  OK

db2  rep_threads  [last change: 2014/08/19 13:51:30]  OK

db2  rep_backlog  [last change: 2014/08/19 13:51:36]  OK: Backlog is null

db3  ping         [last change: 2014/08/19 13:50:08]  OK

db3  mysql        [last change: 2014/08/19 13:50:08]  OK

db3  rep_threads  [last change: 2014/08/19 13:50:08]  OK

db3  rep_backlog  [last change: 2014/08/19 13:50:08]  OK: Backlog is null

db1  ping         [last change: 2014/08/19 13:50:08]  OK

db1  mysql        [last change: 2014/08/19 14:06:58]  ERROR: Connect error (host = 192.168.209.19:3306, user = mmm_monitor)! Lost connection to MySQL server at 'reading initial communication packet', system error: 111

db1  rep_threads  [last change: 2014/08/19 13:50:08]  OK

db1  rep_backlog  [last change: 2014/08/19 13:50:08]  OK: Backlog is null

在db3执行,可以发现master_host已经切换到db2了

mysql> show slave status\G

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

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.209.20

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000011

Read_Master_Log_Pos: 120

Relay_Log_File: cdn21-relay-bin.000002

Relay_Log_Pos: 283

Relay_Master_Log_File: mysql-bin.000011

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB: test1

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 120

Relay_Log_Space: 456

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 0

Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id: 20

Master_UUID: 318ae305-235a-11e4-aeb7-c81f66ec516e

Master_Info_File: /mysql/mysql-5.6/data/master.info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp:

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position: 0

1 row in set (0.00 sec)

Mysql MMM 高可用的更多相关文章

  1. 搭建MySQL MMM高可用

    搭建MMM: 1,安装 agent 节点执行 yum install -y mysql-mmm-agent 2, monitor 节点执行 yum install -y mysql-mmm-monit ...

  2. centos6.6部署mysql mmm高可用架构

    一.环境简述 1.工作逻辑图 2.MySQL-MMM优缺点 优点:高可用性,扩展性好,出现故障自动切换,对于主主同步,在同一时间只提供一台数据库写操作,保证的数据的一致性. 缺点:Monitor节点是 ...

  3. MySQL MMM高可用方案

    200 ? "200px" : this.width)!important;} --> 介绍 本篇文章主要介绍搭建MMM方案以及MMM架构的原理.这里不介绍主从.主主的搭建方 ...

  4. mysql mmm高可用架构设计

    项目概述:搭建主从,双主,安装Perl模块  安装配置mmm软件  测试 硬件环境:4台虚拟PC 软件环境:rehl6.5 MySQL-5.6.26 percona-xtrabackup-2.3.4 ...

  5. CentOS 搭建 Mysql MMM 高可用架构

    环境 CentOS Mysql 5.1 前提 安装了EPEL,详细安装步骤请參照 http://blog.csdn.net/robinsonmhj/article/details/36184863 机 ...

  6. mysql的MMM高可用方案

    1    MMM高可用mysql方案 1.1  方案简介 MMM即Master-Master Replication Manager for MySQL(mysql主主复制管理器)关于mysql主主复 ...

  7. mysql高可用探究 MMM高可用mysql方案

    1    MMM高可用mysql方案 1.1  方案简介 MMM即Master-Master Replication Manager for MySQL(mysql主主复制管理器)关于mysql主主复 ...

  8. 美团点评MySQL数据库高可用架构从MMM到MHA+Zebra以及MHA+Proxy的演进

    本文介绍最近几年美团点评MySQL数据库高可用架构的演进过程,以及我们在开源技术基础上做的一些创新.同时,也和业界其它方案进行综合对比,了解业界在高可用方面的进展,和未来我们的一些规划和展望. MMM ...

  9. 002.MMM高可用MySQL简介

    一 简介 MMM即Multi-Master Replication Manager for MySQL:mysql多主复制管理器,基于perl实现,关于mysql主主复制配置的监控.故障转移和管理的一 ...

随机推荐

  1. linux中MACHINE_START&END在9g10ek上实现

    在linux的板卡初始化文件中有machine的相关定义 //arch/arm/mach-at91/board-sam9261ek.c MACHINE_START(AT91SAM9G10EK, &qu ...

  2. Redis源代码分析(十七)--- multi事务操作

    redis作为一非关系型数据库,居然相同拥有与RDBMS的事务操作,不免让我认为比較吃惊.在redis就专门有文件就是运行事务的相关操作的.也能够让我们领略一下.在Redis的代码中是怎样实现事务操作 ...

  3. 申请edu邮箱

    https://blog.csdn.net/w305607610/article/details/86771593 手把手教你申请CCC(City Colleges of Chicago)教育邮箱 台 ...

  4. PHP 格式化数字串

    在xls或csv文件中, 超过12位以上的数字会被"科学计数", 所以当php读取这些文件的时候, 会读成 420E+16 , 显然这不是我们想要的, 所以就要用到数字格式化了! ...

  5. iOS 蓝牙开发之(mutipeerConnectivity)

    蓝牙 mutipeerConnectivity iOS7 引入的一个全新框架 替代GameKit框架 多用于文件传输 iOS设备不联网也能给附近的人聊天 搜索和传输的方式 * 双方WIFI和蓝牙都没有 ...

  6. 认识影片版本(CAM、TS、TC、DVD、HD、BD、TVRIP等)

    许多朋友在下载电影的时候, 往往会被各种各样的版本标识弄糊涂,今天把各种版本的缩写收集在一起,希望对大家有所帮助 . 引用: 1.CAM(枪版)    CAM 通常是用数码摄像机从电影院盗录.有时会使 ...

  7. 利用socket.io实现多人聊天室(基于Nodejs)

    socket.io简单介绍 在Html5中存在着这种一个新特性.引入了websocket,关于websocket的内部实现原理能够看这篇文章.这篇文章讲述了websocket无到有,依据协议,分析数据 ...

  8. python cookbook第三版学习笔记六:迭代器与生成器

    假如我们有一个列表 items=[1,2,3].我们要遍历这个列表我们会用下面的方式 For i in items:   Print i 首先介绍几个概念:容器,可迭代对象,迭代器 容器是一种存储数据 ...

  9. win7下搭建nginx+php的开发环境(转)

    在win7下用的是IIS做web服务器,但近来因项目需求的原因,需要在服务器遇到404错误的时候自动做转向(不是在客户端的跳转,而是在服务器收到客户端请求去某目录下读取文件返回时,如果发现目录或目录下 ...

  10. SD相关的表

    [转] 一.客户主数据基本数据放在KNA1里:公司代码放在KNB1里:销售视图放在KNVV里:合作伙伴放在KNVP里:二.信用主数据KNKK里有信贷限额.应收总额.特别往来:S066里是未清订单值:S ...