• GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源。

本文介绍如何利用MySQL Shell + GreatSQL 8.0.25构建一个三节点的MGR集群。

MySQL Shell是一个客户端工具,可用于方便管理和操作MySQL,支持SQL、JavaScript、Python等多种语言,也包括完善的API。MySQL Shell支持文档型和关系型数据库模式,通过X DevAPI可以管理文档型数据,通过AdminAPI可以管理InnoDB Cluster、InnoDB ClusterSet及InnoDB ReplicaSet等。

1. 安装准备

准备好下面三台服务器:

IP 端口 角色
172.16.16.10 3306 mgr1
172.16.16.11 3306 mgr2
172.16.16.12 3306 mgr3

确保三个节点间的网络是可以互通的,并且没有针对3306和33061端口的防火墙拦截规则。

利用yum安装MySQL Shell,版本选择和GreatSQL相同的8.0.25:

$ yum install mysql-shell-8.0.25

假定已经参考前文 3. 安装部署MGR集群 做好MySQL Server的初始化并启动三个实例。

接下来直接利用MySQL Shell部署MGR。

2. 利用MySQL Shell构建MGR集群

利用MySQL Shell构建MGR集群比较简单,主要有几个步骤:

  1. 检查实例是否满足条件。
  2. 创建并初始化一个集群。
  3. 逐个添加实例。

首先,用管理员账号 root 连接到第一个节点:

#在本地通过socket方式登入
$ mysqlsh -Spath/mysql.sock root@localhost
Please provide the password for 'root@.%2Fmysql.sock': ********
Save password for 'root@.%2Fmysql.sock'? [Y]es/[N]o/Ne[v]er (default No): yes
MySQL Shell 8.0.25
...

执行命令 \status 查看当前节点的状态,确认连接正常可用。

执行 dba.configureInstance() 命令开始检查当前实例是否满足安装MGR集群的条件,如果不满足可以直接配置成为MGR集群的一个节点:

 MySQL  localhost  JS > dba.configureInstance()
Configuring local MySQL instance listening at port 3306 for use in an InnoDB cluster... This instance reports its own address as 172.16.16.10:3306 #提示当前的用户是管理员,不能直接用于MGR集群,需要新建一个账号
ERROR: User 'root' can only connect from 'localhost'. New account(s) with proper source address specification to allow remote connection from all instances must be created to manage the cluster. 1) Create remotely usable account for 'root' with same grants and password
2) Create a new admin account for InnoDB cluster with minimal required grants
3) Ignore and continue
4) Cancel Please select an option [1]: 2 <-- 这里我们选择方案2,即创建一个最小权限账号
Please provide an account name (e.g: icroot@%) to have it created with the necessary
privileges or leave empty and press Enter to cancel.
Account Name: GreatSQL
Password for new account: ********
Confirm password: ******** applierWorkerThreads will be set to the default value of 4. The instance '172.16.16.10:3306' is valid to be used in an InnoDB cluster. Cluster admin user 'GreatSQL'@'%' created.
The instance '172.16.16.10:3306' is already ready to be used in an InnoDB cluster. Successfully enabled parallel appliers.

完成检查并创建完新用户后,退出当前的管理员账户,并用新创建的MGR专用账户登入,准备初始化创建一个新集群:

$ mysqlsh --uri GreatSQL@172.16.16.10:3306
Please provide the password for 'GreatSQL@172.16.16.10:3306': ********
Save password for 'GreatSQL@172.16.16.10:3306'? [Y]es/[N]o/Ne[v]er (default No): yes
MySQL Shell 8.0.25 ...
#定义一个变量名c,方便下面引用
MySQL 172.16.16.10:3306 ssl JS > var c = dba.createCluster('MGR1');
A new InnoDB cluster will be created on instance '172.16.16.10:3306'. Validating instance configuration at 172.16.16.10:3306... This instance reports its own address as 172.16.16.10:3306 Instance configuration is suitable.
NOTE: Group Replication will communicate with other members using '172.16.16.10:33061'. Use the localAddress option to override. Creating InnoDB cluster 'MGR1' on '172.16.16.10: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. MySQL 172.16.16.10:3306 ssl JS >

这就完成了MGR集群的初始化并加入第一个节点(引导节点)。

接下来,用同样方法先用 root 账号分别登入到另外两个节点,完成节点的检查并创建最小权限级别用户(此过程略过。。。注意各节点上创建的用户名、密码都要一致),之后回到第一个节点,执行 addInstance() 添加另外两个节点。

 MySQL  172.16.16.10:3306 ssl  JS > c.addInstance('GreatSQL@172.16.16.11:3306');  <-- 这里要指定MGR专用账号

WARNING: A GTID set check of the MySQL instance at '172.16.16.11:3306' determined that it contains transactions that do not originate from the cluster, which must be discarded before it can join the cluster.

172.16.16.11:3306 has the following errant GTIDs that do not exist in the cluster:
b05c0838-6850-11ec-a06b-00155d064000:1 WARNING: Discarding these extra GTID events can either be done manually or by completely overwriting the state of 172.16.16.11:3306 with a physical snapshot from an existing cluster member. To use this method by default, set the 'recoveryMethod' option to 'clone'. Having extra GTID events is not expected, and it is recommended to investigate this further and ensure that the data can be removed prior to choosing the clone recovery method. Please select a recovery method [C]lone/[A]bort (default Abort): Clone <-- 选择用Clone方式从第一个节点全量复制数据
Validating instance configuration at 172.16.16.11:3306... This instance reports its own address as 172.16.16.11:3306 Instance configuration is suitable.
NOTE: Group Replication will communicate with other members using '172.16.16.11:33061'. Use the localAddress option to override. 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.
Clone based state recovery is now in progress. NOTE: A server restart is expected to happen as part of the clone process. If the
server does not support the RESTART command or does not come back after a
while, you may need to manually start it back. * Waiting for clone to finish...
NOTE: 172.16.16.11:3306 is being cloned from 172.16.16.10:3306
** Stage DROP DATA: Completed
** Clone Transfer
FILE COPY ############################################################ 100% Completed
PAGE COPY ############################################################ 100% Completed
REDO COPY ############################################################ 100% Completed NOTE: 172.16.16.11:3306 is shutting down... <-- 数据Clone完成,准备重启实例。如果该实例无法完成自动重启,则需要手动启动 * Waiting for server restart... ready
* 172.16.16.11:3306 has restarted, waiting for clone to finish...
** Stage RESTART: Completed
* Clone process has finished: 72.43 MB transferred in about 1 second (~72.43 MB/s) State recovery already finished for '172.16.16.11:3306' The instance '172.16.16.11:3306' was successfully added to the cluster. <-- 新实例加入成功 MySQL 172.16.16.10:3306 ssl JS >

用同样的方法,将 172.16.16.12:3306 实例也加入到集群中。

现在,一个有这三节点的MGR集群已经部署完毕,来确认下:

 MySQL  172.16.16.10:3306 ssl  JS > c.describe()
{
"clusterName": "MGR1",
"defaultReplicaSet": {
"name": "default",
"topology": [
{
"address": "172.16.16.10:3306",
"label": "172.16.16.10:3306",
"role": "HA"
},
{
"address": "172.16.16.11:3306",
"label": "172.16.16.11:3306",
"role": "HA"
},
{
"address": "172.16.16.12:3306",
"label": "172.16.16.12:3306",
"role": "HA"
}
],
"topologyMode": "Single-Primary"
}
}

或者执行 c.status() 可以打印出集群更多的信息。

至此,利用MySQL Shell构建一个三节点的MGR集群做好了,可以尝试向 Primary 节点写入数据观察测试。

3. MySQL Shell接管现存的MGR集群

对于已经在运行中的MGR集群,也是可以用MySQL Shell接管的。只需要在调用 createCluster() 函数时,加上 adoptFromGR:true 选项即可。实际上不加这个选项的话,MySQL Shell也会自动检测到该MGR集群已存在,并询问是否要接管。

在这里简单演示下:

#不加上 adoptFromGr:true 选项
MySQL 172.16.16.10:3306 ssl JS > var c=dba.createCluster('MGR1');
A new InnoDB cluster will be created on instance '172.16.16.10:3306'. You are connected to an instance that belongs to an unmanaged replication group.
Do you want to setup an InnoDB cluster based on this replication group? [Y/n]:

可以看到,会有提示信息询问是否要接管。

如果加上 adoptFromGr:true 选项,则会直接创建集群,不再询问:

var c=dba.createCluster('MGR1', {adoptFromGr:true});
A new InnoDB cluster will be created based on the existing replication group on instance '172.16.16.10:3306'. Creating InnoDB cluster 'MGR1' on '172.16.16.10:3306'... Adding Seed Instance...
Adding Instance '172.16.16.10:3306'...
Adding Instance '172.16.16.11:3306'...
Adding Instance '172.16.16.12:3306'...
...

如果是MGR集群的metadata发生变化,这时候无论调用 dba.getCluster() 还是 dba.createCluster 都可能会报告类似下面的错误:

Dba.getCluster: Unable to get an InnoDB cluster handle. The instance '192.168.6.27:3306' may belong to a different cluster from the one registered in the Metadata since the value of 'group_replication_group_name' does not match the one registered in the Metadata: possible split-brain scenario. Please retry while connected to another member of the cluster. (RuntimeError)

这种情况下,可以调用 dba.dropMetadataSchema() 函数删除元数据,再调用 dba.createCluster() 接管集群:

#确保不影响正常业务的话,删除无用MGR元数据
MySQL 172.16.16.10:3306 ssl JS > dba.dropMetadataSchema()
Are you sure you want to remove the Metadata? [y/N]: y
Metadata Schema successfully removed. #接管现有集群
MySQL 172.16.16.10:3306 ssl JS > var c=dba.createCluster('MGR1', {adoptFromGr:true})
...

这样就可以了接管了。

4. 小结

本文主要介绍了如何利用MySQL Shell构建一个三节点的MGR集群,以及如何用MySQL Shell接管现有集群,处理元数据冲突的问题。相对于手工方式搭建MGR集群,用MySQL Shell操作会方便很多,推荐使用。

参考资料、文档

免责声明

因个人水平有限,专栏中难免存在错漏之处,请勿直接复制文档中的命令、方法直接应用于线上生产环境。请读者们务必先充分理解并在测试环境验证通过后方可正式实施,避免造成生产环境的破坏或损害。

Enjoy GreatSQL

文章推荐:

GreatSQL季报(2021.12.26)

https://mp.weixin.qq.com/s/FZ_zSBHflwloHtZ38YJxbA

技术分享|sysbench 压测工具用法浅析

https://mp.weixin.qq.com/s/m16LwXWy9bFt0i99HjbRsw

故障分析 | linux 磁盘io利用率高,分析的正确姿势

https://mp.weixin.qq.com/s/7cu_36jfsjZp1EkVexkojw

技术分享|闪回在MySQL中的实现和改进

https://mp.weixin.qq.com/s/6jepwEE0DnYUpjMYO17VtQ

万答#20,索引下推如何进行数据过滤

https://mp.weixin.qq.com/s/pt6mr3Ge1ya2aa6WlrpIvQ

关于 GreatSQL

GreatSQL是由万里数据库维护的MySQL分支,专注于提升MGR可靠性及性能,支持InnoDB并行查询特性,是适用于金融级应用的MySQL分支版本。

Gitee:

https://gitee.com/GreatSQL/GreatSQL

GitHub:

https://github.com/GreatSQL/GreatSQL

Bilibili:

https://space.bilibili.com/1363850082/video

微信&QQ群:

可搜索添加GreatSQL社区助手微信好友,发送验证信息“加群”加入GreatSQL/MGR交流微信群

QQ群:533341697

微信小助手:wanlidbc

本文由博客一文多发平台 OpenWrite 发布!

4. 利用MySQL Shell安装部署MGR集群 | 深入浅出MGR的更多相关文章

  1. 3. 安装部署MGR集群 | 深入浅出MGR

    GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 目录 1. 安装准备 2. 初始化MySQL Server 3. 初始化MGR第一个节点 4. 继续设置另外两个节点 5. ...

  2. Cloudera Manager安装之利用parcels方式安装单节点集群(包含最新稳定版本或指定版本的安装)(添加服务)(CentOS6.5)(四)

    不多说,直接上干货! 福利 => 每天都推送 欢迎大家,关注微信扫码并加入我的4个微信公众号:   大数据躺过的坑      Java从入门到架构师      人工智能躺过的坑          ...

  3. 使用docker安装部署Spark集群来训练CNN(含Python实例)

    使用docker安装部署Spark集群来训练CNN(含Python实例) http://blog.csdn.net/cyh_24/article/details/49683221 实验室有4台神服务器 ...

  4. centos7.8 安装部署 k8s 集群

    centos7.8 安装部署 k8s 集群 目录 centos7.8 安装部署 k8s 集群 环境说明 Docker 安装 k8s 安装准备工作 Master 节点安装 k8s 版本查看 安装 kub ...

  5. kubernetes系列03—kubeadm安装部署K8S集群

    本文收录在容器技术学习系列文章总目录 1.kubernetes安装介绍 1.1 K8S架构图 1.2 K8S搭建安装示意图 1.3 安装kubernetes方法 1.3.1 方法1:使用kubeadm ...

  6. supervisor的安装部署及集群管理

    supervisor的安装部署及集群管理 supervisor官网:http://www.supervisord.org/ 参考链接: http://blog.csdn.net/xyang81/art ...

  7. 安装部署 Kubernetes 集群

    安装部署 Kubernetes 集群 阅读目录: 准备工作 部署 Master 管理节点 部署 Minion 工作节点 部署 Hello World 应用 安装 Dashboard 插件 安装 Hea ...

  8. 【大数据之数据仓库】安装部署GreenPlum集群

    本篇将向大家介绍如何快捷的安装部署GreenPlum测试集群,大家可以跟着我一块儿实践一把^_^ 1.主机资源 申请2台网易云主机,操作系统必须是RedHat或者CentOS,配置尽量高一点.如果是s ...

  9. Docker安装部署es集群

    Docker安装部署es集群:环境准备:已安装docker的centos服务器一台1. 拉取es版本docker pull elasticsearch:5.6.82. 新建文件夹 数据挂载目录 和 配 ...

随机推荐

  1. 实验二——以点类 Point 为基类设计圆类 Circle

    学习内容:以点类 Point 为基类设计圆类 Circle 示例代码: package 实验二; import java.util.Scanner; class Point{//父类Point pri ...

  2. 个人冲刺(四阶段)——体温上报app(一阶段)

    任务:完成了后台数据库的类模块 MyDBHelper.java package com.example.helloworld; import android.content.Context; impo ...

  3. 探究MySQL中SQL查询的成本

    成本 什么是成本,即SQL进行查询的花费的时间成本,包含IO成本和CPU成本. IO成本:即将数据页从硬盘中读取到内存中的读取时间成本.通常1页就是1.0的成本. CPU成本:即是读取和检测是否满足条 ...

  4. .net 获取IP地址的几种方式

    1.获取服务器IP地址: 1) Local_Addr var Local_Addr = Request.ServerVariables.Get("Local_Addr").ToSt ...

  5. 异常——JavaSE基础

    异常 异常的分类 检查性异常 运行时异常:可能被程序员避免的异常,运行时异常可以在编译时被忽略 错误ERROR:错误不是异常 在Java中把异常当作对象来处理,并且定义了一个基类java.lang.T ...

  6. centos6搭建mysql

    目前CentOS6.5及一下版本基本上被官方给放弃更新了,但是考虑到忠实粉丝迟迟不肯放手,所以还留了入口但是非常有限 1.搭建mysql 可参照:https://blog.csdn.net/huang ...

  7. windows和linux系统下测试端口连通性的命令

    0. ping 1. telnet 2. ssh 3. curl 4. wget 5. tcping 6. 总结 本文地址: https://www.cnblogs.com/hchengmx/p/12 ...

  8. IIS版本与Windows Server版本对应关系

    IIS 6.0随着Windows XP Professional 64位和Windows Server 2003发布. IIS 7.0随着Windows Vista和Windows Server 20 ...

  9. VMware 虚拟机安装CentOS镜像详细步骤

    CentOS目前官网提供的下载版本有6.7.8,最新的版本为8,不过个人推荐CentOS 7 的版本,因为相比较于最新版本,版本7更加地稳定.而相比于版本6,版本7新增了很多的功能.CentOS 7 ...

  10. 编写一个kubernetes controller

    Overview 根据Kuberneter文档对Controller的描述,Controller在kubernetes中是负责协调的组件,根据设计模式可知,controller会不断的你的对象(如Po ...