目录

一、InnoDB Cluster介绍

MySQL InnoDB Cluster是MySQL官方推出完整的高可用性解决方案,MySQL InnoDB Cluster由三大组件组成:MySQL ShellMySQL RouterMySQL Group Replication。每个MySQL服务器实例都运行MySQL Group Replication,它提供了在InnoDB集群内复制数据的机制,具有内置故障转移功能。

MySQL Cluster的部署有两种方式,一种是直接部署MySQL InnoDB Cluster,一种是基于现有的MySQL Group Replication部署,本文采用基于现有的MySQL Group Replication部署

InnoDB Cluster不支持MySQL NDB Cluster

二、环境准备

主机名 IP地址 角色
oratest51 172.16.9.51 primary
oratest52 172.16.9.52 seconde
test61 172.16.9.61 seconde
node4 172.16.8.68 MySQL Router

操作系统:CentOS Linux release 7.2.1511

MySQL版本:mysql-5.7.26-linux-glibc2.12-x86_64

MySQL Router版本:mysql-router-8.0.17-linux-glibc2.12-x86_64

MySQL Shell版本:mysql-shell-8.0.17-linux-glibc2.12-x86-64bit

下面的安装步骤前提条件是MGR、MySQL Shell已经安装好的情况下

三、将MGR节点加入MySQL Cluster

3.1登录所有MGR节点,并在该节点的shell中登录所有节点(包括自己),并保存密码

  1. MySQL JS > shell.connect('root@172.16.9.51:3306')
  2. MySQL JS > shell.connect('root@172.16.9.52:3306')
  3. MySQL JS > shell.connect('root@172.16.9.61:3306')

3.2检查MGR所有节点状态是否正常

  1. MySQL JS > dba.checkInstanceConfiguration('root@172.16.9.52:3306')
  2. Please provide the password for 'root@172.16.9.52:3306': ******
  3. Save password for 'root@172.16.9.52:3306'? [Y]es/[N]o/Ne[v]er (default No): y
  4. Validating MySQL instance at 172.16.9.52:3306 for use in an InnoDB cluster...
  5. This instance reports its own address as oratest52:3306
  6. Clients and other cluster members will communicate with it through this address by default. If this is not correct, the report_host MySQL system variable should be changed.
  7. Checking whether existing tables comply with Group Replication requirements...
  8. No incompatible tables detected
  9. Checking instance configuration...
  10. Instance configuration is compatible with InnoDB cluster
  11. The instance '172.16.9.52:3306' is valid for InnoDB cluster usage.
  12. {
  13. "status": "ok" #状态为ok
  14. }

3.3检查my.cnf配置是否正确,只有正确才能创建集群

  1. MySQL JS > dba.configureLocalInstance('root@172.16.9.51:3306')
  2. The instance '172.16.9.51:3306' belongs to an InnoDB cluster.
  3. Detecting the configuration file...
  4. Default file not found at the standard locations.
  5. Please specify the path to the MySQL configuration file: /etc/my.cnf #输入my.cnf绝对路径
  6. Persisting the cluster settings...
  7. The instance '172.16.9.51:3306' was configured for use in an InnoDB cluster.
  8. The instance cluster settings were successfully persisted.

3.4创建一个名为myCluster的集群

  1. MySQL 172.16.9.51:3306 JS > var cluster = dba.createCluster('myCluster');
  2. A new InnoDB cluster will be created on instance '172.16.9.51:3306'.
  3. Disabling super_read_only mode on instance '172.16.9.51:3306'.
  4. Validating instance at 172.16.9.51:3306...
  5. This instance reports its own address as oratest51:3306
  6. Instance configuration is suitable.
  7. WARNING: Instance '172.16.9.51:3306' cannot persist Group Replication configuration since MySQL version 5.7.26 does not support the SET PERSIST command (MySQL version >= 8.0.11 required). Please use the <Dba>.configureLocalInstance() command locally to persist the chang
  8. es.Creating InnoDB cluster 'myCluster' on '172.16.9.51:3306'...
  9. Adding Seed Instance...
  10. Cluster successfully created. Use Cluster.addInstance() to add MySQL instances.
  11. At least 3 instances are needed for the cluster to be able to withstand up to
  12. one server failure.

3.5查看集群状态,可以发现myCluster集群目前只有一个节点

  1. MySQL 172.16.9.51:3306 JS > cluster.status();
  2. {
  3. "clusterName": "myCluster",
  4. "defaultReplicaSet": {
  5. "name": "default",
  6. "primary": "oratest51:3306",
  7. "ssl": "DISABLED",
  8. "status": "OK_NO_TOLERANCE",
  9. "statusText": "Cluster is NOT tolerant to any failures.",
  10. "topology": {
  11. "oratest51:3306": {
  12. "address": "oratest51:3306",
  13. "mode": "R/W",
  14. "readReplicas": {},
  15. "role": "HA",
  16. "status": "ONLINE"
  17. }
  18. },
  19. "topologyMode": "Single-Primary"
  20. },
  21. "groupInformationSourceMember": "oratest51:3306"
  22. }

3.6添加其他MGR节点到InnoDB Cluster集群当中

以下仅示范一个节点,添加其他节点方法也是一样

  1. MySQL 172.16.9.51:3306 JS > cluster.addInstance('root@oratest52:3306');
  2. Please provide the password for 'root@oratest52:3306': ******
  3. Save password for 'root@oratest52:3306'? [Y]es/[N]o/Ne[v]er (default No): y
  4. The safest and most convenient way to provision a new instance is through
  5. automatic clone provisioning, which will completely overwrite the state of
  6. 'oratest52:3306' with a physical snapshot from an existing cluster member. To
  7. use this method by default, set the 'recoveryMethod' option to 'clone'.
  8. The incremental distributed state recovery may be safely used if you are sure
  9. all updates ever executed in the cluster were done with GTIDs enabled, there
  10. are no purged transactions and the new instance contains the same GTID set as
  11. the cluster or a subset of it. To use this method by default, set the
  12. 'recoveryMethod' option to 'incremental'.
  13. Incremental distributed state recovery was selected because it seems to be safely usable.
  14. Validating instance at oratest52:3306...
  15. This instance reports its own address as oratest52:3306
  16. Instance configuration is suitable.
  17. WARNING: Instance 'oratest52:3306' cannot persist Group Replication configuration since MySQL version 5.7.26 does not support the SET PERSIST command (MySQL version >= 8.0.11 required). Please use the <Dba>.configureLocalInstance() command locally to persist the changes
  18. .A new instance will be added to the InnoDB cluster. Depending on the amount of
  19. data on the cluster this might take from a few seconds to several hours.
  20. Adding instance to the cluster...
  21. Monitoring recovery process of the new cluster member. Press ^C to stop monitoring and let it continue in background.
  22. State recovery already finished for 'oratest52:3306'
  23. WARNING: Instance 'oratest51:3306' cannot persist configuration since MySQL version 5.7.26 does not support the SET PERSIST command (MySQL version >= 8.0.11 required). Please use the <Dba>.configureLocalInstance() command locally to persist the changes.
  24. The instance 'oratest52:3306' was successfully added to the cluster.

3.7检查InnoDB Cluster集群状态

所有节点都添加到InnoDB Cluster中之后,检查InnoDB Cluster集群状态

  1. MySQL 172.16.9.51:3306 JS > cluster.status();
  2. {
  3. "clusterName": "myCluster",
  4. "defaultReplicaSet": {
  5. "name": "default",
  6. "primary": "oratest51:3306",
  7. "ssl": "DISABLED",
  8. "status": "OK",
  9. "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
  10. "topology": {
  11. "oratest51:3306": {
  12. "address": "oratest51:3306",
  13. "mode": "R/W",
  14. "readReplicas": {},
  15. "role": "HA",
  16. "status": "ONLINE"
  17. },
  18. "oratest52:3306": {
  19. "address": "oratest52:3306",
  20. "mode": "R/O",
  21. "readReplicas": {},
  22. "role": "HA",
  23. "status": "ONLINE"
  24. },
  25. "test61:3306": {
  26. "address": "test61:3306",
  27. "mode": "R/O",
  28. "readReplicas": {},
  29. "role": "HA",
  30. "status": "ONLINE"
  31. }
  32. },
  33. "topologyMode": "Single-Primary"
  34. },
  35. "groupInformationSourceMember": "oratest51:3306"
  36. }

四、问题汇总

4.1获取不到集群状态,需要先定义集群再获取,如下:

  1. MySQL 172.16.9.51:3306 JS > var cluster = dba.getCluster()
  2. MySQL 172.16.9.51:3306 JS > cluster.status();

4.2节点重启后,如果未加入集群,执行下面代码加入

  1. # mysqlsh --uri root@172.16.9.51:3306
  2. MySQL 172.16.9.51:3306 JS > dba.rebootClusterFromCompleteOutage()
  3. MySQL 172.16.9.51:3306 JS > var cluster = dba.getCluster();
  4. MySQL 172.16.9.51:3306 JS > cluster.rescan()

4.3集群所有节点发生重启

当集群的所有节点都offline,直接获取集群信息失败,如何重新恢复集群

  1. mysql-js> var cluster=dba.getCluster('mycluster')
  2. Dba.getCluster: This function is not available through a session to a standalone instance (RuntimeError)
  3. mysql-js> dba.rebootClusterFromCompleteOutage('mlampCluster'

五、性能测试

5.1在MGR的primary节点插入数据,查看seconde节点的同步情况和性能

5.1.1在MGR的primary节点上插入600W行数据

  1. [root@test51 data]# mysql -uroot -p123456 < db_hq_market_sh_daykline.sql

5.1.2查看seconde节点的各项性能

  1. avg-cpu: %user %nice %system %iowait %steal %idle
  2. 4.24 0.00 0.64 1.85 0.00 93.27
  3. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  4. sda 4.00 0.00 328.80 0 1644
  5. sdb 352.80 0.00 21174.60 0 105873
  6. dm-0 4.80 0.00 328.80 0 1644
  7. dm-1 0.00 0.00 0.00 0 0
  8. avg-cpu: %user %nice %system %iowait %steal %idle
  9. 6.62 0.00 0.54 1.78 0.00 91.06
  10. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  11. sda 0.20 0.00 0.80 0 4
  12. sdb 266.80 0.00 27255.60 0 136278
  13. dm-0 0.20 0.00 0.80 0 4
  14. dm-1 0.00 0.00 0.00 0 0
  15. avg-cpu: %user %nice %system %iowait %steal %idle
  16. 2.84 0.00 0.20 1.36 0.00 95.60
  17. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  18. sda 6.80 0.00 72.00 0 360
  19. sdb 131.60 0.00 18786.10 0 93930
  20. dm-0 7.40 0.00 72.00 0 360
  21. dm-1 0.00 0.00 0.00 0 0
  22. avg-cpu: %user %nice %system %iowait %steal %idle
  23. 7.24 0.00 0.73 2.02 0.00 90.02
  24. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  25. sda 0.40 0.00 148.00 0 740
  26. sdb 316.20 0.00 28787.50 0 143937
  27. dm-0 0.40 0.00 148.00 0 740
  28. dm-1 0.00 0.00 0.00 0 0
  29. avg-cpu: %user %nice %system %iowait %steal %idle
  30. 3.44 0.00 0.36 1.01 0.00 95.18
  31. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  32. sda 4.20 12.80 39.00 64 195
  33. sdb 145.40 0.00 15742.60 0 68713
  34. dm-0 5.40 12.80 39.00 64 195
  35. dm-1 0.00 0.00 0.00 0 0
  1. mysql> select count(*) from t_daykline;
  2. +----------+
  3. | count(*) |
  4. +----------+
  5. | 6088654 |
  6. +----------+

测试结果: IOPS基本维持在100到350之间,每秒写入基本在15M~22M之间,主库数据导入成功后,从库数据也实时同步完成

六、个人总结

  • MGR架构可以实现高可用,但实现failover,则需要安装InnoDB Cluster了。MySQL Shell和MySQL Router是InnoDB Cluster集群的一部分。MySQL Shell用于安装和管理InnoDB Cluster集群,InnoDB Cluster集群通过新建的原数据库MySQL_innodb_cluster_metadata管理MGR集群状态,MySQL Router通过周期性的访问InnoDB Cluster创建的MySQL_innodb_cluster_metadata库中的元数据获取集群成员信息,再通过performance_schema的系统表获取可连接实例及其状态来实现failover和读负载均衡、读写分离的路由。
  • 创建InnoDB Cluster至少需要三台MySQL服务器,且数量为奇数个。
  • MySQL InnoDB Cluster作为MySQL官方推荐的两个集群解决方案之一,个人觉得各方面还是不错的,对功能要求不多的话可以选择此方案,第三方的高可用方案如:HAProxy、Proxsql也可以。

MySQL InnoDB Cluster介绍的更多相关文章

  1. MYSQL InnoDB Cluster

    https://dev.mysql.com/doc/refman/5.7/en/group-replication.html GroupReplication的原理 https://dev.mysql ...

  2. Mysql Innodb cluster集群搭建

    之前搭建过一个Mysql Ndb cluster集群,但是mysql版本是5.7的,看到官网上mysql8的还是开发者版本,所以尝试搭建下mysql Innodb cluster集群. MySQL的高 ...

  3. MySQL高可用方案-MySQL InnoDB Cluster

    MySQL InnoDB Cluster简介 MySQL InnoDB Cluster 是最新GA的MySQL高可用方案,利用MySQL Group Replication和MySQL Shell.M ...

  4. mysql innodb cluster 无感知集群

    MySQL 8.0.12 innodb cluster 高可用集群部署运维管理手册 Innodb cluster 原理介绍 Innodb cluster  利用组复制的 pxos 协议,保障数据一致性 ...

  5. 什么是mysql innodb cluster?

    目录 一.简介 二.特性 一.简介 MySQL InnoDB集群提供了一个集成的,本地的,HA解决方案.MySQL InnoDB集群由以下几部分组成: MySQL Servers with Group ...

  6. MySQL InnoDB索引介绍以及在线添加索引实例分析

    引言:MySQL之所以能成为经典,不是没有道理的,B+树足矣! 一.索引概念 InnoDB引擎支持三种常见的索引:B+树索引,全文索引和(自适应)哈希索引.B+树索引是传统意义上的索引,构造类似二叉树 ...

  7. Centos7.5基于MySQL5.7的 InnoDB Cluster 多节点高可用集群环境部署记录

    一.   MySQL InnoDB Cluster 介绍MySQL的高可用架构无论是社区还是官方,一直在技术上进行探索,这么多年提出了多种解决方案,比如MMM, MHA, NDB Cluster, G ...

  8. MySQL 8.0.18 InnoDB Cluster 主从(MGR)完整安装配置

    提示: MySQL InnoDB Cluster底层依赖Group Replication模式,至少3台机器 1.  准备3台 CentOS Linux 7 (Core), 修改各主机名:db-hos ...

  9. Innodb Cluster集群部署配置

    目录 一.简介 二.环境声明 三.部署 安装(均操作) 配置(均操作) 开启group_replication(均操作) 启动group_replication 创建集群(在mysql-1执行) 创建 ...

随机推荐

  1. [网络协议]TCP粘包分析

    关于socket粘包,socket缓冲区设置的问题,记录一下: 一 .两个简单概念长连接与短连接: 长连接     Client方与Server方先建立通讯连接,连接建立后不断开, 然后再进行报文发送 ...

  2. Shiro中@RequiresAuthentication等等注解介绍

    使用前请先开启Shiro的controller层注解,如果已经设置请下滑绕过 要在spring-mvc.xml中写. <!--下面的用于开启shiro的权限注解--> <bean c ...

  3. Java web导出word,文件名为中文,%E6%9D%90%E8%B4%A8%E5%8D%95乱码

    因为文件名为中文,导出时会有乱码问题 原代码: String fileName = "文件名.doc"; response.setHeader("Content-Disp ...

  4. Ansible配置文件ansible.cfg详解

    Ansible是一个系列文章,我会尽量以通俗易懂.诙谐幽默的总结方式给大家呈现这些枯燥的知识点,让学习变的有趣一些. Ansible系列博文直达链接:Ansible入门系列 前言 此时外面小雨淅淅沥沥 ...

  5. 【CYH-02】NOIp考砸后虐题赛:转换式:题解

    这道题真的不难吧. 如@AKEE@AKEE@AKEE 大佬所说,此题的确可以将n推广到一般情况. 但题面还是良心的只到了N<=4N<=4N<=4 以目前的题目来看,简单模拟即可. 分 ...

  6. svg文字描边动画

    svg动画在网页中是经常见到的,svg动画使得网页看起来清新美观 任何不规则图形都可以由svg绘制完成,当然也包括文字,文字本身就可以看作一个不规则图形

  7. 用python输出回文数

    一个b站上的朋友问我,怎么返回五位数的回文数的个数. 我首先百度回文数的概念,就是正读和倒读都一样的数字,例如:10001,99899 等等 数字的位数拆分一头雾水,思来想去,用字符串的方法完美解决! ...

  8. Maven重新下载未下载完成的jar包

    使用maven下载jar包,经常会遇到下载失败的情况,如果失败的jar包过多,或是不清楚到底有那些jar包在下载过程中出现了问题.可通过maven命令重新批量下载未成功的jar包. 1,打开cmd , ...

  9. Go语言圣经习题练习_1.7. Web服务

    练习 1.12: 修改Lissajour服务,从URL读取变量,比如你可以访问 http://localhost:8000/?cycles=20 这个URL,这样访问可以将程序里的cycles默认的5 ...

  10. Jmeter脚本录制--HTTP代理服务器

    Jmeter脚本录制功能依赖第三方工具Badboy,所以在安装了Jmeter之后,还需要再安装一个工具. Badboy本身自带浏览器,相关操作只能在Badboy上进行操作,偶尔可能会遇到浏览器兼容的问 ...