背景
腾讯混沌演练平台提供模拟云数据库 MySQL 主节点故障的场景故障动作,您可以使用该故障动作来验证您的业务 MySQL 灾备能力及整体高可用能力。
注意:
故障描述
该故障会向实例注入致命错误,来模拟多节点架构实例主节点故障。在故障动作执行期间会出现短暂数据库连接断开或者无法连接状况,进而造成数据库无法访问,请谨慎操作!故障注入后,MySQL 实例会进行主从切换,原从节点会成为新主节点,并会在原主可用区拉起新节点作为新备节点。
演练实施
步骤一:演练准备
一台 云数据库 MySQL 实例,双节点架构(主节点:广州七区;备节点:广州六区)。
一台 CVM 实例,用于测试连接 MySQL 实例。
步骤二:演练编排
1. 登录 混沌演练控制台,进入演练管理页面,单击新建演练。
2. 单击左下角跳过,新建空白演练。![](https://qcloudimg.tencent-cloud.cn/image/document/8de75fb1cea34ef736311d827af3289c.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/8de75fb1cea34ef736311d827af3289c.png)
3. 填写演练信息, 选择演练目标云数据库 MySQL 实例。![](https://qcloudimg.tencent-cloud.cn/image/document/bb0773429ebb9ba62122f843f7009b79.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/bb0773429ebb9ba62122f843f7009b79.png)
4. 添加 CDB 主节点故障演练动作。单击下一步。![](https://qcloudimg.tencent-cloud.cn/image/document/754e3c3428d8b9c7c6206d887aec9a28.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/754e3c3428d8b9c7c6206d887aec9a28.png)
5. 为故障动作配置动作参数信息,并单击确定。![](https://qcloudimg.tencent-cloud.cn/image/document/f2909c04108b558708596665c3c6e374.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/f2909c04108b558708596665c3c6e374.png)
6. 动作参数配置完成后,单击下一步。确定所有配置之后,单击提交,完成演练创建。![](https://qcloudimg.tencent-cloud.cn/image/document/d16a2b211d8eb856d8f72d078bc988c7.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/d16a2b211d8eb856d8f72d078bc988c7.png)
步骤三:执行演练
故障前:![](https://qcloudimg.tencent-cloud.cn/image/document/4bd27b2b6a3532f692a125307e94c058.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/4bd27b2b6a3532f692a125307e94c058.png)
MySQL 实例在故障前,主节点在广州7区,备节点在广州6区。使用 CVM 实例登录当前 MySQL 实例,建立一个客户端连接。
![](https://qcloudimg.tencent-cloud.cn/image/document/e572a5c7d06a4c671f1250ce6124a04f.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/e572a5c7d06a4c671f1250ce6124a04f.png)
执行演练:
进入演练详情,单击执行,开始执行演练。
![](https://qcloudimg.tencent-cloud.cn/image/document/d774039d4d25c070b5dc4543332333d9.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/d774039d4d25c070b5dc4543332333d9.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/c213e1cdcf6bfa0fa1f49205b3b98e21.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/c213e1cdcf6bfa0fa1f49205b3b98e21.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/eb0d270766d11cf9023403756967c030.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/eb0d270766d11cf9023403756967c030.png)
故障执行成功之后,可在 云数据库 MySQL 控制台 看到如下变化。故障后6区备节点被提为主节点,并在7区重新拉起了一个新节点作为备节点;并且右上角可收到异常告警(数据来自 数据库智能管家 DBbrain 巡检)。
![](https://qcloudimg.tencent-cloud.cn/image/document/08d294e1f5ee88d8aa434697873770e1.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/08d294e1f5ee88d8aa434697873770e1.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/3ac779079193101add9e8eb264f7e965.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/3ac779079193101add9e8eb264f7e965.png)
故障后实例监控
MySQL 主节点故障后,可以通过实例监控面板观测到主节点故障时,实例在11:05:45~11:06:15期间,当前实例将会出现短暂不可用。
![](https://qcloudimg.tencent-cloud.cn/image/document/07b2cc9900588712afbcefbc34ebdc63.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/07b2cc9900588712afbcefbc34ebdc63.png)
在此期间使用 CVM 执行 sql, 原连接已经断开,需要重连。
![](https://qcloudimg.tencent-cloud.cn/image/document/ec0e2e0ae52bba726cfe29b290095308.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/ec0e2e0ae52bba726cfe29b290095308.png)
同时 DBbrain 会话监控原连接已经不存在,新连接出现。
![](https://qcloudimg.tencent-cloud.cn/image/document/941edb92522420162eafab76f639c805.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/941edb92522420162eafab76f639c805.png)