探索MySQL-Cluster奥秘系列之SQL节点故障测试(10)

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
云数据库 RDS MySQL,高可用系列 2核4GB
简介: 在这一小节中,我继续来对MySQL-Cluster集群环境的高可用性进行测试,接下来我们来看下当SQL节点出现故障时,MySQL-Cluster集群环境是如何保障其高可用性的。

在第一小节中我们讲到了,MySQL Cluster 集群环境下的 SQL 节点负责接收和解析应用端发来的 SQL 命令,然后再将解析后的命令传送至数据节点进行数据的过滤和查询,最后再由 SQL 节点将需要的数据反馈至应用端。

网络异常,图片无法展示
|

那么,如果当某一个SQL节点出现故障,例如 mysqld 进程意外中止,或者服务器出现了宕机,这时MySQL Cluster 集群是否仍可以提供应用端的正常读写呢?这一小节,我们就来对“某个 SQL 节点出现单点故障是否会对 MySQL Cluster 整体的读写造成影响”这个问题进行简单的测试。

我们先检测一下两个SQL节点(mysql04、mysql05)的运行状态。在管理节点上查看每个节点的运行状态,看到每个节点的状态均是正常的。

ndb_mgm> show;
Cluster Configuration
[ndbd(NDB)] 2 node(s)
id=2 @192.168.1.6 (mysql-5.7.36 ndb-7.6.20, Nodegroup: 0, *)
id=3 @192.168.1.7 (mysql-5.7.36 ndb-7.6.20, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.1.3 (mysql-5.7.36 ndb-7.6.20)
[mysqld(API)] 2 node(s)
id=4 @192.168.1.4 (mysql-5.7.36 ndb-7.6.20)
id=5 @192.168.1.5 (mysql-5.7.36 ndb-7.6.20)

然后进行一个简单的测试。

mysql04 节点:

[mysql@mysql04 ~]$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.36-ndb-7.6.20-cluster-gpl MySQL Cluster Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use testdb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from t2;
+------+------+
| id   | name |
+------+------+
|    1 | a    |
|    2 | bbb  |
+------+------+
2 rows in set (0.00 sec)

mysql05 节点:

[mysql@mysql05 ~]$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.36-ndb-7.6.20-cluster-gpl MySQL Cluster Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use testdb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from t2;
+------+------+
| id   | name |
+------+------+
|    1 | a    |
|    2 | bbb  |
+------+------+
2 rows in set (0.00 sec)

可以看到,两个 SQL 节点均运行正常,这时我们对 mysql04 节点上的 mysqld 进行 kill 操作,来进行故障的模拟。

[mysql@mysql04 ~]$ ps -ef | grep mysqld
mysql      5759   5738  0 09:05 pts/2    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf
mysql      5955   5759  3 09:05 pts/2    00:02:57 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/mysql/mydata --plugin-dir=/usr/local/mysql/lib/plugin --log-error=mysql04.err --pid-file=mysql04.pid --socket=/mysql/mydata/mysql.sock --port=3306
mysql      6135   5738  0 10:27 pts/2    00:00:00 grep --color=auto mysqld
[mysql@mysql04 ~]$ kill -9 5759 5955
[mysql@mysql04 ~]$ 
[1]+  Killed                  /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf
[mysql@mysql04 ~]$ 
[mysql@mysql04 ~]$ ps -ef | grep mysqld
mysql      6137   5738  0 10:27 pts/2    00:00:00 grep --color=auto mysqld

可以看到,当前在 mysql04 节点上已经不存在 mysqld 进程了,同时通过 mysql04 节点已经无法连接到 MySQL Cluster 集群环境中。

[mysql@mysql04 ~]$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/mysql/mydata/mysql.sock' (111)

接下来,我们在管理节点上确认一下 mysql04 节点的运行状态。

ndb_mgm> show;
Cluster Configuration
[ndbd(NDB)] 2 node(s)
id=2 @192.168.1.6 (mysql-5.7.36 ndb-7.6.20, Nodegroup: 0, *)
id=3 @192.168.1.7 (mysql-5.7.36 ndb-7.6.20, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.1.3 (mysql-5.7.36 ndb-7.6.20)
[mysqld(API)] 2 node(s)
id=4 (not connected, accepting connect from 192.168.1.4)
id=5 @192.168.1.5 (mysql-5.7.36 ndb-7.6.20)

可以看到,当前 mysql04 节点处于 not connected 状态,即 mysql04 是与 MySQL Cluster 集群环境处于连接中断的状态。

然后,我们在 mysql05 节点上测试是否可以连接到 MySQL Cluster 集群环境,同时是否可以在 mysql05 节点上进行数据的读写操作。如下所示:

[mysql@mysql05 ~]$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.36-ndb-7.6.20-cluster-gpl MySQL Cluster Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use testdb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from t2;
+------+------+
| id   | name |
+------+------+
|    1 | a    |
|    2 | bbb  |
+------+------+
2 rows in set (0.00 sec)
mysql> update t2 set name='aaaaa' where id=1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> select * from t2;
+------+-------+
| id   | name  |
+------+-------+
|    1 | aaaaa |
|    2 | bbb   |
+------+-------+
2 rows in set (0.00 sec)

我们发现,通过 mysql05 节点可以正常连接到 MySQL Cluster 集群环境中,同时也可以对数据进行正常读写,mysql04节点的故障并不影响mysql05节点的运行

那么此时,我们修复 mysql04 节点上的故障,启动 mysql04 节点上的 mysqld 进程。

[mysql@mysql04 ~]$ /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
[1] 6140
[mysql@mysql04 ~]$ 2022-03-10T02:35:08.658547Z mysqld_safe Logging to '/mysql/mydata/mysql04.err'.
2022-03-10T02:35:08.683992Z mysqld_safe Starting mysqld daemon with databases from /mysql/mydata

之后,在管理节点上查看其状态。

ndb_mgm> show;
Cluster Configuration
[ndbd(NDB)] 2 node(s)
id=2 @192.168.1.6 (mysql-5.7.36 ndb-7.6.20, Nodegroup: 0, *)
id=3 @192.168.1.7 (mysql-5.7.36 ndb-7.6.20, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.1.3 (mysql-5.7.36 ndb-7.6.20)
[mysqld(API)] 2 node(s)
id=4 @192.168.1.4 (mysql-5.7.36 ndb-7.6.20)
id=5 @192.168.1.5 (mysql-5.7.36 ndb-7.6.20)

这个时候,mysql04 节点上的服务也恢复正常了,然后通过 mysql04 连接到 MySQL Cluster 集群环境,测试是否可以读取到最新的数据信息,即读取到 t2 表中 id=1 的 name 字段是否为 aaaaa。如下所示:

[mysql@mysql04 ~]$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.36-ndb-7.6.20-cluster-gpl MySQL Cluster Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use testdb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from t2;
+------+-------+
| id   | name  |
+------+-------+
|    1 | aaaaa |
|    2 | bbb   |
+------+-------+
2 rows in set (0.00 sec)

可以看到,在对 mysql04 节点故障恢复后,仍然是可以读取到最新数据的。即单个SQL节点的故障其实并不会影响到整个MySQL Cluster集群环境的可用性

当某个 SQL 节点出现故障后,只需要把应用端的连接指向可用的 SQL 节点即可。这也就是为什么在工作中的 MySQL Cluster 环境往往需要在数据库的前端配备一个负载均衡器,当某一个 SQL 节点出现故障时,应用端的请求在通过负载均衡器时,自动会分发到可用的 SQL 节点上,从而保证 SQL 节点的故障对于应用程序来说是零影响的。

好了,关于 SQL 节点故障的测试我们就讲到这里。在下一小节中,我们来讲解在 MySQL Cluster 集群环境中如何关闭各个节点服务。

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
目录
相关文章
|
3月前
|
存储 关系型数据库 测试技术
玩转n8n测试自动化:核心节点详解与测试实战指南
n8n中节点是自动化测试的核心,涵盖触发器、数据操作、逻辑控制和工具节点。通过组合节点,测试工程师可构建高效、智能的测试流程,提升测试自动化能力。
|
6月前
|
SQL 缓存 自然语言处理
【赵渝强老师】OceanBase OBServer节点的SQL层
OceanBase OBServer节点的SQL层将用户的SQL请求转化为对Tablet的数据访问。整个处理流程包括Parser、Resolver、Transformer、Optimizer、CodeGenerator和Executor六大组件,依次完成词法解析、语义解析、逻辑改写、执行计划优化、代码生成及执行任务。同时,SQL层还支持Plan Cache功能,缓存历史执行计划以提升后续查询效率。视频讲解和图示展示了完整的SQL执行过程。
|
8月前
|
SQL 缓存 关系型数据库
使用温InnoDB缓冲池启动MySQL测试
使用温InnoDB缓冲池启动MySQL测试
142 0
|
8月前
|
SQL 缓存 关系型数据库
MySQL8.4 Enterprise安装Firewall及测试
MySQL8.4 Enterprise安装Firewall及测试
240 0
|
8月前
|
安全 关系型数据库 MySQL
MySQL8使用物理文件恢复MyISAM表测试
MySQL8使用物理文件恢复MyISAM表测试
138 0
|
9月前
|
Oracle 关系型数据库 MySQL
使用崖山YMP 迁移 Oracle/MySQL 至YashanDB 23.2 验证测试
这篇文章是作者尚雷关于使用崖山YMP迁移Oracle/MySQL至YashanDB 23.2的验证测试分享。介绍了YMP的产品信息,包括架构、版本支持等,还详细阐述了外置库部署、YMP部署、访问YMP、数据源管理、任务管理(创建任务、迁移配置、离线迁移、校验初始化、一致性校验)及MySQL迁移的全过程。
|
Java 关系型数据库 MySQL
自动化测试项目实战笔记(一):JDK、Tomcat、MySQL、Jpress环境安装和搭建
这篇文章是关于自动化测试项目实战笔记,涵盖了JDK、Tomcat、MySQL、Jpress环境的安装和搭建过程,以及测试用例和常见问题总结。
283 1
自动化测试项目实战笔记(一):JDK、Tomcat、MySQL、Jpress环境安装和搭建
|
关系型数据库 MySQL 测试技术
【赵渝强老师】MySQL的基准测试与sysbench
本文介绍了MySQL数据库的基准测试及其重要性,并详细讲解了如何使用sysbench工具进行测试。内容涵盖sysbench的安装、基本使用方法,以及具体测试MySQL数据库的步骤,包括创建测试数据库、准备测试数据、执行测试和清理测试数据。通过这些步骤,可以帮助读者掌握如何有效地评估MySQL数据库的性能。
432 5
|
SQL 分布式计算 NoSQL
大数据-170 Elasticsearch 云服务器三节点集群搭建 测试运行
大数据-170 Elasticsearch 云服务器三节点集群搭建 测试运行
300 4
|
分布式计算 Hadoop Shell
Hadoop-35 HBase 集群配置和启动 3节点云服务器 集群效果测试 Shell测试
Hadoop-35 HBase 集群配置和启动 3节点云服务器 集群效果测试 Shell测试
318 4

热门文章

最新文章

推荐镜像

更多