mysql MMM高可用方案

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

mysql  MMM高可用方案

 MMM简介:

MMMMaster-Master Replication Manager for MySQLmysql主主复制管理器)关于mysql主主复制配置的监控、故障转移和管理的一套可伸缩的脚本套件(在任何时候只有一个节点可以被写入),这个套件也能对居于标准的主从配置的任意数量的从服务器进行读负载均衡,所以你可以用它来在一组居于复制的服务器启动虚拟ip,除此之外,它还有实现数据备份、节点之间重新同步功能的脚本。

MySQL本身没有提供replication failover的解决方案,通过MMM方案能实现服务器的故障转移,从而实现mysql的高可用。

环境配置

MMM_monitor:172.19.0.122

MySQL_master1:172.19.0.121 (db1)

MySQL_master2:172.19.0.122(db2)

MySQL_slave1:172.19.123(db3)

VIP_Write:172.19.0.126

vip_Read1:172.19.0.127, 172.19.0.128

 

三台服务安装好mysql,把db1db2做成主主同步,db3为从,是同步db1的。后面搭建好mmm后,当DB1的脱机后,db3会自动change同步db2

1.设置hosts解析

三台服务的配置如下

[root@db1 ~]# cat /etc/hosts

172.19.0.121 db1

172.19.0.122 db2

172.19.0.123 db3

 

创建三个账号。

(复制账号)

GRANT REPLICATION slave,REPLICATION CLIENT ON *.* TO 'repl'@'%' IDENTIFIED BY 'repl';

(代理账号)

GRANT PROCESS,SUPER,REPLICATION CLIENT ON *.* TO 'mmm_agent'@'%' IDENTIFIED BY '123456';

(监听账号)

GRANT REPLICATION CLIENT ON *.* TO 'mmm_monitor'@'%' IDENTIFIED BY '123456';

 

3.安装mysql-mmm

在三台服务上分别进行安装,安装命令如下:

#wget http://download.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

#rpm -ivh epel-release-5-4.noarch.rpm

#yum -y install mysql-mmm*

 

4.配置MMM监控、代理服务

在三台服务器修改mmm_common.conf配置文件

[root@db1 ~]# cd /etc/mysql-mmm/

[root@db1 mysql-mmm]# vi 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    repl

    agent_user              mmm_agent

    agent_password          123456

</host>

 

<host db1>

    ip      172.19.0.121

    mode    master

    peer    db2

</host>

 

<host db2>

    ip      172.19.0.122

    mode    master

    peer    db1

</host>

 

<host db3>

    ip      172.19.0.123

    mode    slave

</host>

 

<role writer>

    hosts   db1, db2

    ips     172.19.0.126

    mode    exclusive

</role>

<role reader>

    hosts   db1, db2, db3

    ips     172.19.0.127,172.19.0.128

    mode    balanced

</role>

 

其次,修改三台服务器mmm_agent.conf配置文件

[root@db1 mysql-mmm]# cat 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

 

[root@db2 mysql-mmm]# cat 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 db2

 

[root@db3 mysql-mmm]# cat 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 db3

 

最后修改172.19.0.122db2 mysql-mon服务配置mmm_mon.conf配置文件,把这台做为MMM_monitor

[root@db2 mysql-mmm]# cat mmm_mon.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

[root@db1 mysql-mmm]# cat 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            172.19.0.121,172.19.0.122,172.19.0.123

    auto_set_online     10

 

    # 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

 

这样,配置MMM监控,代理服务的工作就完成了

5.启动相关服务

在三台服务器启动以下服务

/etc/init.d/mysql-mmm-agent start

 

db2中启动mysql-mon监控服务

/etc/init.d/mysql-mmm-monitor  start

 

 

查看MMM状态信息

[root@db2 mysql-mmm]# mmm_control show

  db1(172.19.0.121) master/ONLINE. Roles: writer(172.19.0.126)

  db2(172.19.0.122) master/ONLINE. Roles: reader(172.19.0.127)

  db3(172.19.0.123) slave/ONLINE. Roles: reader(172.19.0.128)

 

[root@db2  mysql-mmm]# mmm_control checks all

db2  ping         [last change: 2014/08/22 16:57:07]  OK

db2  mysql        [last change: 2014/08/22 16:57:07]  OK

db2  rep_threads  [last change: 2014/08/22 16:57:07]  OK

db2  rep_backlog  [last change: 2014/08/22 16:57:07]  OK: Backlog is null

db3  ping         [last change: 2014/08/22 16:57:07]  OK

db3  mysql        [last change: 2014/08/22 17:11:48]  OK

db3  rep_threads  [last change: 2014/08/22 16:57:07]  OK

db3  rep_backlog  [last change: 2014/08/22 16:57:07]  OK: Backlog is null

db1  ping         [last change: 2014/08/22 16:57:07]  OK

db1  mysql        [last change: 2014/08/22 16:57:07]  OK

db1  rep_threads  [last change: 2014/08/22 16:57:07]  OK

db1  rep_backlog  [last change: 2014/08/22 16:57:07]  OK: Backlog is null

 

 

以上说明成功,为了数据一致性,我们采用半同步方案

 


本文转自 jxzhfei  51CTO博客,原文链接:http://blog.51cto.com/jxzhfei/1543409


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
2月前
|
存储 关系型数据库 MySQL
Mysql高可用|索引|事务 | 调优
Mysql高可用|索引|事务 | 调优
|
3月前
|
SQL 容灾 关系型数据库
rds容灾与高可用
rds容灾与高可用
28 4
|
3月前
|
关系型数据库 MySQL
电子好书发您分享《MySQL MGR 8.0高可用实战》
电子好书发您分享《MySQL MGR 8.0高可用实战》 电子好书发您分享《MySQL MGR 8.0高可用实战》
89 1
|
2月前
|
SQL 存储 关系型数据库
MySQL索引(二)索引优化方案有哪些
MySQL索引(二)索引优化方案有哪些
47 0
|
20天前
|
canal 消息中间件 关系型数据库
【分布式技术专题】「分布式技术架构」MySQL数据同步到Elasticsearch之N种方案解析,实现高效数据同步
【分布式技术专题】「分布式技术架构」MySQL数据同步到Elasticsearch之N种方案解析,实现高效数据同步
66 0
|
20天前
|
SQL 关系型数据库 MySQL
【MySQL技术之旅】(7)总结和盘点优化方案系列之常用SQL的优化
【MySQL技术之旅】(7)总结和盘点优化方案系列之常用SQL的优化
36 1
|
1月前
|
缓存 关系型数据库 MySQL
史上最全MySQL 大表优化方案(长文)
史上最全MySQL 大表优化方案(长文)
315 0
|
2月前
|
监控 容灾 关系型数据库
rds容灾与高可用
rds容灾与高可用
45 6
|
3月前
|
SQL 关系型数据库 MySQL
Mysql高可用,索引,事务与调优:提高数据库性能的关键技术
在当今互联网时代,高可用性、稳定性和性能是数据库的三大关键要素。本文将深入探讨Mysql高可用、索引、事务和调优等方面的技术,为读者提供实用的解决方案和经验。
24 0
|
3月前
|
监控 关系型数据库 MySQL
MySQL高可用与性能优化综述
MySQL作为一种常用的关系型数据库管理系统,高可用性、索引优化、事务处理和性能调优一直是开发人员和运维人员关注的重点。本文将从MySQL高可用性解决方案、索引设计与优化、事务处理最佳实践以及性能调优策略等方面进行探讨,为读者提供全面的MySQL技术知识概览。