MySQL InnoDB Cluster 高可用集群部署

MySQL InnoDB Cluster 简介

官方文档:https://dev.mysql.com/doc/refman/8.4/en/mysql-innodb-cluster-introduction.html

本章介绍 MySQL InnoDB Cluster,它结合了 MySQL 技术,使您能够部署和管理完整的 MySQL 集成高可用性解决方案。

说明:InnoDB Cluster 不提供对 MySQL NDB Cluster 的支持。

InnoDB Cluster至少由三个MySQL Server实例组成,它提供高可用性和扩展功能。 InnoDB Cluster 使用以下 MySQL 技术:

  • MySQL Shell,它是 MySQL 的高级客户端和代码编辑器。
  • MySQL server 和 Group Replication,,使一组MySQL实例能够提供高可用性。 InnoDB Cluster 提供了一种替代的、易于使用的编程方式来使用组复制。
  • MySQL Router,一种轻量级中间件,可在应用程序和 InnoDB Cluster 之间提供透明路由。

下图显示了这些技术如何协同工作的概述:
在这里插入图片描述

基于MySQL Group Replication 构建,提供自动成员管理、容错、自动故障转移等功能。 InnoDB Cluster通常以单主模式运行,具有一个主实例(读写)和多个辅助实例(只读)。高级用户还可以利用多主模式,其中所有实例都是主实例。您甚至可以在 InnoDB Cluster 在线时更改集群的拓扑,以确保尽可能高的可用性。

集群部署节点规划

必须部署至少三台MySQL服务器,用于mysql innodb节点,至少一台MySQL Router服务器。

本示例使用7台虚拟机进行部署。部署架构如下图所示:

在这里插入图片描述

节点规划清单如下:

HostIP操作系统角色
mysql-innodb01192.168.72.50Ubuntu 22.04mysql innodb/mysql shell
mysql-innodb02192.168.72.51Ubuntu 22.04mysql innodb/mysql shell
mysql-innodb03192.168.72.52Ubuntu 22.04mysql innodb/mysql shell
mysql-router01192.168.72.41Ubuntu 22.04mysql router/mysql client
mysql-router02192.168.72.42Ubuntu 22.04mysql router/mysql client
lb01192.168.72.33Ubuntu 22.04haproxy/keepalived
lb02192.168.72.34Ubuntu 22.04haproxy/keepalived
mysql-db-vip192.168.72.200N/AN/A

以下操作在所有mysql-router节点及mysql-innodb节点执行。

分别在每个节点配置主机名

hostnamectl set-hostname mysql-innodb01
hostnamectl set-hostname mysql-innodb02
hostnamectl set-hostname mysql-innodb03
hostnamectl set-hostname mysql-router01
hostnamectl set-hostname mysql-router02

分别在每个节点配置hosts解析

cat << EOF > /etc/hosts
192.168.72.41 mysql-router01 mysql-router02
192.168.72.42 mysql-router02 mysql-router02
192.168.72.50 mysql-innodb01 mysql-innodb01
192.168.72.51 mysql-innodb02 mysql-innodb02
192.168.72.52 mysql-innodb03 mysql-innodb03
EOF

添加mysql官方软件源

下载地址:https://dev.mysql.com/downloads/repo/apt/

wget https://repo.mysql.com//mysql-apt-config_0.8.30-1_all.deb
dpkg -i mysql-apt-config_0.8.30-1_all.deb
apt update -y

安装innodb集群

以下操作在所有innodb节点执行。

在安装过程中,您需要为MySQL root用户设置密码。

apt update -y
apt install -y mysql-server mysql-shell

查看安装版本

root@mysql-innodb01:~# mysql -V
mysql  Ver 8.0.37 for Linux on x86_64 (MySQL Community Server - GPL)root@mysql-innodb01:~# mysqlsh -V
mysqlsh   Ver 8.0.37 for Linux on x86_64 - for MySQL 8.0.37 (MySQL Community Server (GPL))

在innodb01节点执行

连接到mysql-shell

root@mysql-innodb01:~# mysqlsh

连接到数据库,输入数据库root用户密码

 MySQL  SQL > \connect root@localhost
Creating a session to 'root@localhost'
Please provide the password for 'root@localhost': ************
Save password for 'root@localhost'? [Y]es/[N]o/Ne[v]er (default No): y
Fetching global names for auto-completion... Press ^C to stop.
Your MySQL connection id is 13 (X protocol)
Server version: 8.4.0 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.MySQL  localhost:33060+ ssl  SQL > 

或者直接连接

mysqlsh -uroot -pMysql@123456 -h localhost

查看数据库信息

 MySQL  localhost:33060+ ssl  SQL > \sqlMySQL  localhost:33060+ ssl  SQL > show schemas;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.0011 sec)

或者切换到JS模式

 MySQL  localhost:33060+ ssl  SQL > \js
Switching to JavaScript mode...MySQL  localhost:33060+ ssl  JS > 
MySQL  localhost:33060+ ssl  JS > \sql show schemas;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.0011 sec)MySQL  localhost:33060+ ssl  JS > 

为innodb集群创建独立账号icadmin,密码为icadminPassw0rd!

MySQL  localhost:33060+ ssl  JS > dba.configureInstance()
Configuring local MySQL instance listening at port 3306 for use in an InnoDB Cluster...This instance reports its own address as innodb01: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.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) CancelPlease select an option [1]: 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: icadmin
Password for new account: icadmin
Confirm password: ***********applierWorkerThreads will be set to the default value of 4.NOTE: Some configuration options need to be fixed:
+--------------------------+---------------+----------------+--------------------------------------------------+
| Variable                 | Current Value | Required Value | Note                                             |
+--------------------------+---------------+----------------+--------------------------------------------------+
| enforce_gtid_consistency | OFF           | ON             | Update read-only variable and restart the server |
| gtid_mode                | OFF           | ON             | Update read-only variable and restart the server |
| server_id                | 1             | <unique ID>    | Update read-only variable and restart the server |
+--------------------------+---------------+----------------+--------------------------------------------------+Some variables need to be changed, but cannot be done dynamically on the server.
Do you want to perform the required configuration changes? [y/n]: y
Do you want to restart the instance after configuring it? [y/n]: yCreating user icadmin
@%.
Account icadmin@% was successfully created.Configuring instance...
The instance 'mysql-innodb01:3306' was configured to be used in an InnoDB Cluster.
Restarting MySQL...
NOTE: MySQL server at mysql-innodb01:3306 was restarted.MySQL  localhost:33060+ ssl  JS > 

或者使用以下命令

 MySQL  localhost:33060+ ssl  JS > dba.configureInstance('root@localhost:3306', {clusterAdmin: "'icadmin'@'%'", clusterAdminPassword: 'icadminPassw0rd!'});

查看数据库信息,查看本节点数据库实例Uptime参数,确认已重启

 MySQL  localhost:33060+ ssl  JS > \sql
Switching to SQL mode... Commands end with ;MySQL  localhost:33060+ ssl  SQL > \s
MySQL Shell version 8.4.0Error Retrieving Status:      MySQL Error 2006: MySQL server has gone away
The global session got disconnected..
Attempting to reconnect to 'mysqlx://root@localhost:33060'..
The global session was successfully reconnected.MySQL  localhost:33060+ ssl  SQL > MySQL  localhost:33060+ ssl  SQL > \s
MySQL Shell version 8.4.0Connection Id:                9
Default schema:               
Current schema:               
Current user:                 root@localhost
SSL:                          Cipher in use: TLS_AES_128_GCM_SHA256 TLSv1.3
Using delimiter:              ;
Server version:               8.4.0 MySQL Community Server - GPL
Protocol version:             X protocol
Client library:               8.4.0
Connection:                   localhost via TCP/IP
TCP port:                     33060
Server characterset:          utf8mb4
Schema characterset:          utf8mb4
Client characterset:          utf8mb4
Conn. characterset:           utf8mb4
Result characterset:          utf8mb4
Compression:                  Enabled (DEFLATE_STREAM)
Uptime:                       2 min 55.0000 sec

查看gtid_mode 已启用

 MySQL  localhost:33060+ ssl  SQL > \js
Switching to JavaScript mode...MySQL  localhost:33060+ ssl  JS > \sql select  @@gtid_mode, @@server_id
+-------------+-------------+
| @@gtid_mode | @@server_id |
+-------------+-------------+
| ON          |  2728360213 |
+-------------+-------------+
1 row in set (0.0007 sec)

查看生成的mysqld-auto.cnf配置文件

root@innodb01:~# cat /var/lib/mysql/mysqld-auto.cnf 

其中确认参数如下

gtid_mode": {"Value": "ON"
server_id": {"Value": "2728360213

重新连接到集群账号

root@mysql-innodb01:~# fgMySQL  localhost:33060+ ssl  JS > \connect icadmin@localhost
Creating a session to 'icadmin@localhost'
Please provide the password for 'icadmin@localhost': **********
Save password for 'icadmin@localhost'? [Y]es/[N]o/Ne[v]er (default No): y
Fetching schema names for auto-completion... Press ^C to stop.
Closing old connection...
Your MySQL connection id is 12 (X protocol)
Server version: 8.4.0 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.

检查实例配置,确认status参数为ok。

 MySQL  localhost:33060+ ssl  JS > dba.checkInstanceConfiguration()
Validating local MySQL instance listening at port 3306 for use in an InnoDB Cluster...This instance reports its own address as innodb01: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 detectedChecking instance configuration...
Instance configuration is compatible with InnoDB clusterThe instance 'mysql-innodb01:3306' is valid for InnoDB Cluster usage.{"status": "ok"
}MySQL  localhost:33060+ ssl  JS > 

连接到innodb02

连接到mysql-shell

root@mysql-innodb02:~# mysqlsh
MySQL Shell 8.4.0Copyright (c) 2016, 2024, 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 '\?' for help; '\quit' to exit.MySQL  JS > 

连接到数据库

 MySQL  SQL > \connect root@localhost
Creating a session to 'root@localhost'
Please provide the password for 'root@localhost': ************
Save password for 'root@localhost'? [Y]es/[N]o/Ne[v]er (default No): y
Fetching global names for auto-completion... Press ^C to stop.
Your MySQL connection id is 9 (X protocol)
Server version: 8.4.0 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.MySQL  localhost:33060+ ssl  SQL > 

为innodb集群创建独立账号icadmin,密码为icadminPassw0rd!

 MySQL  localhost:33060+ ssl  SQL > \js
Switching to JavaScript mode...MySQL  localhost:33060+ ssl  JS > dba.configureInstance()
Configuring local MySQL instance listening at port 3306 for use in an InnoDB Cluster...This instance reports its own address as innodb02: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.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) CancelPlease select an option [1]: 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: icadmin
Password for new account: ************
Confirm password: ************applierWorkerThreads will be set to the default value of 4.NOTE: Some configuration options need to be fixed:
+--------------------------+---------------+----------------+--------------------------------------------------+
| Variable                 | Current Value | Required Value | Note                                             |
+--------------------------+---------------+----------------+--------------------------------------------------+
| enforce_gtid_consistency | OFF           | ON             | Update read-only variable and restart the server |
| gtid_mode                | OFF           | ON             | Update read-only variable and restart the server |
| server_id                | 1             | <unique ID>    | Update read-only variable and restart the server |
+--------------------------+---------------+----------------+--------------------------------------------------+Some variables need to be changed, but cannot be done dynamically on the server.
Do you want to perform the required configuration changes? [y/n]: y
Do you want to restart the instance after configuring it? [y/n]: yCreating user icadmin@%.
Account icadmin@% was successfully created.Configuring instance...
The instance 'mysql-innodb02:3306' was configured to be used in an InnoDB Cluster.
Restarting MySQL...
NOTE: MySQL server at mysql-innodb02:3306 was restarted.MySQL  localhost:33060+ ssl  JS > 

连接到集群账号

 MySQL  localhost:33060+ ssl  JS > \connect icadmin@localhost
Creating a session to 'icadmin@localhost'
Please provide the password for 'icadmin@localhost': ************
Save password for 'ic@localhost'? [Y]es/[N]o/Ne[v]er (default No): y
Fetching schema names for auto-completion... Press ^C to stop.
Closing old connection...
Your MySQL connection id is 9 (X protocol)
Server version: 8.4.0 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.

检查实例

 MySQL  localhost:33060+ ssl  JS > dba.checkInstanceConfiguration()
Validating local MySQL instance listening at port 3306 for use in an InnoDB Cluster...This instance reports its own address as mysql-innodb02: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 detectedChecking instance configuration...
Instance configuration is compatible with InnoDB clusterThe instance 'mysql-innodb02:3306' is valid for InnoDB Cluster usage.{"status": "ok"
}MySQL  localhost:33060+ ssl  JS > 

连接到innodb03

root@innodb03:~# mysqlsh
MySQL Shell 8.4.0Copyright (c) 2016, 2024, 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 '\?' for help; '\quit' to exit.

连接到数据库账号

 MySQL  SQL > \connect root@localhost
Creating a session to 'root@localhost'
Please provide the password for 'root@localhost': ************
Save password for 'root@localhost'? [Y]es/[N]o/Ne[v]er (default No): y
Fetching global names for auto-completion... Press ^C to stop.
Your MySQL connection id is 9 (X protocol)
Server version: 8.4.0 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.MySQL  localhost:33060+ ssl  SQL > 

为innodb集群创建独立账号icadmin,密码为icadminPassw0rd!

 MySQL  localhost:33060+ ssl  SQL > \js
Switching to JavaScript mode...MySQL  localhost:33060+ ssl  JS > dba.configureInstance()
Configuring local MySQL instance listening at port 3306 for use in an InnoDB Cluster...This instance reports its own address as mysql-innodb03: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.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) CancelPlease select an option [1]: 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: ic
Password for new account: **********
Confirm password: *********applierWorkerThreads will be set to the default value of 4.NOTE: Some configuration options need to be fixed:
+--------------------------+---------------+----------------+--------------------------------------------------+
| Variable                 | Current Value | Required Value | Note                                             |
+--------------------------+---------------+----------------+--------------------------------------------------+
| enforce_gtid_consistency | OFF           | ON             | Update read-only variable and restart the server |
| gtid_mode                | OFF           | ON             | Update read-only variable and restart the server |
| server_id                | 1             | <unique ID>    | Update read-only variable and restart the server |
+--------------------------+---------------+----------------+--------------------------------------------------+Some variables need to be changed, but cannot be done dynamically on the server.
Do you want to perform the required configuration changes? [y/n]: y
Do you want to restart the instance after configuring it? [y/n]: yCreating user icadmin@%.
Account icadmin@% was successfully created.Configuring instance...
The instance 'mysql-innodb03:3306' was configured to be used in an InnoDB Cluster.
Restarting MySQL...
NOTE: MySQL server at mysql-innodb03:3306 was restarted.MySQL  localhost:33060+ ssl  JS > 

连接到集群账号

 MySQL  localhost:33060+ ssl  JS > \connect icadmin@localhost
Creating a session to 'icadmin@localhost'
Please provide the password for 'icadmin@localhost': **
Save password for 'icadmin@localhost'? [Y]es/[N]o/Ne[v]er (default No): y
Fetching schema names for auto-completion... Press ^C to stop.
Closing old connection...
Your MySQL connection id is 9 (X protocol)
Server version: 8.4.0 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.

检查实例

 MySQL  localhost:33060+ ssl  JS > dba.checkInstanceConfiguration()
Validating local MySQL instance listening at port 3306 for use in an InnoDB Cluster...This instance reports its own address as mysql-innodb03: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 detectedChecking instance configuration...
Instance configuration is compatible with InnoDB clusterThe instance 'mysql-innodb03:3306' is valid for InnoDB Cluster usage.{"status": "ok"
}MySQL  localhost:33060+ ssl  JS > 

创建innodb集群

以下所有操作在innodb01节点执行

 MySQL  localhost:33060+ ssl  JS > dba.createCluster('my_innodb_cluster')
A new InnoDB Cluster will be created on instance 'mysql-innodb01:3306'.Validating instance configuration at localhost:3306...This instance reports its own address as innodb01:3306Instance configuration is suitable.
NOTE: Group Replication will communicate with other members using 'mysql-innodb01:3306'. Use the localAddress option to override.* Checking connectivity and SSL configuration...Creating InnoDB Cluster 'my_innodb_cluster' on 'innodb01: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.<Cluster:my_innodb_cluster>MySQL  localhost:33060+ ssl  JS > 

查看集群状态

 MySQL  localhost:33060+ ssl  JS > dba.getCluster()
<Cluster:my_innodb_cluster>MySQL  localhost:33060+ ssl  JS > herc = dba.getCluster()
<Cluster:my_innodb_cluster>MySQL  localhost:33060+ ssl  JS > herc.status()
{"clusterName": "my_innodb_cluster", "defaultReplicaSet": {"name": "default", "primary": "mysql-innodb01:3306", "ssl": "REQUIRED", "status": "OK_NO_TOLERANCE", "statusText": "Cluster is NOT tolerant to any failures.", "topology": {"innodb01:3306": {"address": "mysql-innodb01:3306", "memberRole": "PRIMARY", "mode": "R/W", "readReplicas": {}, "replicationLag": "applier_queue_applied", "role": "HA", "status": "ONLINE", "version": "8.4.0"}}, "topologyMode": "Single-Primary"}, "groupInformationSourceMember": "mysql-innodb01:3306"
}MySQL  localhost:33060+ ssl  JS > 

添加innodb02节点到集群

 MySQL  localhost:33060+ ssl  JS > herc.addInstance('icadmin@mysql-innodb02')NOTE: The target instance 'mysql-innodb02: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 'innodb02: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 innodb02:3306...This instance reports its own address as innodb02:3306Instance configuration is suitable.
NOTE: Group Replication will communicate with other members using 'mysql-innodb02:3306'. Use the localAddress option to override.* Checking connectivity and SSL configuration...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: innodb02:3306 is being cloned from innodb01:3306
** Stage DROP DATA: Completed
** Clone Transfer  FILE COPY  ############################################################  100%  CompletedPAGE COPY  ############################################################  100%  CompletedREDO COPY  ############################################################  100%  CompletedNOTE: innodb02:3306 is shutting down...* Waiting for server restart... ready 
* innodb02:3306 has restarted, waiting for clone to finish...
** Stage RESTART: Completed
* Clone process has finished: 74.14 MB transferred in about 1 second (~74.14 MB/s)State recovery already finished for 'mysql-innodb02:3306'The instance 'mysql-innodb02:3306' was successfully added to the cluster.

检查集群状态

 MySQL  localhost:33060+ ssl  JS > herc.status()
{"clusterName": "my_innodb_cluster", "defaultReplicaSet": {"name": "default", "primary": "mysql-innodb01:3306", "ssl": "REQUIRED", "status": "OK_NO_TOLERANCE", "statusText": "Cluster is NOT tolerant to any failures.", "topology": {"innodb01:3306": {"address": "mysql-innodb01:3306", "memberRole": "PRIMARY", "mode": "R/W", "readReplicas": {}, "replicationLag": "applier_queue_applied", "role": "HA", "status": "ONLINE", "version": "8.4.0"}, "innodb02:3306": {"address": "mysql-innodb02:3306", "memberRole": "SECONDARY", "mode": "R/O", "readReplicas": {}, "replicationLag": "applier_queue_applied", "role": "HA", "status": "ONLINE", "version": "8.4.0"}}, "topologyMode": "Single-Primary"}, "groupInformationSourceMember": "mysql-innodb01:3306"
}MySQL  localhost:33060+ ssl  JS > 

在innnodb01节点检查super_read_only参数,只读节点数为0

MySQL  localhost:33060+ ssl  JS > \sql select @@super_read_only;
+-------------------+
| @@super_read_only |
+-------------------+
|                 0 |
+-------------------+
1 row in set (0.0007 sec)

在innnodb02节点检查super_read_only参数,只读节点数为1

 MySQL  localhost:33060+ ssl  JS > \sql select @@super_read_only;
+-------------------+
| @@super_read_only |
+-------------------+
|                 1 |
+-------------------+
1 row in set (0.0004 sec)

添加innodb03节点到集群

 MySQL  localhost:33060+ ssl  JS > herc.addInstance('icadmin@mysql-innodb03')NOTE: The target instance 'mysql-innodb03: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 'mysql-innodb03: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 mysql-innodb03:3306...This instance reports its own address as mysql-innodb03:3306Instance configuration is suitable.
NOTE: Group Replication will communicate with other members using 'mysql-innodb03:3306'. Use the localAddress option to override.* Checking connectivity and SSL configuration...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: mysql-innodb03:3306 is being cloned from mysql-innodb01:3306
** Stage DROP DATA: Completed
** Clone Transfer  FILE COPY  ############################################################  100%  CompletedPAGE COPY  ############################################################  100%  CompletedREDO COPY  ############################################################  100%  CompletedNOTE: innodb03:3306 is shutting down...* Waiting for server restart... ready 
* innodb03:3306 has restarted, waiting for clone to finish...
** Stage RESTART: Completed
* Clone process has finished: 74.41 MB transferred in about 1 second (~74.41 MB/s)State recovery already finished for 'mysql-innodb03:3306'The instance 'mysql-innodb03:3306' was successfully added to the cluster.

查看集群状态

 MySQL  localhost:33060+ ssl  JS > herc.status()
{"clusterName": "my_innodb_cluster", "defaultReplicaSet": {"name": "default", "primary": "mysql-innodb01:3306", "ssl": "REQUIRED", "status": "OK", "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.", "topology": {"mysql-innodb01:3306": {"address": "mysql-innodb01:3306", "memberRole": "PRIMARY", "mode": "R/W", "readReplicas": {}, "replicationLag": "applier_queue_applied", "role": "HA", "status": "ONLINE", "version": "8.4.0"}, "mysql-innodb02:3306": {"address": "mysql-innodb02:3306", "memberRole": "SECONDARY", "mode": "R/O", "readReplicas": {}, "replicationLag": "applier_queue_applied", "role": "HA", "status": "ONLINE", "version": "8.4.0"}, "mysql-innodb03:3306": {"address": "mysql-innodb03:3306", "memberRole": "SECONDARY", "mode": "R/O", "readReplicas": {}, "replicationLag": "applier_queue_applied", "role": "HA", "status": "ONLINE", "version": "8.4.0"}}, "topologyMode": "Single-Primary"}, "groupInformationSourceMember": "innodb01:3306"
}MySQL  localhost:33060+ ssl  JS > 

关键字段如下:

"status": "OK" 表示集群状态是正常的
"topologyMode": "Single-Primary" 表示是单主模式
"mode": "R/W" 表示可读可写
"mode": "R/O" 表示只读

查看库及表

 MySQL  localhost:33060+ ssl  JS > \sql
Switching to SQL mode... Commands end with ;MySQL  localhost:33060+ ssl  SQL > show schemas;
+-------------------------------+
| Database                      |
+-------------------------------+
| information_schema            |
| mysql                         |
| mysql_innodb_cluster_metadata |
| performance_schema            |
| sys                           |
+-------------------------------+
5 rows in set (0.0013 sec)MySQL  localhost:33060+ ssl  SQL > use mysql_innodb_cluster_metadata;
Default schema set to `mysql_innodb_cluster_metadata`.
Fetching global names, object names from `mysql_innodb_cluster_metadata` for auto-completion... Press ^C to stop.MySQL  localhost:33060+ ssl  mysql_innodb_cluster_metadata  SQL > MySQL  localhost:33060+ ssl  mysql_innodb_cluster_metadata  SQL > show tables;
+-----------------------------------------+
| Tables_in_mysql_innodb_cluster_metadata |
+-----------------------------------------+
| async_cluster_members                   |
| async_cluster_views                     |
| clusters                                |
| clusterset_members                      |
| clusterset_views                        |
| clustersets                             |
| instances                               |
| router_rest_accounts                    |
| routers                                 |
| schema_version                          |
| v2_ar_clusters                          |
| v2_ar_members                           |
| v2_clusters                             |
| v2_cs_clustersets                       |
| v2_cs_members                           |
| v2_cs_router_options                    |
| v2_gr_clusters                          |
| v2_instances                            |
| v2_router_options                       |
| v2_router_rest_accounts                 |
| v2_routers                              |
| v2_this_instance                        |
+-----------------------------------------+
22 rows in set (0.0020 sec)MySQL  localhost:33060+ ssl  mysql_innodb_cluster_metadata  SQL > use performance_schema;
Default schema set to `performance_schema`.
Fetching global names, object names from `performance_schema` for auto-completion... Press ^C to stop.MySQL  localhost:33060+ ssl  performance_schema  SQL > show tables;
+------------------------------------------------------+
| Tables_in_performance_schema                         |
+------------------------------------------------------+
| accounts                                             |
| binary_log_transaction_compression_stats             |
| clone_progress                                       |
| clone_status                                         |
| cond_instances                                       |
| data_lock_waits                                      |
| data_locks                                           |
| error_log                                            |
| events_errors_summary_by_account_by_error            |
| events_errors_summary_by_host_by_error               |
| events_errors_summary_by_thread_by_error             |
| events_errors_summary_by_user_by_error               |
| events_errors_summary_global_by_error                |
| events_stages_current                                |
| events_stages_history                                |
| events_stages_history_long                           |
| events_stages_summary_by_account_by_event_name       |
| events_stages_summary_by_host_by_event_name          |
| events_stages_summary_by_thread_by_event_name        |
| events_stages_summary_by_user_by_event_name          |
| events_stages_summary_global_by_event_name           |
| events_statements_current                            |
| events_statements_histogram_by_digest                |
| events_statements_histogram_global                   |
| events_statements_history                            |
| events_statements_history_long                       |
| events_statements_summary_by_account_by_event_name   |
| events_statements_summary_by_digest                  |
| events_statements_summary_by_host_by_event_name      |
| events_statements_summary_by_program                 |
| events_statements_summary_by_thread_by_event_name    |
| events_statements_summary_by_user_by_event_name      |
| events_statements_summary_global_by_event_name       |
| events_transactions_current                          |
| events_transactions_history                          |
| events_transactions_history_long                     |
| events_transactions_summary_by_account_by_event_name |
| events_transactions_summary_by_host_by_event_name    |
| events_transactions_summary_by_thread_by_event_name  |
| events_transactions_summary_by_user_by_event_name    |
| events_transactions_summary_global_by_event_name     |
| events_waits_current                                 |
| events_waits_history                                 |
| events_waits_history_long                            |
| events_waits_summary_by_account_by_event_name        |
| events_waits_summary_by_host_by_event_name           |
| events_waits_summary_by_instance                     |
| events_waits_summary_by_thread_by_event_name         |
| events_waits_summary_by_user_by_event_name           |
| events_waits_summary_global_by_event_name            |
| file_instances                                       |
| file_summary_by_event_name                           |
| file_summary_by_instance                             |
| global_status                                        |
| global_variables                                     |
| host_cache                                           |
| hosts                                                |
| innodb_redo_log_files                                |
| keyring_component_status                             |
| keyring_keys                                         |
| log_status                                           |
| memory_summary_by_account_by_event_name              |
| memory_summary_by_host_by_event_name                 |
| memory_summary_by_thread_by_event_name               |
| memory_summary_by_user_by_event_name                 |
| memory_summary_global_by_event_name                  |
| metadata_locks                                       |
| mutex_instances                                      |
| objects_summary_global_by_type                       |
| performance_timers                                   |
| persisted_variables                                  |
| prepared_statements_instances                        |
| processlist                                          |
| replication_applier_configuration                    |
| replication_applier_filters                          |
| replication_applier_global_filters                   |
| replication_applier_status                           |
| replication_applier_status_by_coordinator            |
| replication_applier_status_by_worker                 |
| replication_asynchronous_connection_failover         |
| replication_asynchronous_connection_failover_managed |
| replication_connection_configuration                 |
| replication_connection_status                        |
| replication_group_communication_information          |
| replication_group_configuration_version              |
| replication_group_member_actions                     |
| replication_group_member_stats                       |
| replication_group_members                            |
| rwlock_instances                                     |
| session_account_connect_attrs                        |
| session_connect_attrs                                |
| session_status                                       |
| session_variables                                    |
| setup_actors                                         |
| setup_consumers                                      |
| setup_instruments                                    |
| setup_meters                                         |
| setup_metrics                                        |
| setup_objects                                        |
| setup_threads                                        |
| socket_instances                                     |
| socket_summary_by_event_name                         |
| socket_summary_by_instance                           |
| status_by_account                                    |
| status_by_host                                       |
| status_by_thread                                     |
| status_by_user                                       |
| table_handles                                        |
| table_io_waits_summary_by_index_usage                |
| table_io_waits_summary_by_table                      |
| table_lock_waits_summary_by_table                    |
| threads                                              |
| tls_channel_status                                   |
| user_defined_functions                               |
| user_variables_by_thread                             |
| users                                                |
| variables_by_thread                                  |
| variables_info                                       |
+------------------------------------------------------+
118 rows in set (0.0031 sec)MySQL  localhost:33060+ ssl  performance_schema  SQL > 

查看replication_group_members

MySQL  localhost:33060+ ssl  performance_schema  SQL > select * from replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+----------------------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST       | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | MEMBER_COMMUNICATION_STACK |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+----------------------------+
| group_replication_applier | 7149de5f-34f4-11ef-91fc-005056aaaba0 | mysql-innodb03    |        3306 | ONLINE       | SECONDARY   | 8.4.0          | MySQL                      |
| group_replication_applier | 7970842a-34f4-11ef-9af0-005056aafb5f | mysql-innodb02    |        3306 | ONLINE       | SECONDARY   | 8.4.0          | MySQL                      |
| group_replication_applier | 8091d83c-34f4-11ef-aac6-005056aa2dba | mysql-innodb01    |        3306 | ONLINE       | PRIMARY     | 8.4.0          | MySQL                      |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+----------------------------+
3 rows in set (0.0010 sec)MySQL  localhost:33060+ ssl  performance_schema  SQL > select CHANNEL_NAME,MEMBER_ID,MEMBER_HOST,MEMBER_STATE,MEMBER_ROLE from replication_group_members;
+---------------------------+--------------------------------------+-------------+--------------+-------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST       | MEMBER_STATE | MEMBER_ROLE |
+---------------------------+--------------------------------------+-------------+--------------+-------------+
| group_replication_applier | 7149de5f-34f4-11ef-91fc-005056aaaba0 | mysql-innodb03    | ONLINE       | SECONDARY   |
| group_replication_applier | 7970842a-34f4-11ef-9af0-005056aafb5f | mysql-innodb02    | ONLINE       | SECONDARY   |
| group_replication_applier | 8091d83c-34f4-11ef-aac6-005056aa2dba | mysql-innodb01    | ONLINE       | PRIMARY     |
+---------------------------+--------------------------------------+-------------+--------------+-------------+
3 rows in set (0.0017 sec)MySQL  localhost:33060+ ssl  performance_schema  SQL > 

至此,3节点mysql innodb集群部署已经完成。

部署mysql-router

安装mysql-router

以下操作在所有mysql-router节点执行

apt install -y mysql-router mysql-client

查看安装版本

root@mysql-router01:~# mysqlrouter -V
MySQL Router  Ver 8.0.37 for Linux on x86_64 (MySQL Community - GPL)root@mysql-router01:~# mysql -V
mysql  Ver 8.0.37 for Linux on x86_64 (MySQL Community Server - GPL)
root@mysql-router01:~# 

修改apparmor配置,末尾添加如下内容

root@mysql-router01:~# nano /etc/apparmor.d/usr.bin.mysqlrouter
......
# Allow directory for MySQL InnoDB cluster/var/lib/mysqlrouter/ rw,/var/lib/mysqlrouter/** rw, 
}

重新加载apparmor服务

systemctl reload apparmor.service 

连接innodb集群

mysqlrouter --bootstrap icadmin@mysql-innodb01:3306 --directory /var/lib/mysqlrouter \
--conf-bind-address 0.0.0.0 --user=mysqlrouter

命令输出示例

root@mysql-router01:~# mysqlrouter --bootstrap ic@innodb01:3306 --directory /var/lib/mysqlrouter --conf-bind-address 0.0.0.0 --user=mysqlrouter --force
Please enter MySQL password for ic: 
# Bootstrapping MySQL Router 8.4.0 (MySQL Community - GPL) instance at '/var/lib/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 /var/lib/mysqlrouter/mysqlrouter.conf# MySQL Router configured for the InnoDB Cluster 'my_innodb_cluster'After this MySQL Router has been started with the generated configuration$ mysqlrouter -c /var/lib/mysqlrouter/mysqlrouter.confInnoDB Cluster 'my_innodb_cluster' can be reached by connecting to:## MySQL Classic protocol- Read/Write Connections: localhost:6446
- Read/Only Connections:  localhost:6447
- Read/Write Split Connections: localhost:6450## MySQL X protocol- Read/Write Connections: localhost:6448
- Read/Only Connections:  localhost:6449

查看监听端口

root@router01:~/data# ss -antulp
Netid            State             Recv-Q            Send-Q                       Local Address:Port                       Peer Address:Port           Process                                               
udp              UNCONN            0                 0                            127.0.0.53%lo:53                              0.0.0.0:*               users:(("systemd-resolve",pid=823,fd=13))            
udp              UNCONN            0                 0                                127.0.0.1:323                             0.0.0.0:*               users:(("chronyd",pid=865,fd=5))                     
udp              UNCONN            0                 0                                    [::1]:323                                [::]:*               users:(("chronyd",pid=865,fd=6))                     
tcp              LISTEN            0                 4096                         127.0.0.53%lo:53                              0.0.0.0:*               users:(("systemd-resolve",pid=823,fd=14))            
tcp              LISTEN            0                 128                                0.0.0.0:22                              0.0.0.0:*               users:(("sshd",pid=900,fd=3))                        
tcp              LISTEN            0                 128                                   [::]:22                                 [::]:*               users:(("sshd",pid=900,fd=4))  

手动临时启动服务

root@mysql-router01:~# cd /var/lib/mysqlrouter/
root@mysql-router01:/var/lib/mysqlrouter# ./start.sh
root@mysql-router01:/var/lib/mysqlrouter# PID 4310 written to '/var/lib/mysqlrouter/mysqlrouter.pid'
stopping to log to the console. Continuing to log to filelog
^C

重新查看监听端口,mysql router读写端口为6446,mysql router只读端口为6447

root@mysql-router01:/var/lib/mysqlrouter# ss -tulnp
Netid            State             Recv-Q            Send-Q                       Local Address:Port                       Peer Address:Port           Process                                               
udp              UNCONN            0                 0                            127.0.0.53%lo:53                              0.0.0.0:*               users:(("systemd-resolve",pid=823,fd=13))            
udp              UNCONN            0                 0                                127.0.0.1:323                             0.0.0.0:*               users:(("chronyd",pid=865,fd=5))                     
udp              UNCONN            0                 0                                    [::1]:323                                [::]:*               users:(("chronyd",pid=865,fd=6))                     
tcp              LISTEN            0                 1024                               0.0.0.0:6448                            0.0.0.0:*               users:(("mysqlrouter",pid=4310,fd=12))               
tcp              LISTEN            0                 1024                               0.0.0.0:6449                            0.0.0.0:*               users:(("mysqlrouter",pid=4310,fd=14))               
tcp              LISTEN            0                 1024                               0.0.0.0:6450                            0.0.0.0:*               users:(("mysqlrouter",pid=4310,fd=16))               
tcp              LISTEN            0                 4096                         127.0.0.53%lo:53                              0.0.0.0:*               users:(("systemd-resolve",pid=823,fd=14))            
tcp              LISTEN            0                 128                                0.0.0.0:22                              0.0.0.0:*               users:(("sshd",pid=900,fd=3))                        
tcp              LISTEN            0                 128                                0.0.0.0:8443                            0.0.0.0:*               users:(("mysqlrouter",pid=4310,fd=10))               
tcp              LISTEN            0                 1024                               0.0.0.0:6446                            0.0.0.0:*               users:(("mysqlrouter",pid=4310,fd=13))               
tcp              LISTEN            0                 1024                               0.0.0.0:6447                            0.0.0.0:*               users:(("mysqlrouter",pid=4310,fd=15))               
tcp              LISTEN            0                 128                                   [::]:22                                 [::]:*               users:(("sshd",pid=900,fd=4))                        
root@mysql-router01:/var/lib/mysqlrouter#

查看配置文件监听端口

root@mysql-router01:~# cat /var/lib/mysqlrouter/mysqlrouter.conf 
# File automatically generated during MySQL Router bootstrap[routing:bootstrap_rw]
bind_address=0.0.0.0
bind_port=6446
destinations=metadata-cache://my_innodb_cluster/?role=PRIMARY
routing_strategy=first-available
protocol=classic[routing:bootstrap_ro]
bind_address=0.0.0.0
bind_port=6447
destinations=metadata-cache://my_innodb_cluster/?role=SECONDARY
routing_strategy=round-robin-with-fallback
protocol=classic

查看缓存的集群信息

root@mysql-router01:~# cat /var/lib/mysqlrouter/data/state.json 
{"metadata-cache": {"group-replication-id": "806533fa-36ac-11ef-9f9b-005056aaaba0","cluster-metadata-servers": ["mysql://mysql-innodb03:3306","mysql://mysql-innodb02:3306","mysql://mysql-innodb01:3306"]},"version": "1.0.0"
}root@mysql-router01:~# 

禁用默认的systemd服务,配置mysql-router服务开机自启动

systemctl stop mysqlrouter.service
rm -rf /etc/init.d/mysqlrouter
systemctl daemon-reload

新建systemd文件

cat >/etc/systemd/system/mysqlrouter.service<<EOF
[Unit]
Description=MySQL Router
After=network.target
After=syslog.target
[Service]
Type=notify
User=mysqlrouter
Group=mysqlrouter
# Start main service
ExecStart=/usr/bin/mysqlrouter -c /var/lib/mysqlrouter/mysqlrouter.conf --user=mysqlrouter
# Sets open_files_limit
LimitNOFILE = 10000
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF

启动服务

systemctl enable --now mysqlrouter.service

连接数据库

创建示例用户

root@mysql-innodb01:~# mysql -uroot -p
Enter password: mysql> create user app@'%' identified by 'App@123456';
Query OK, 0 rows affected (0.02 sec)mysql> grant all on *.* to app@'%';
Query OK, 0 rows affected (0.02 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)mysql> 

通过mysql-router连接到读写数据库

root@mysql-router01:~# mysql -h127.0.0.1 -P 6446 -u app -p'App@123456'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 0
Server version: 8.4.0-router MySQL Community Server - GPLCopyright (c) 2000, 2024, 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> select @@hostname;
+------------+
| @@hostname |
+------------+
| mysql-innodb01   |
+------------+
1 row in set (0.00 sec)mysql> create database mydb;
Query OK, 1 row affected (0.00 sec)mysql> 

通过mysql-router连接到只读数据库

root@mysql-router01:~# mysql -h127.0.0.1 -P 6447 -u app -p'App@123456'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 0
Server version: 8.4.0-router MySQL Community Server - GPLCopyright (c) 2000, 2024, 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> select @@hostname;
+------------+
| @@hostname |
+------------+
| mysql-innodb02   |
+------------+
1 row in set (0.00 sec)mysql> create database mydb1;
ERROR 1290 (HY000): The MySQL server is running with the --super-read-only option so it cannot execute this statement
mysql> 
mysql> select user, host from mysql.user;
+---------------------------------+-----------+
| user                            | host      |
+---------------------------------+-----------+
| app                             | %         |
| ic                              | %         |
| mysql_innodb_cluster_2444823474 | %         |
| mysql_innodb_cluster_2728360213 | %         |
| mysql_innodb_cluster_3109234783 | %         |
| mysql_router1_d99tpklyj1n3      | %         |
| mysql.infoschema                | localhost |
| mysql.session                   | localhost |
| mysql.sys                       | localhost |
| root                            | localhost |
+---------------------------------+-----------+
10 rows in set (0.00 sec)mysql> \q
Bye

部署负载局衡器

以下操作在所有lb节点执行。

配置主机名

hostnamectl set-hostname lb01
hostnamectl set-hostname lb02

安装haproxy和keepalived

apt install -y haproxy keepalived

创建haproxy配置文件,两个节点配置相同

root@lb01:~# cat /etc/haproxy/haproxy.cfg
# HAProxy Configuration for lb01
globallog /dev/log local0log /dev/log local1 noticechroot /var/lib/haproxystats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listenersstats timeout 30suser haproxygroup haproxydaemondefaultslog globalmode tcpoption tcplogoption dontlognulltimeout connect 5000timeout client 50000timeout server 50000frontend db_rw_frontbind *:6446default_backend db_rw_backbackend db_rw_backbalance roundrobinserver router01 192.168.72.41:6446 checkserver router02 192.168.72.42:6446 checkfrontend db_ro_frontbind *:6447default_backend db_ro_backbackend db_ro_backbalance roundrobinserver router01 192.168.72.41:6447 checkserver router02 192.168.72.42:6447 check

创建keepalived配置文件,两个节点配置相同

root@lb01:~# cat /etc/keepalived/keepalived.conf 
# Keepalived Configuration for lb01
global_defs {router_id 51script_user rootenable_script_security
}vrrp_script check_haproxy {script "/usr/bin/killall -0 haproxy"interval 2fall 2       # require 2 failures for KOrise 2       # require 2 successes for OK
}vrrp_instance db_vip {state BACKUPinterface ens33virtual_router_id 51priority 100nopreemptadvert_int 1authentication {auth_type PASSauth_pass secret456}virtual_ipaddress {192.168.72.200}track_script {check_haproxy}
}

启动服务

systemctl restart keepalived.service
systemctl restart haproxy.service

验证通过VIP连接读写端口

root@mysql-router01:~# mysql -h192.168.72.200 -P 6446 -u app -p'App@123456'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 392427
Server version: 8.0.37 MySQL Community Server - GPLCopyright (c) 2000, 2024, 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> 

验证通过VIP连接只读端口

root@mysql-router01:~# mysql -h192.168.72.200 -P 6447 -u app -p'App@123456'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 71
Server version: 8.0.37 MySQL Community Server - GPLCopyright (c) 2000, 2024, 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> 

集群角色管理

切换为多个Primary模式

 MySQL  localhost:33060+ ssl  JS > herc.switchToMultiPrimaryMode()

切换为单个Primary模式

 MySQL  localhost:33060+ ssl  JS > herc.switchToSinglePrimaryMode()

指定节点切换为Primary模式

 MySQL  localhost:33060+ ssl  JS > herc.setPrimaryInstance('mysql-innodb02')

从集群删除节点

 MySQL  localhost:33060+ ssl  JS > herc.removeInstance('mysql-innodb03')

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/40665.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

科普文:Linux服务器性能调优之CPU调度策略和可调参数

概叙 进程 进程是操作系统虚拟出来的概念&#xff0c;用来组织计算机中的任务。计算机的核心是CPU&#xff0c;它承担了所有的计算任务&#xff1b;而操作系统是计算机的管理者&#xff0c;它负责任务的调度、资源的分配和管理&#xff0c;统领整个计算机硬件&#xff1b;应用…

网络编程:UDP编程笔记

1.字节序的概念和转换 小端格式: 低位字节数据存储在低地址 大端格式: 高位字节数据存储在低地址 在主机上时为小端存储,在网络上时为大端,所以接收到数据时,要转为小端口 如下图: #include <arpa/inet.h> 发送者调用的函数: uint32_t htonl(uint32_t hostlong); //转…

【信息学奥赛】CSP-J/S初赛06 算法基础及时间/空间复杂度等问题

本专栏&#x1f449;CSP-J/S初赛内容主要讲解信息学奥赛的初赛内容&#xff0c;包含计算机基础、初赛常考的C程序和算法以及数据结构&#xff0c;并收集了近年真题以作参考。 如果你想参加信息学奥赛&#xff0c;但之前没有太多C基础&#xff0c;请点击&#x1f449;专栏&#…

AI与学术的交响:ChatGPT辅助下的实验设计新篇章

学境思源&#xff0c;一键生成论文初稿&#xff1a; AcademicIdeas - 学境思源AI论文写作 在学术研究中&#xff0c;实验设计是确保研究质量和结果可信度的关键环节。这篇文章我们将为大家介绍如何利用ChatGPT辅助完成学术论文的实验设计&#xff0c;通过提供灵感、优化实验步…

VUE Pinia状态持久化

效果 实现方法 插件&#xff1a;pinia-plugin-persistedstate 链接地址 具体操作 安装 npm i pinia-plugin-persistedstate 添加到 pinia 实例上 import { createPinia } from pinia import piniaPluginPersistedstate from pinia-plugin-persistedstateconst pinia cre…

K8s 集群(kubeadm) CA 证书过期解决方案

Author&#xff1a;Arsen Date&#xff1a;2024/07/04 目录 一、现象描述二、解决方案三、集群验证 一、现象描述 之前有篇文章《K8s Token 过期解决方案&#xff08;Kubeadm&#xff09;》提到了默认生成的 Token 有效期只有 24 小时&#xff0c;过期后 Token 将不可用&#…

B端系统设计风格简洁与高效的完美融合

B端系统设计风格简洁与高效的完美融合

CIDEr(Consensus-based Image Description Evaluation)的计算

CIDEr&#xff08;Consensus-based Image Description Evaluation&#xff09; 论文原文 CIDEr: Consensus-based Image Description Evaluation CIDEr&#xff08;Consensus-based Image Description Evaluation&#xff09;是一种用于自动评估图像描述&#xff08;image ca…

基于java语言+ Vue+ElementUI+ MySQL8.0.36数字化产科管理平台源码,妇幼信息化整体解决方案

基于java语言 VueElementUI MySQL8.0.36数字化产科管理平台源码&#xff0c;妇幼信息化整体解决方案 数字化产科管理平台是为医院产科量身定制的信息管理系统。它管理了孕妇从怀孕开始到生产结束42天一系列医院保健服务信息。该系统由门诊系统、住院系统、数据统计模块三部分组…

web零碎知识

&nbsp 在html文件中 连续的空格会被认为是一个空格 所以我们需要使用&nbsp来代表空格 &#x3000 把这个当成tab键来使用 我们可以引入js文件&#xff0c;就可以减少html文件的长度。 首先创建一个js文件夹&#xff0c;然后在js文件夹中创建一个&#xff0c;后缀…

数据库表导出到excel:前置知识4 业务和效果

清单配置页面(就是配置那些用户可以下载那些表内容,清单下载实际就是指数据库表下载,清单就是对应的表) 比如:导出一个atom_base_info表数据(数据多) atom_base_info的数据结构 下面这个配置审核状态一类不问&#xff0c;直接到清单下载页面 发起自己想下载的清单(先异步把数…

FreeRTOS之队列上锁和解锁(详解)

这篇文章将记录我学习实时操作系统FreeRTOS的队列上锁和解锁的知识&#xff0c;在此分享给大家&#xff0c;希望我的分享能给你带来不一样的收获&#xff01; 目录 一、简介 二、队列上锁函数prvLockQueue&#xff08;&#xff09; 1、函数初探 2、应用示例 三、队列解锁函…

js之模糊搜索

多的不说 少的不唠 直接上代码

警翼警用记录仪视频格式化后恢复方法

警翼是国内较大的一家警用记录仪厂商&#xff0c;此品牌我们恢复过很多&#xff0c;此次遇到的是一个典型的误格式化的情况&#xff0c;我们来看看误格式化后如何恢复。 故障存储: 32G卡/fat32 故障现象: 客户提供的信息是在交接设备后没有及时备份而做出了初始化设备的操…

养老院管理系统-计算机毕业设计源码00010

养老院管理系统的设计与实现 摘要 本文介绍了一种基于Spring Boot框架的养老院管理系统的设计与实现。该系统旨在帮助养老院管理者更有效地管理机构内的各项事务&#xff0c;并提供更好的服务于老年人。系统的设计考虑了养老院管理的特殊需求&#xff0c;包括系统用户、老人信息…

高二的他已通过NOI保送北大了,让我们一起了解他的信息学奥赛学习经历吧!!!

相信关注本号的各位&#xff0c;对于信息学奥赛已经不陌生了&#xff0c;部分同学也已经开始踏入信息学的旅程&#xff0c;但前路茫茫&#xff0c;让我们一起看看已经取得成就的同学的经历吧。 今天要介绍的这位同学&#xff0c;是来自深圳中学的高二某班的欧阳达晟同学&#x…

简洁纯文字类的Typecho主题wenso

主题介绍 文章说说类博客网站源码&#xff0c;页面清新简洁。适合文章说说美文博客网站建站使用&#xff0c;响应式手机版本。 本来是dedecms的模板&#xff0c;也比较简单&#xff0c;适合用来搭建一个文学类的&#xff0c;纯文字的网站&#xff0c;简单的改成了typecho&…

JVM 堆内存结构 年轻代 老年代

堆内存 内存划分 对于大多数应用&#xff0c;Java 堆是 Java 虚拟机管理的内存中最大的一块&#xff0c;被所有线程共享。此内存区域的唯一目的就是存放对象实例&#xff0c;几乎所有的对象实例以及数据都在这里分配内存。 为了进行高效的垃圾回收&#xff0c;虚拟机把堆内存…

小白 | 华为云docker设置镜像加速器

一、操作场景 通过docker pull命令下载镜像中心的公有镜像时&#xff0c;往往会因为网络原因而需要很长时间&#xff0c;甚至可能因超时而下载失败。为此&#xff0c;容器镜像服务提供了镜像下载加速功能&#xff0c;帮助您获得更快的下载体验。 二、约束与限制 构建镜像的客…