Mysql MMM 高可用
一、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 高可用的更多相关文章
- 搭建MySQL MMM高可用
搭建MMM: 1,安装 agent 节点执行 yum install -y mysql-mmm-agent 2, monitor 节点执行 yum install -y mysql-mmm-monit ...
- centos6.6部署mysql mmm高可用架构
一.环境简述 1.工作逻辑图 2.MySQL-MMM优缺点 优点:高可用性,扩展性好,出现故障自动切换,对于主主同步,在同一时间只提供一台数据库写操作,保证的数据的一致性. 缺点:Monitor节点是 ...
- MySQL MMM高可用方案
200 ? "200px" : this.width)!important;} --> 介绍 本篇文章主要介绍搭建MMM方案以及MMM架构的原理.这里不介绍主从.主主的搭建方 ...
- mysql mmm高可用架构设计
项目概述:搭建主从,双主,安装Perl模块 安装配置mmm软件 测试 硬件环境:4台虚拟PC 软件环境:rehl6.5 MySQL-5.6.26 percona-xtrabackup-2.3.4 ...
- CentOS 搭建 Mysql MMM 高可用架构
环境 CentOS Mysql 5.1 前提 安装了EPEL,详细安装步骤请參照 http://blog.csdn.net/robinsonmhj/article/details/36184863 机 ...
- mysql的MMM高可用方案
1 MMM高可用mysql方案 1.1 方案简介 MMM即Master-Master Replication Manager for MySQL(mysql主主复制管理器)关于mysql主主复 ...
- mysql高可用探究 MMM高可用mysql方案
1 MMM高可用mysql方案 1.1 方案简介 MMM即Master-Master Replication Manager for MySQL(mysql主主复制管理器)关于mysql主主复 ...
- 美团点评MySQL数据库高可用架构从MMM到MHA+Zebra以及MHA+Proxy的演进
本文介绍最近几年美团点评MySQL数据库高可用架构的演进过程,以及我们在开源技术基础上做的一些创新.同时,也和业界其它方案进行综合对比,了解业界在高可用方面的进展,和未来我们的一些规划和展望. MMM ...
- 002.MMM高可用MySQL简介
一 简介 MMM即Multi-Master Replication Manager for MySQL:mysql多主复制管理器,基于perl实现,关于mysql主主复制配置的监控.故障转移和管理的一 ...
随机推荐
- js获取和设置属性的方法
function square(num){ var total = num*num;//局部变量 return total;}var total = 50;//全局变量var number ...
- 4.锁--并行编程之条件变量(posix condition variables)
在整理Java LockSupport.park()的东东.看到了个"Spurious wakeup".又一次梳理下. 首先来个<UNIX环境高级编程>里的样例: [c ...
- PowerBuilder -- 指定重复的列不显示
- os引导程序boot 在根目录区寻找os加载程序文件loader 对应的根目录条目
[0]README 0.0) source code from orange's implemention of a os and for complete code , please visit h ...
- HDU 5343 MZL's Circle Zhou 后缀自动机+DP
MZL's Circle Zhou Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- loadrunner动态从mysql取值 [需要下载跟数据库服务器一致的dll,32位或64位]
loadrunner中有参数化从数据库中取值,但是只是静态的,对于一些要实时取值的数据就game over了,比如取短信验证码,因为MySQL中有一个libmysql.dll,里面提供了可以操作数据库 ...
- 【题解】[CJOI2019Chebnear]
[题解][CJOI2019Chebnear] 题目描述 给定平面上有\(n\)个仇人,\((x,y) ,x,y \in R^+\) ,\(n\)个人都是仇人关系,而有仇人关系的一对人的切比雪夫距离若\ ...
- linux怎么设置vsftp用户访问目录权限
1.在指定的目录创建文件夹(访问的目录): mkdir picture 2.创建一个用户组(zdhgroup): groupadd zdhgroup 3.创建一个用户并指定路径和组: useradd ...
- WordPress用户角色及其权限管理编辑插件:User Role Editor汉化版
如果Wordpress默认的用户角色及权限不能满足您的需求,又觉得修改代码编辑用户权限太麻烦.那不妨试试User Role Editor,Wordpress用户角色及其权限管理编辑插件. User R ...
- PHP中的排序函数sort、asort、rsort、krsort、ksort区别分析(转)
sort() 函数用于对数组单元从低到高进行排序. rsort() 函数用于对数组单元从高到低进行排序. asort() 函数用于对数组单元从低到高进行排序并保持索引关系. arsort() 函数用于 ...