MySQL MHA 典型使用场景

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 1      管理节点部署位置1.1.       Dedicated Manager server and multiple MySQL (master,slaves) servers 使用专用的管理服务器管理多组MySQL主从服务器Sin...

1      管理节点部署位置

1.1.       Dedicated Manager server and multiple MySQL (master,slaves) servers

使用专用的管理服务器管理多组MySQL主从服务器

Since MHA Manager uses very little CPU/Memory resources, you can manage lots of (master, slaves) pairs from single MHA Manager. It is even possible to manage 100+ pairs from single manager server.

 

1.2.       Running MHA Manager on one of MySQL slaves

在一个从库上部署管理节点

If you have only one (master, slaves) pair, you may not like allocating dedicated hardware for MHA Manager because it adds relatively high costs. In such cases, running MHA Manager on one of slaves makes sense. Note that current version of MHA Manager connects to MySQL slave server via SSH even though the MySQL server is located on the same host as MHA Manager, so you need to enable SSH public key authentication from the same host.

2      不同主从配置下的主从切换场景

2.1         Single master, multiple slaves(单主多从)

        M(RW)                            M(RW), promoted from S1
         |                                             |
  +------+------+        --(master crash)-->     +-----+-----+
 S1(R) S2(R)   S3(R)                           S2(R)        S3(R)
 

This is the most common replication settings. MHA works very well here.

 

2.2         Single master, multiple slaves (one on remote datacenter) 单主多从,一个从位于远程数据中心

        M(RW)                                M(RW), promoted from S1
         |                                                 |
  +------+---------+         --(master crash)-->     +-----+------+
 S1(R) S2(R)     Sr(R,no_master=1)                   S2(R)         Sr(R,no_master=1)
 

In many cases you want to deploy at least one slave server on a remote datacenter. When the master crashes, you may not want to promote the remote slave to the new master, but let one of other slaves running on the local datacenter become the new master. MHA supports such requirements. Setting no_master=1 in the configuration file makes the slave never becomes new master.

 

2.3         Single master, multiple slaves, one candidate master(单主多从,一个候选主)

      M(RW)-----S0(R,candidate_master=1)   M(RW), promoted from S0
       |                                          |
  +----+----+          --(master crash)-->   +----+----+
 S1(R)     S2(R)                             S1(R)      S2(R)
 

In some cases you may want to promote a specific server to the new master if the current master crashes. In such cases, setting candidate_master=1 in the configuration file will help.

 

2.4         Multiple masters, multiple slaves(多主多从)

      M(RW)<--->M2(R,candidate_master=1)   M(RW), promoted from M2
       |                                          |
  +----+----+          --(master crash)-->   +----+----+
 S(R)     S2(R)                             S1(R)      S2(R)
 

In some cases you may want to use multi-master configurations, and you may want to make the read-only master the new master if the current master crashes. MHA Manager supports multi-master configurations as long as all non-primary masters (M2 in this figure) are read-only.

 

2.5         Three tier replication(三层复制架构)

        M(RW)                                   M(RW), promoted from S1
         |                                                 |
  +------+---------+         --(master crash)-->     +-----+------+
 S1(R) S2(R)     Sr(R)                              S2(R)       Sr(R)
                   |                                              |
                   +                                              +
                  Sr2                                            Sr2
 

In some cases you may want to use three-tier replication like this. MHA can still be used for master failover. In the configuration file, manage the master and all second-tier slaves (in this figure, add M,S1,S2 and Sr in the MHA config file, but do not add Sr2). If the current master (M) fails, MHA automatically promotes one of the second-tier slaves(S1,S2,Sr, and you can also set priorities) to the new master, and recover the rest second-tier slaves. The third tier slave(Sr2) is not managed by MHA, but as long as Sr (Sr2's master) is alive, Sr2 can continue replication without changing anything.

If Sr crashes, Sr2 can't continue replication because Sr2's master is Sr. MHA can NOT be used to recover Sr2. This is where support for global transaction id is desired. Hopefully this is less serious than master crash.

 

2.6         Three tier replication, multi-master(三层复制架构,多主)

   M1(host1,RW) <-----------------> M2(host2,read-only)
        |                                |
  +-----+--------+                       +
 S1(host3,R)    S2(host4,R)             S3(host5,R)
 

=> After failover

 

          M2(host2,RW)

                 |

  +--------------+--------------------------+

 S1(host3,R)    S2(host4,R)             S3(host5,R)

 

This structure is also supported. In this case, host5 is a third-tier slave, so MHA does not manage host5(MHA does not execute CHANGE MASTER on host5 when the primary master host1 fails). When current master host1 is down, host2 will be new master, so host5 can keep replication from host2 without doing anything. Here are configuration file example.

[server default]
multi_tier_slave=1

[server1]
hostname=host1
candidate_master=1

[server2]
hostname=host2
candidate_master=1

[server3]
hostname=host3

[server4]
hostname=host4

[server5]
hostname=host5

 

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
7月前
|
存储 关系型数据库 MySQL
使用 MHA 和 HAProxy 部署高可用 MySQL
使用 MHA 和 HAProxy 部署高可用 MySQL
|
4月前
|
监控 关系型数据库 MySQL
MySQL高可用MHA
MySQL高可用管理工具(MHA,Master High Availability)是一个用于自动管理MySQL主从复制的工具,它可以提供高可用性和自动故障转移。MHA由原版的MHA工具和MHA Manager组成,它们协同工作以实现自动主从切换和监控。
136 0
|
2月前
|
SQL 关系型数据库 MySQL
MySQL日期函数的SQL代码示例和使用场景
MySQL日期函数的SQL代码示例和使用场景
25 0
|
6月前
|
算法 关系型数据库 MySQL
MySQL 的索引类型及使用场景
MySQL支持多种类型的索引,每种索引类型都有不同的使用场景。下面是一些常见的索引类型及其适用场景: 1. B-树索引:B-树索引是MySQL的默认索引类型。它适用于经常需要范围查询的列,例如日期范围查询、区间查询等。B-树索引也适用于针对大型表进行排序和分组查询。 2. 唯一索引:唯一索引确保索引列中的值是唯一的。它适用于要求索引列的值不重复的场景。 3. 主键索引:主键索引是唯一索引的一种特殊类型。它用于定义表的主键,并且主键值不能为NULL。主键索引可以帮助快速查找表中的唯一行。 4. 全文索引:全文索引用于全文搜索场景,支持对文本数据进行全文搜索和相关性排序。它适用于需要执行全
130 0
|
7月前
|
监控 关系型数据库 MySQL
MySQL高可用搭建方案之(MHA)(下)
MySQL高可用搭建方案之(MHA)(下)
|
7月前
|
监控 前端开发 关系型数据库
MySQL高可用搭建方案之(MHA)(上)
MySQL高可用搭建方案之(MHA)
|
8月前
|
NoSQL 关系型数据库 MySQL
云计算--Docker典型命令Docker run部署nginx\mysql\redis
云计算–Docker典型命令Docker run部署nginx\mysql\redis 上两章节分别介绍了Docker在Centos和Ubuntu上的安装方法,这次我们就来介绍一下docker常用命令之一的docker run,并且部署常用应用mysql、redis、nginx作为docker run的示例。
143 0
|
8月前
|
存储 关系型数据库 MySQL
MySQL四种常用的索引类型以及使用场景
MySQL四种常用的索引类型以及使用场景
214 0
|
9月前
|
SQL 关系型数据库 MySQL
项目实战典型案例2——sql优化 mysql执行顺序 explain关键字进行性能分析
项目实战典型案例2——sql优化 mysql执行顺序 explain关键字进行性能分析
183 0
|
9月前
|
SQL 关系型数据库 MySQL
Shardingsphere结合ES、Mysql MHA、Logstash实现全家桶
Shardingsphere结合ES、Mysql MHA、Logstash实现全家桶
433 0