mysql 集群恢复

news/2024/12/29 17:44:49/

准备使用集群的时候发现集群起不来,

发现抱错集群各个节点都是readonly 状态,找了很多资料,由于集群处于不一致的情况需要防止不同的节点数据写入脏数据

取消节点readonly 方法如下:

MySQL 取消 super read only

直接关闭read only 模式

SET GLOBAL super_read_only = OFF;

登录 mysqlsh  执行

dba.configureLocalInstance()

Dba.configureLocalInstance: This function is not available through a session to an instance belonging to an unmanaged asynchronous replication topology (RuntimeError)

shell.connect('root@node1:3306')
Creating a session to 'root@node1:3306'
Fetching schema names for autocompletion... Press ^C to stop.
Closing old connection...
Your MySQL connection id is 215
Server version: 8.0.30 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.

看到一个帖子说创建了一个集群就好了

开始创建集群:

var cluster = dba.createCluster('testCluster')A new InnoDB Cluster will be created on instance 'node1:3306'.Disabling super_read_only mode on instance 'node1:3306'.
Validating instance configuration at node1: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...
NOTE: User 'mysql_innodb_cluster_1891693795'@'%' already existed at instance 'node1:3306'. It will be deleted and created again with a new password.
Cluster successfully created. Use Cluster.addInstance() to add MySQL instances.

创建成功,添加实例

cluster.addInstance('root@node2:3306');

结果报错: 

cluster.addInstance('root@node2:3306');WARNING: A GTID set check of the MySQL instance at 'node2:3306' determined that it contains transactions that do not originate from the cluster, which must be discarded before it can join the cluster.node2:3306 has the following errant GTIDs that do not exist in the cluster:
45fc6a70-48a9-11ed-adfc-000c29325d80:1WARNING: Discarding these extra GTID events can either be done manually or by completely overwriting 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'.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): C
Validating instance configuration at node2: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...NOTE: User 'mysql_innodb_cluster_1780669600'@'%' already existed at instance 'node1:3306'. It will be deleted and created again with a new password.
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: 75.75 MB transferred in about 1 second (~75.75 MB/s)State recovery already finished for 'node2:3306'The instance 'node2:3306' was successfully added to the cluster.

实例中有的gts没同步过来,需要同步选择C 复制过来,第二个实例也添加成功了

再添加第三个实例

查看集群状态

cluster.status(); 

cluster.status();  
{"clusterName": "testCluster", "defaultReplicaSet": {"name": "default", "primary": "node1:3306", "ssl": "REQUIRED", "status": "OK", "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.", "topology": {"node1:3306": {"address": "node1:3306", "memberRole": "PRIMARY", "mode": "R/W", "readReplicas": {}, "replicationLag": "applier_queue_applied", "role": "HA", "status": "ONLINE", "version": "8.0.30"}, "node2:3306": {"address": "node2:3306", "memberRole": "SECONDARY", "mode": "R/O", "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": "node1:3306"
}

集群状态运行正常


http://www.ppmy.cn/news/1229971.html

相关文章

Python如何实现原型设计模式?什么是原型设计模式?Python 原型设计模式示例代码

什么是原型&#xff08;ProtoType&#xff09;设计模式&#xff1f; 原型模式&#xff08;Prototype Pattern&#xff09;是一种创建型设计模式&#xff0c;旨在通过复制现有对象来创建新对象&#xff0c;而无需通过标准的构造方式。它允许我们基于现有对象创建新对象&#xf…

Django DRF权限组件

在Django的drf框架内的权限组件&#xff0c;如果遇到多个权限认证类&#xff0c;是需要所有的权限类都要通过验证&#xff0c;才能访问视图。 一、简单示例 1、per.py 自定义权限类 from rest_framework.permissions import BasePermission import randomclass MyPerssion(B…

Vue3--Vue Router详解--学习笔记

1. 认识vue-router Angular的ngRouter React的ReactRouter Vue的vue-router Vue Router 是Vue.js的官方路由&#xff1a; 它与Vue.js核心深度集成&#xff0c;让Vue.js构建单页应用&#xff08;SPA&#xff09;变得非常容易&#xff1b;目前Vue路由最新的版本是4.x版本。 v…

【VRTK】【VR开发】【Unity】7-配置交互能力和向量追踪

【前情提要】 目前为止,我们虽然设定了手模型和动画,还能够正确根据输入触发动作,不过还未能与任何物体互动。要互动,需要给手部设定相应的Interactor能力。 【配置Interactor的抓取功能】 在Hierarchy中选中[VRTK_CAMERA_RIGS_SETUP] ➤ Camera Rigs, Tracked Alias ➤ …

力扣刷题-二叉树-二叉树的高度与深度

二叉树最大深度 给定一个二叉树 root &#xff0c;返回其最大深度。 二叉树的 最大深度 是指从根节点到最远叶子节点的最长路径上的节点数。 示例 1&#xff1a; 输入&#xff1a;root [3,9,20,null,null,15,7] 输出&#xff1a;3 递归法 本题可以使用前序&#xff08;中左…

Tomcat无法映射到activiti-app导致activiti无法启动页面

原因之一&#xff1a;JDK版本与Tomcat版本不匹配&#xff0c;jdk8 yyds 我使用的是JDK11&#xff0c;Tomcat是9.0的&#xff0c;都是最新的&#xff0c;但还是不行&#xff0c;最后JDK改为8&#xff0c;tomcat的cmd后台没有报错&#xff0c;activiti-pp也可以正常访问了,很神奇…

【Java并发编程九】同步控制

ReentrantLock(重入锁) ReentrantLock的基本使用 ReentrantLock可以自己决定加锁的位置和解锁的位置。 package myTest;import java.util.ArrayList; import java.util.concurrent.locks.ReentrantLock;public class myTest implements Runnable{// 重入锁public static Reen…

Go 语言中的map和内存泄漏

map在内存中总是会增长&#xff1b;它不会收缩。因此&#xff0c;如果map导致了一些内存问题&#xff0c;你可以尝试不同的选项&#xff0c;比如强制 Go 重新创建map或使用指针。 在 Go 中使用map时&#xff0c;我们需要了解map增长和收缩的一些重要特性。让我们深入探讨这一点…