标题: MySQL InnoDB Cluster搭建安装 [打印本页] 作者: 莱莱 时间: 2024-4-16 18:34 标题: MySQL InnoDB Cluster搭建安装 环境介绍:
这里的MySQL Innodb Cluster搭建环境如下所示,总共有三台机器搭建MySQL InnoDB Cluster: 操作系统: Red Hat Enterprise Linux release 8.8 (Ootpa) 数据库版本:8.0.35 MySQL Community Server - GPL 第一步:环境检查与配置
SET SQL_LOG_BIN=0;<br>CREATE USER icadmin@'192.168.9.%' IDENTIFIED BY '******';<br>GRANT ALL ON *.* TO icadmin@'192.168.9.%' WITH GRANT OPTION;<br>SET SQL_LOG_BIN=1;<br>
MySQL 192.168.9.200:7306 ssl JS > dba.checkInstanceConfiguration('icadmin@192.168.9.201:7306')<br>Please provide the password for 'icadmin@192.168.9.201:7306': ****************<br>Save password for 'icadmin@192.168.9.201:7306'? [Y]es/[N]o/Ne[v]er (default No): yes<br>Validating MySQL instance at mysqlu02:7306 for use in an InnoDB cluster...<br><br>This instance reports its own address as mysqlu02:7306<br>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.<br><br>Checking whether existing tables comply with Group Replication requirements...<br>No incompatible tables detected<br><br>Checking instance configuration...<br>Instance configuration is compatible with InnoDB cluster<br><br>The instance 'mysqlu02:7306' is valid to be used in an InnoDB cluster.<br><br>{<br> "status": "ok"<br>}<br> MySQL 192.168.9.200:7306 ssl JS ><br>
MySQL 192.168.9.200:7306 ssl JS > dba.configureInstance('icadmin@192.168.9.200:7306', {clusterAdmin: "'icadmin'@'192.168.9.%'"});<br><br>Configuring local MySQL instance listening at port 7306 for use in an InnoDB cluster...<br><br>This instance reports its own address as mysqlu01:7306<br>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.<br>User 'icadmin'@'192.168.9.%' already exists and will not be created.<br><br>applierWorkerThreads will be set to the default value of 4.<br><br>The instance 'mysqlu01:7306' is valid to be used in an InnoDB cluster.<br>The instance 'mysqlu01:7306' is already ready to be used in an InnoDB cluster.<br><br>Successfully enabled parallel appliers.<br> MySQL 192.168.9.200:7306 ssl JS > dba.configureInstance('icadmin@192.168.9.201:7306', {clusterAdmin: "'icadmin'@'192.168.9.%'"});<br><br>Configuring MySQL instance at mysqlu02:7306 for use in an InnoDB cluster...<br><br>This instance reports its own address as mysqlu02:7306<br>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.<br>User 'icadmin'@'192.168.9.%' already exists and will not be created.<br><br>applierWorkerThreads will be set to the default value of 4.<br><br>The instance 'mysqlu02:7306' is valid to be used in an InnoDB cluster.<br>The instance 'mysqlu02:7306' is already ready to be used in an InnoDB cluster.<br><br>Successfully enabled parallel appliers.<br> MySQL 192.168.9.200:7306 ssl JS > dba.configureInstance('icadmin@192.168.9.202:7306', {clusterAdmin: "'icadmin'@'192.168.9.%'"});<br><br>Configuring MySQL instance at mysqlu03:7306 for use in an InnoDB cluster...<br><br>This instance reports its own address as mysqlu03:7306<br>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.<br>User 'icadmin'@'192.168.9.%' already exists and will not be created.<br><br>applierWorkerThreads will be set to the default value of 4.<br><br>The instance 'mysqlu03:7306' is valid to be used in an InnoDB cluster.<br>The instance 'mysqlu03:7306' is already ready to be used in an InnoDB cluster.<br><br>Successfully enabled parallel appliers.<br> MySQL 192.168.9.200:7306 ssl JS ><br>
复制代码
创建集群
var cluster = dba.createCluster('gsp_cluster');<br>
复制代码
具体操作如下所示:
MySQL 192.168.9.200:7306 ssl JS > var cluster = dba.createCluster('gsp_cluster');<br>A new InnoDB Cluster will be created on instance 'mysqlu01:7306'.
Validating instance configuration at 192.168.9.200:7306...
This instance reports its own address as mysqlu01:7306
Instance configuration is suitable.
NOTE: Group Replication will communicate with other members using 'mysqlu01:7306'. Use the localAddress option to override.
* Checking connectivity and SSL configuration...
Creating InnoDB Cluster 'gsp_cluster' on 'mysqlu01:7306'...
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.9.200:7306 ssl JS >
复制代码
查看创建集群状态
var cluster = dba.getCluster()<br>cluster.status()<br>
var cluster=dba.getCluster()<br>cluster.addInstance('icadmin@192.168.9.201:7306')<br>cluster.status()<br>cluster.addInstance('icadmin@192.168.9.202:7306')<br>cluster.status()<br>
复制代码
部分输出如下所示:
MySQL 192.168.9.200:7306 ssl JS > cluster.addInstance('icadmin@192.168.9.202:7306')<br><br>NOTE: The target instance 'mysqlu03:7306' has not been pre-provisioned (GTID set is empty). The Shell is unable to decide whether incremental state recovery can correctly provision it.<br>The safest and most convenient way to provision a new instance is through automatic clone provisioning, which will completely overwrite the state of 'mysqlu03:7306' with a physical snapshot from an existing cluster member. To use this method by default, set the 'recoveryMethod' option to 'clone'.<br><br>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'.<br><br><br>Please select a recovery method [C]lone/[I]ncremental recovery/[A]bort (default Clone): C<br>Validating instance configuration at 192.168.9.202:7306...<br><br>This instance reports its own address as mysqlu03:7306<br><br>Instance configuration is suitable.<br>NOTE: Group Replication will communicate with other members using 'mysqlu03:7306'. Use the localAddress option to override.<br><br>* Checking connectivity and SSL configuration...<br>A new instance will be added to the InnoDB Cluster. Depending on the amount of<br>data on the cluster this might take from a few seconds to several hours.<br><br>Adding instance to the cluster...<br><br>Monitoring recovery process of the new cluster member. Press ^C to stop monitoring and let it continue in background.<br>Clone based state recovery is now in progress.<br><br>NOTE: A server restart is expected to happen as part of the clone process. If the<br>server does not support the RESTART command or does not come back after a<br>while, you may need to manually start it back.<br><br>* Waiting for clone to finish...<br>NOTE: mysqlu03:7306 is being cloned from mysqlu02:7306<br>** Stage DROP DATA: Completed <br><br><br><br><br>** Clone Transfer FILE COPY ============================================================ 0% Not Started PAGE COPY ============================================================ 0% Not Started REDO COPY ============================================================ 0% Not Started** Clone Transfer FILE COPY ============================================================ 0% In Progress PAGE COPY ============================================================ 0% Not Started REDO COPY ============================================================ 0% Not Started** Clone Transfer FILE COPY ############################################################ 100% Completed PAGE COPY ############################################################ 100% Completed REDO COPY ############################################################ 100% Completed<br>NOTE: mysqlu03:7306 is shutting down...<br><br>* Waiting for server restart... ready <br>* mysqlu03:7306 has restarted, waiting for clone to finish...<br>** Stage RESTART: Completed<br>* Clone process has finished: 73.65 MB transferred in about 1 second (~73.65 MB/s)<br><br>State recovery already finished for 'mysqlu03:7306'<br><br>The instance 'mysqlu03:7306' was successfully added to the cluster.<br><br> MySQL 192.168.9.200:7306 ssl JS > cluster.status()<br>{<br> "clusterName": "gsp_cluster", <br> "defaultReplicaSet": {<br> "name": "default", <br> "primary": "mysqlu01:7306", <br> "ssl": "REQUIRED", <br> "status": "OK", <br> "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.", <br> "topology": {<br> "mysqlu01:7306": {<br> "address": "mysqlu01:7306", <br> "memberRole": "PRIMARY", <br> "mode": "R/W", <br> "readReplicas": {}, <br> "replicationLag": "applier_queue_applied", <br> "role": "HA", <br> "status": "ONLINE", <br> "version": "8.0.33"<br> }, <br> "mysqlu02:7306": {<br> "address": "mysqlu02:7306", <br> "memberRole": "SECONDARY", <br> "mode": "R/O", <br> "readReplicas": {}, <br> "replicationLag": "applier_queue_applied", <br> "role": "HA", <br> "status": "ONLINE", <br> "version": "8.0.33"<br> }, <br> "mysqlu03:7306": {<br> "address": "mysqlu03:7306", <br> "memberRole": "SECONDARY", <br> "mode": "R/O", <br> "readReplicas": {}, <br> "replicationLag": "applier_queue_applied", <br> "role": "HA", <br> "status": "ONLINE", <br> "version": "8.0.33"<br> }<br> }, <br> "topologyMode": "Single-Primary"<br> }, <br> "groupInformationSourceMember": "mysqlu01:7306"<br>}<br> MySQL 192.168.9.200:7306 ssl JS ><br>
$ cd /data/soft<br>$ tar xvf mysql-router-8.0.35-linux-glibc2.28-x86_64.tar.xz -C /opt/mysql<br>$ cd /opt/mysql/<br>$ ln -s mysql-router-8.0.35-linux-glibc2.28-x86_64/ router<br>
$ mysqlrouter --bootstrap icadmin@mysqlu01:7306 --directory /data/mysqlrouter --name='iicrouter' --force-password-validation<br>Please enter MySQL password for icadmin: <br># Bootstrapping MySQL Router 8.0.35 (MySQL Community - GPL) instance at '/data/mysqlrouter'...<br><br>- Creating account(s) (only those that are needed, if any)<br>- Verifying account (using it to run SQL queries that would be run by Router)<br>- Storing account in keyring<br>- Adjusting permissions of generated files<br>- Creating configuration /data/mysqlrouter/mysqlrouter.conf<br><br># MySQL Router 'iicrouter' configured for the ClusterSet 'yicticcset'<br><br>After this MySQL Router has been started with the generated configuration<br><br> $ mysqlrouter -c /data/mysqlrouter/mysqlrouter.conf<br><br>ClusterSet 'yicticcset' can be reached by connecting to:<br><br>## MySQL Classic protocol<br><br>- Read/Write Connections: localhost:6446<br>- Read/Only Connections: localhost:6447<br><br>## MySQL X protocol<br><br>- Read/Write Connections: localhost:6448<br>- Read/Only Connections: localhost:6449<br>
[mysql@mysqlu01 mysqlrouter]$ mysqlrouter --bootstrap icadmin@mysqlu01:7306 \<br>> --directory /data/mysqlrouter \<br>> --account iccrouter \<br>> --user mysql --name icrouter \<br>> --conf-bind-address="192.168.9.200" \<br>> --account-host="192.168.9.%" --force-password-validation<br>Please enter MySQL password for icadmin: <br># Reconfiguring MySQL Router 8.0.35 (MySQL Community - GPL) instance at '/data/mysqlrouter'...<br><br>Please enter MySQL password for iccrouter: <br>- Creating account(s) (only those that are needed, if any)<br>- Using existing certificates from the '/data/mysqlrouter/data' directory<br>- Verifying account (using it to run SQL queries that would be run by Router)<br>- Storing account in keyring<br>- Adjusting permissions of generated files<br>- Creating configuration /data/mysqlrouter/mysqlrouter.conf<br><br>Existing configurations backed up to '/data/mysqlrouter/mysqlrouter.conf.bak'<br><br># MySQL Router 'icrouter' configured for the InnoDB Cluster 'gsp_cluster'<br><br>After this MySQL Router has been started with the generated configuration<br><br> $ mysqlrouter -c /data/mysqlrouter/mysqlrouter.conf<br><br>InnoDB Cluster 'gsp_cluster' can be reached by connecting to:<br><br>## MySQL Classic protocol<br><br>- Read/Write Connections: localhost:6446<br>- Read/Only Connections: localhost:6447<br><br>## MySQL X protocol<br><br>- Read/Write Connections: localhost:6448<br>- Read/Only Connections: localhost:6449<br><br>[mysql@mysqlu01 mysqlrouter]$<br>
复制代码
查看MySQL Router信息
var cluster =dba.getCluster()<br>cluster.listRouters()<br>