文章目录

  • 安装
    • 下载Yum存储库
    • 安装发布包
    • 导入密钥
    • 安装MySQL
  • 启动MySQL
    • 查看临时口令
    • 登录并修改口令
  • 安装MySQL Shell
  • InnoDB Cluster 账户配置
    • 服务器配置账户
    • 集群管理员帐户
    • Router帐户
  • 创建InnoDB Cluster集群
    • 检查实例
    • 配置集群
    • 创建集群
    • 查看集群状态
    • 添加实例
  • 配置Router
  • 启动Router
  • 故障转移测试

安装

下载Yum存储库

wget https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm

安装发布包

yum install -y mysql80-community-release-el7-6.noarch.rpm

导入密钥

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

安装MySQL

sudo yum install -y mysql-community-server

启动MySQL

systemctl start mysqld

查看临时口令

grep 'temporary password' /var/log/mysqld.log

登录并修改口令

mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY '12345678';

安装MySQL Shell

sudo yum install -y mysql-shell

InnoDB Cluster 账户配置

服务器配置账户

mysql> create user root@'%' identified by '12345678';
mysql> grant all privileges on * to 'root'@'%';
mysql> flush privileges;

配置集群管理权限

GRANT CLONE_ADMIN, CONNECTION_ADMIN, CREATE USER, EXECUTE, FILE, GROUP_REPLICATION_ADMIN, PERSIST_RO_VARIABLES_ADMIN, PROCESS, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, REPLICATION_APPLIER, REPLICATION_SLAVE_ADMIN, ROLE_ADMIN, SELECT, SHUTDOWN, SYSTEM_VARIABLES_ADMIN ON *.* TO 'root'@'%' WITH GRANT OPTION;
GRANT DELETE, INSERT, UPDATE ON mysql.* TO 'root'@'%' WITH GRANT OPTION;
GRANT ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, INDEX, INSERT, LOCK TABLES, REFERENCES, SHOW VIEW, TRIGGER, UPDATE ON mysql_innodb_cluster_metadata.* TO 'root'@'%' WITH GRANT OPTION;
GRANT ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, INDEX, INSERT, LOCK TABLES, REFERENCES, SHOW VIEW, TRIGGER, UPDATE ON mysql_innodb_cluster_metadata_bkp.* TO 'root'@'%' WITH GRANT OPTION;
GRANT ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, INDEX, INSERT, LOCK TABLES, REFERENCES, SHOW VIEW, TRIGGER, UPDATE ON mysql_innodb_cluster_metadata_previous.* TO 'root'@'%' WITH GRANT OPTION;

集群管理员帐户

创建集群后通过函数创建集群管理员帐户:

 MySQL  192.168.2.201:3306 ssl  mysql  JS > cluster.setupAdminAccount('clusterAdmin');Missing the password for new account clusterAdmin@%. Please provide one.
Password for new account: ********
Confirm password: ********Creating user clusterAdmin@%.
Account clusterAdmin@% was successfully created.

Router帐户

 MySQL  192.168.2.201:3306 ssl  mysql  JS > cluster.setupRouterAccount('routerUser1')Missing the password for new account routerUser1@%. Please provide one.
Password for new account: ********
Confirm password: ********Creating user routerUser1@%.
Account routerUser1@% was successfully created.

创建InnoDB Cluster集群

检查实例

dba.checkInstanceConfiguration('root@192.168.2.201:3306')

配置集群

 MySQL  localhost:33060+ ssl  JS > dba.configureInstance('root@192.168.2.201:3306');
Configuring local MySQL instance listening at port 3306 for use in an InnoDB cluster...This instance reports its own address as node1: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.applierWorkerThreads will be set to the default value of 4.The instance 'node1:3306' is valid to be used in an InnoDB cluster.
The instance 'node1:3306' is already ready to be used in an InnoDB cluster.Successfully enabled parallel appliers.

创建集群

 MySQL  192.168.2.201:3306 ssl  mysql  JS > var cluster = dba.createCluster('testCluster')
A new InnoDB Cluster will be created on instance 'node1:3306'.Validating instance configuration at 192.168.2.201:3306...This instance reports its own address as node1:3306Instance configuration is suitable.
NOTE: Group Replication will communicate with other members using 'node1:3306'. Use the localAddress option to override.Creating InnoDB Cluster 'testCluster' on 'node1: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  192.168.2.201:3306 ssl  mysql  JS > cluster.status()
{"clusterName": "testCluster", "defaultReplicaSet": {"name": "default", "primary": "node1:3306", "ssl": "REQUIRED", "status": "OK_NO_TOLERANCE", "statusText": "Cluster is NOT tolerant to any failures.", "topology": {"node1:3306": {"address": "node1:3306", "memberRole": "PRIMARY", "mode": "R/W", "readReplicas": {}, "replicationLag": "applier_queue_applied", "role": "HA", "status": "ONLINE", "version": "8.0.30"}}, "topologyMode": "Single-Primary"}, "groupInformationSourceMember": "node1:3306"
}

添加实例

 MySQL  192.168.2.201:3306 ssl  mysql  JS > cluster.addInstance('root@192.168.2.202:3306')NOTE: The target instance 'node2:3306' has not been pre-provisioned (GTID set is empty). The Shell is unable to decide whether incremental state recovery can correctly provision it.
The safest and most convenient way to provision a new instance is through automatic clone provisioning, which will completely overwrite the state of 'node2:3306' with a physical snapshot from an existing cluster member. To use this method by default, set the 'recoveryMethod' option to 'clone'.The incremental 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'.Please select a recovery method [C]lone/[I]ncremental recovery/[A]bort (default Clone): C
Validating instance configuration at 192.168.2.202:3306...This instance reports its own address as node2:3306Instance configuration is suitable.
NOTE: Group Replication will communicate with other members using 'node2:3306'. 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: node2:3306 is being cloned from node1:3306
** Stage DROP DATA: Completed
** Clone Transfer  FILE COPY  ############################################################  100%  CompletedPAGE COPY  ############################################################  100%  CompletedREDO COPY  ############################################################  100%  CompletedNOTE: node2:3306 is shutting down...* Waiting for server restart... ready
* node2:3306 has restarted, waiting for clone to finish...
** Stage RESTART: Completed
* Clone process has finished: 72.61 MB transferred in 3 sec (24.20 MB/s)State recovery already finished for 'node2:3306'The instance 'node2:3306' was successfully added to the cluster.

配置Router

[root@node1 mysql8.0]# mysqlrouter --bootstrap root@192.168.2.201:3306 --account=mysqlrouter --user=root
Please enter MySQL password for root:
# Bootstrapping system MySQL Router instance...Please enter MySQL password for mysqlrouter:
- Creating account(s) (only those that are needed, if any)
- Verifying account (using it to run SQL queries that would be run by Router)
- Storing account in keyring
- Adjusting permissions of generated files
- Creating configuration /etc/mysqlrouter/mysqlrouter.confExisting configuration backed up to '/etc/mysqlrouter/mysqlrouter.conf.bak'# MySQL Router configured for the InnoDB Cluster 'testCluster'After this MySQL Router has been started with the generated configuration$ /etc/init.d/mysqlrouter restart
or$ systemctl start mysqlrouter
or$ mysqlrouter -c /etc/mysqlrouter/mysqlrouter.confInnoDB Cluster 'testCluster' can be reached by connecting to:## MySQL Classic protocol- Read/Write Connections: localhost:6446
- Read/Only Connections:  localhost:6447## MySQL X protocol- Read/Write Connections: localhost:6448
- Read/Only Connections:  localhost:6449

启动Router

mysqlrouter -c /tmp/myrouter/mysqlrouter.conf

故障转移测试

停用node1实例

systemctl stop mysqld

查看node2日志

2022-09-03T05:36:49.419627Z 0 [Warning] [MY-011499] [Repl] Plugin group_replication reported: 'Members removed from the group: node1:3306'
2022-09-03T05:36:49.419648Z 0 [System] [MY-011500] [Repl] Plugin group_replication reported: 'Primary server with address node1:3306 left the group. Electing new Primary.'
2022-09-03T05:36:49.420017Z 0 [System] [MY-011507] [Repl] Plugin group_replication reported: 'A new primary with address node2:3306 was elected. The new primary will execute all previous group transactions before allowing writes.'
2022-09-03T05:36:49.420363Z 0 [System] [MY-011503] [Repl] Plugin group_replication reported: 'Group membership changed to node2:3306, node3:3306 on view 16620968151373714:14.'
2022-09-03T05:36:49.422096Z 19 [System] [MY-013731] [Repl] Plugin group_replication reported: 'The member action "mysql_disable_super_read_only_if_primary" for event "AFTER_PRIMARY_ELECTION" with priority "1" will be run.'
2022-09-03T05:36:49.422301Z 19 [System] [MY-011566] [Repl] Plugin group_replication reported: 'Setting super_read_only=OFF.'
2022-09-03T05:36:49.422341Z 19 [System] [MY-013731] [Repl] Plugin group_replication reported: 'The member action "mysql_start_failover_channels_if_primary" for event "AFTER_PRIMARY_ELECTION" with priority "10" will be run.'
2022-09-03T05:36:49.423681Z 7439 [System] [MY-011510] [Repl] Plugin group_replication reported: 'This server is working as primary member.'

查看集群状态

 MySQL  node2:33060+ ssl  JS > cluster.status()
{"clusterName": "testCluster", "defaultReplicaSet": {"name": "default", "primary": "node2:3306", "ssl": "REQUIRED", "status": "OK_NO_TOLERANCE_PARTIAL", "statusText": "Cluster is NOT tolerant to any failures. 1 member is not active.", "topology": {"node1:3306": {"address": "node1:3306", "memberRole": "SECONDARY", "mode": "n/a", "readReplicas": {}, "role": "HA", "shellConnectError": "MySQL Error 2003: Could not open connection to 'node1:3306': Can't connect to MySQL server on 'node1:3306' (111)", "status": "(MISSING)"}, "node2:3306": {"address": "node2:3306", "memberRole": "PRIMARY", "mode": "R/W", "readReplicas": {}, "replicationLag": "applier_queue_applied", "role": "HA", "status": "ONLINE", "version": "8.0.30"}, "node3:3306": {"address": "node3:3306", "memberRole": "SECONDARY", "mode": "R/O", "readReplicas": {}, "replicationLag": "applier_queue_applied", "role": "HA", "status": "ONLINE", "version": "8.0.30"}}, "topologyMode": "Single-Primary"}, "groupInformationSourceMember": "node2:3306"
}

此时无法检测node1的状态,且整个集群的状态为OK_NO_TOLERANCE_PARTIAL,即无法容忍再发生故障了。

重新启动node1实例

systemctl start mysqld

查看集群状态

 MySQL  node2:33060+ ssl  JS > cluster.status()
{"clusterName": "testCluster", "defaultReplicaSet": {"name": "default", "primary": "node2:3306", "ssl": "REQUIRED", "status": "OK", "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.", "topology": {"node1:3306": {"address": "node1:3306", "memberRole": "SECONDARY", "mode": "R/O", "readReplicas": {}, "replicationLag": "applier_queue_applied", "role": "HA", "status": "ONLINE", "version": "8.0.30"}, "node2:3306": {"address": "node2:3306", "memberRole": "PRIMARY", "mode": "R/W", "readReplicas": {}, "replicationLag": "applier_queue_applied", "role": "HA", "status": "ONLINE", "version": "8.0.30"}, "node3:3306": {"address": "node3:3306", "memberRole": "SECONDARY", "mode": "R/O", "readReplicas": {}, "replicationLag": "applier_queue_applied", "role": "HA", "status": "ONLINE", "version": "8.0.30"}}, "topologyMode": "Single-Primary"}, "groupInformationSourceMember": "node2:3306"
}

此时集群状态为OK,但node1是作为只读实例加入到集群。

MySQL InnoDB Cluster部署相关推荐

  1. Mysql InnoDB Cluster部署装配

    Mysql集群安装 参考官网:https://dev.mysql.com/doc/refman/5.7/en/mysql-innodb-cluster-userguide.html 环境简介: 四台虚 ...

  2. mysql高可靠部署_可能是我见过最好的 MySQL 高可用解决方案 MySQL InnoDB Cluster 中文教程!...

    公众号关注 「运维之美」设为「星标」,每天带你玩转 Linux ! 这篇文章将详细地介绍 MySQL 的高可用解决方案-- MySQL InnoDB Cluster. 说到高可用性,首先要了解一下什么 ...

  3. MySQL InnoDB Cluster

    Mysql高可用环境的搭建比较麻烦,而且之前的那种mysql cluster使用的是内存式存储引擎,一旦断电就会灰飞烟灭,数据丢失. 自从mysql被oracle收购后,新版本发布频繁,推出了很多好用 ...

  4. MySQL NDB Cluster部署方案与实践

    MySQL Cluster集群 一.概述 ​ MySQL Cluster是MySQL适用于分布式计算环境的高实用.高冗余版本.他采用了NDB Cluster存储引擎,允许在一个Cluster中运行多个 ...

  5. MySQL InnoDB Cluster安装

    环境说明 centos 7.x 64位 mysql 5.7.20 编译源码安装 mysql shell linux generic版本 mysql router linux generic版本 路由节 ...

  6. MySQL高可用架构InnoDB Cluster (和NDB Cluster是两码事)

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

  7. innodb 集群_部署MySQL InnoDB集群以实现高可用性

    innodb 集群 In this article, I am going to explain how we can deploy the MySQL InnoDB cluster. InnoDB ...

  8. 技术分享 | InnoDB Cluster+GreatSQL快速部署MGR集群,并实现读写分离和故障自动转移(超详细)...

    本文来源:原创投稿 * GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 0. 内容提纲 1. 部署环境及初始化 2. 利用MySQL Shell构建MGR集群 3. 对在 ...

  9. 初探mysql innodb集群_MySQL InnoDB Cluster搭建

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

最新文章

  1. asp.net 用户控件
  2. 计算机网络word文档,计算机网络word.doc
  3. 端口镜像 流量过滤_技术盛宴 | 流量可视化之ERSPAN的前世今生
  4. JVM GC性能方面的考虑(吞吐量和STW)
  5. PHP安全基础第一章
  6. Android Studio Gradle 问题 解决方案
  7. 家用简单电线路图_家庭配电箱接线图解 家用配电箱安装方法
  8. [C++STL]list容器用法介绍
  9. ssl初一组周六模拟赛【2018.5.19】
  10. c语言程序设计电大作业,2018年最新电大C语言程序设计作业答案.doc
  11. 《RxJava 2.x 实战》— 技术书籍
  12. Centos6.5 x86_64系统安装kvm虚拟机—基础篇
  13. iptv鉴权 php,[转]关于openwrt用于dhcp客户端协议突破iptv的dhcp+鉴权(ipoe)
  14. 如何用c语言编码判断质数,如何用C语言筛选法判断质数
  15. 51单片机入门(第二讲)
  16. java验证码提交错误时_验证码输入错误后自动刷新验证码
  17. 一级建造师考试备考各科知识点记忆技巧
  18. 视频教程-C/C++黑客编程入门教学视频-C/C++
  19. MOOS-ivp 实验四 MOOS编程入门(2)MOOS类讲解
  20. 现在买笔记本电脑要注意哪些方面? 哪些比较好?

热门文章

  1. 深度解密Go语言之关于 interface 的 10 个问题
  2. 用java下载apk解析包出错_Android 9.0 安装包解析错误 java.lang.SecurityException: Permission Denial解决方案...
  3. ElasticSearch 文档检索、查询建议、数据聚合
  4. 天宝水准仪DINI数据传输遇到问题
  5. 第二章 四部和声的基本要求
  6. XML中配置网易云歌手详情滑动效果
  7. Matlab算法之优化计算1
  8. final修饰符,修饰的变量、方法、类、还有一些相关注意事项
  9. Vue3的组件开发大法不完全指北
  10. 如何在VMware Workstation虚拟机上安装苹果系统(Mac OS)