目录

一、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中登录所有节点(包括自己),并保存密码

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

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

 MySQL  JS > dba.checkInstanceConfiguration('root@172.16.9.52:3306')
Please provide the password for 'root@172.16.9.52:3306': ******
Save password for 'root@172.16.9.52:3306'? [Y]es/[N]o/Ne[v]er (default No): y
Validating MySQL instance at 172.16.9.52:3306 for use in an InnoDB cluster... This instance reports its own address as oratest52:3306
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. Checking whether existing tables comply with Group Replication requirements...
No incompatible tables detected Checking instance configuration...
Instance configuration is compatible with InnoDB cluster The instance '172.16.9.52:3306' is valid for InnoDB cluster usage. {
"status": "ok" #状态为ok
}

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

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

3.4创建一个名为myCluster的集群

 MySQL  172.16.9.51:3306  JS > var cluster = dba.createCluster('myCluster');
A new InnoDB cluster will be created on instance '172.16.9.51:3306'. Disabling super_read_only mode on instance '172.16.9.51:3306'.
Validating instance at 172.16.9.51:3306... This instance reports its own address as oratest51:3306 Instance configuration is suitable.
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
es.Creating InnoDB cluster 'myCluster' on '172.16.9.51:3306'... Adding Seed Instance...
Cluster successfully created. Use Cluster.addInstance() to add MySQL instances.
At least 3 instances are needed for the cluster to be able to withstand up to
one server failure.

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

 MySQL  172.16.9.51:3306  JS > cluster.status();
{
"clusterName": "myCluster",
"defaultReplicaSet": {
"name": "default",
"primary": "oratest51:3306",
"ssl": "DISABLED",
"status": "OK_NO_TOLERANCE",
"statusText": "Cluster is NOT tolerant to any failures.",
"topology": {
"oratest51:3306": {
"address": "oratest51:3306",
"mode": "R/W",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
}
},
"topologyMode": "Single-Primary"
},
"groupInformationSourceMember": "oratest51:3306"
}

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

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

 MySQL  172.16.9.51:3306  JS > cluster.addInstance('root@oratest52:3306');
Please provide the password for 'root@oratest52:3306': ******
Save password for 'root@oratest52:3306'? [Y]es/[N]o/Ne[v]er (default No): y
The safest and most convenient way to provision a new instance is through
automatic clone provisioning, which will completely overwrite the state of
'oratest52:3306' with a physical snapshot from an existing cluster member. To
use this method by default, set the 'recoveryMethod' option to 'clone'. The incremental distributed state recovery may be safely used if you are sure
all updates ever executed in the cluster were done with GTIDs enabled, there
are no purged transactions and the new instance contains the same GTID set as
the cluster or a subset of it. To use this method by default, set the
'recoveryMethod' option to 'incremental'. Incremental distributed state recovery was selected because it seems to be safely usable.
Validating instance at oratest52:3306... This instance reports its own address as oratest52:3306 Instance configuration is suitable.
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
.A new instance will be added to the InnoDB cluster. Depending on the amount of
data on the cluster this might take from a few seconds to several hours. Adding instance to the cluster... Monitoring recovery process of the new cluster member. Press ^C to stop monitoring and let it continue in background.
State recovery already finished for 'oratest52:3306' 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.
The instance 'oratest52:3306' was successfully added to the cluster.

3.7检查InnoDB Cluster集群状态

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

 MySQL  172.16.9.51:3306  JS > cluster.status();
{
"clusterName": "myCluster",
"defaultReplicaSet": {
"name": "default",
"primary": "oratest51:3306",
"ssl": "DISABLED",
"status": "OK",
"statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
"topology": {
"oratest51:3306": {
"address": "oratest51:3306",
"mode": "R/W",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
},
"oratest52:3306": {
"address": "oratest52:3306",
"mode": "R/O",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
},
"test61:3306": {
"address": "test61:3306",
"mode": "R/O",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
}
},
"topologyMode": "Single-Primary"
},
"groupInformationSourceMember": "oratest51:3306"
}

四、问题汇总

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

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

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

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

4.3集群所有节点发生重启

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

mysql-js> var cluster=dba.getCluster('mycluster')

Dba.getCluster: This function is not available through a session to a standalone instance (RuntimeError)

mysql-js> dba.rebootClusterFromCompleteOutage('mlampCluster'

五、性能测试

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

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

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

5.1.2查看seconde节点的各项性能

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
4.24 0.00 0.64 1.85 0.00 93.27 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 4.00 0.00 328.80 0 1644
sdb 352.80 0.00 21174.60 0 105873
dm-0 4.80 0.00 328.80 0 1644
dm-1 0.00 0.00 0.00 0 0 avg-cpu: %user %nice %system %iowait %steal %idle
6.62 0.00 0.54 1.78 0.00 91.06 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 0.20 0.00 0.80 0 4
sdb 266.80 0.00 27255.60 0 136278
dm-0 0.20 0.00 0.80 0 4
dm-1 0.00 0.00 0.00 0 0 avg-cpu: %user %nice %system %iowait %steal %idle
2.84 0.00 0.20 1.36 0.00 95.60 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 6.80 0.00 72.00 0 360
sdb 131.60 0.00 18786.10 0 93930
dm-0 7.40 0.00 72.00 0 360
dm-1 0.00 0.00 0.00 0 0 avg-cpu: %user %nice %system %iowait %steal %idle
7.24 0.00 0.73 2.02 0.00 90.02 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 0.40 0.00 148.00 0 740
sdb 316.20 0.00 28787.50 0 143937
dm-0 0.40 0.00 148.00 0 740
dm-1 0.00 0.00 0.00 0 0 avg-cpu: %user %nice %system %iowait %steal %idle
3.44 0.00 0.36 1.01 0.00 95.18 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 4.20 12.80 39.00 64 195
sdb 145.40 0.00 15742.60 0 68713
dm-0 5.40 12.80 39.00 64 195
dm-1 0.00 0.00 0.00 0 0
mysql> select count(*) from t_daykline;
+----------+
| count(*) |
+----------+
| 6088654 |
+----------+

测试结果: 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. c++书籍推荐《C++编码规范》下载

    百度云及其他网盘下载地址:点我 编辑推荐 <C++编程规范:101条规则.准则与 实践>:良好的编程规范可以改善软件质量,缩短上市时间,提升团队效率,简化维护工作.在<C++编程规范 ...

  2. WPF 入门笔记之事件

    一.事件路由 1. 直接路由事件 起源于一个元素,并且不能传递给其他元素 MouserEnter 和MouserLeave 就是直接事件路由 2. 冒泡路由事件 在包含层次中向上传递,首先由引发的元素 ...

  3. Spring Cloud Alibaba | Nacos配置管理

    目录 Spring Cloud Alibaba | Nacos配置管理 1. pom.xml 项目依赖 2. 在 bootstrap.properties 中配置 Nacos server 的地址和应 ...

  4. 浅谈 Attention 机制的理解

    什么是注意力机制? 注意力机制模仿了生物观察行为的内部过程,即一种将内部经验和外部感觉对齐从而增加部分区域的观察精细度的机制.例如人的视觉在处理一张图片时,会通过快速扫描全局图像,获得需要重点关注的目 ...

  5. MLlib特征变换方法

    Spark1.6.2.2.3 PCA 算法介绍: 主成分分析是一种统计学方法,它使用正交转换从一系列可能相关的变量中提取线性无关变量集,提取出的变量集中的元素称为主成分.使用PCA方法可以对变量集合进 ...

  6. LeetCode第2题

    // 给出两个 非空 的链表用来表示两个非负的整数.其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字.//// 如果,我们将这两个数相加起来,则会返回一个新的链表 ...

  7. Java NIO学习系列五:I/O模型

    前面总结了很多IO.NIO相关的基础知识点,还总结了IO和NIO之间的区别及各自适用场景,本文会从另一个视角来学习一下IO,即IO模型.什么是IO模型?对于不同人.在不同场景下给出的答案是不同的,所以 ...

  8. 【区分】Typescript 中 interface 和 type

    在接触 ts 相关代码的过程中,总能看到 interface 和 type 的身影.只记得,曾经遇到 type 时不懂查阅过,记得他们很像,相同的功能用哪一个都可以实现.但最近总看到他们,就想深入的了 ...

  9. 【微信小程序】微信小程序-实现tab

    一.前言 小程序开发中,有很多封装好的控件供开发者使用,但是,很常见的tab选项卡居然没有,只能自己搞一个. 实现原理也很简单,无非是用给view(tab)设置一个点击事件bintap,并且给view ...

  10. 获取Oracle中表的结构

    首先cmd登录Oracle:sqlplus user/password@host/db_name 然后输入DESC table_name 可以先按住Alt,再选中字段名(块选中快捷方式)