欢迎光临
我们一直在努力

MySQL PXC集群原理与Galera协议深度剖析:高可用数据库架构揭秘

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */
#content_views .toc,
/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */
#content_views.markdown_views > p:empty:has(+ .toc),
#content_views.markdown_views > .toc + p:empty,
/* 富文本旧版目录标记 */
#content_views.htmledit_views #main-toc,
#content_views.htmledit_views #hr-toc,
#content_views.htmledit_views p[id*=\”-toc\”] {
display: none !important;
}
/* 目录去掉后,紧跟的首个标题不再多出一块上边距 */
#content_views.markdown_views > .toc + h1,
#content_views.markdown_views > .toc + h2,
#content_views.markdown_views > .toc + h3,
#content_views.markdown_views > .toc + h4,
#content_views.markdown_views > .toc + p:empty + h1,
#content_views.markdown_views > .toc + p:empty + h2,
#content_views.markdown_views > .toc + p:empty + h3,
#content_views.markdown_views > .toc + p:empty + h4 {
margin-top: 0 !important;
}

一、PXC集群概述:高可用数据库解决方案

Percona XtraDB Cluster (PXC) 是一个基于Galera库构建的高可用性、强一致性的MySQL集群解决方案。它通过同步复制技术,确保集群中所有节点数据实时一致,从而实现零数据丢失和故障自动转移。PXC集群的核心目标是解决传统主从复制架构中数据不一致和单点故障的问题,为关键业务提供稳定可靠的数据服务。

1.1 PXC的核心优势

PXC集群相较于传统主从复制,具备以下显著优势:

  • 强一致性:所有节点采用同步复制,保证数据在集群内完全一致。
  • 高可用性:任意节点故障,集群仍可继续提供服务,无需手动切换。
  • 读写分离:所有节点均可接受读写请求,负载均衡更灵活。
  • 自动故障转移:节点宕机后,集群自动完成故障检测与数据同步。
  • 二、Galera协议核心:同步复制的基石

    Galera Cluster是PXC集群的技术基础,其核心是Galera复制协议。该协议实现了多主节点的同步复制,确保数据的一致性和集群的健壮性。

    2.1 主从复制 vs. Galera同步复制

    传统的主从复制是异步的,主节点将binlog发送给从节点,从节点再应用。这种模式下,主从数据存在延迟,可能导致数据不一致。而Galera协议采用同步复制,所有节点对事务进行认证,只有当大多数节点确认后,事务才被提交。

    为了更直观地理解主从复制与Galera同步复制的区别,我们可以通过以下流程图进行对比:

    #publish-mermaid-0-1792075097769{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#publish-mermaid-0-1792075097769 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#publish-mermaid-0-1792075097769 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#publish-mermaid-0-1792075097769 .error-icon{fill:#552222;}#publish-mermaid-0-1792075097769 .error-text{fill:#552222;stroke:#552222;}#publish-mermaid-0-1792075097769 .edge-thickness-normal{stroke-width:1px;}#publish-mermaid-0-1792075097769 .edge-thickness-thick{stroke-width:3.5px;}#publish-mermaid-0-1792075097769 .edge-pattern-solid{stroke-dasharray:0;}#publish-mermaid-0-1792075097769 .edge-thickness-invisible{stroke-width:0;fill:none;}#publish-mermaid-0-1792075097769 .edge-pattern-dashed{stroke-dasharray:3;}#publish-mermaid-0-1792075097769 .edge-pattern-dotted{stroke-dasharray:2;}#publish-mermaid-0-1792075097769 .marker{fill:#333333;stroke:#333333;}#publish-mermaid-0-1792075097769 .marker.cross{stroke:#333333;}#publish-mermaid-0-1792075097769 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#publish-mermaid-0-1792075097769 p{margin:0;}#publish-mermaid-0-1792075097769 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#publish-mermaid-0-1792075097769 .cluster-label text{fill:#333;}#publish-mermaid-0-1792075097769 .cluster-label span{color:#333;}#publish-mermaid-0-1792075097769 .cluster-label span p{background-color:transparent;}#publish-mermaid-0-1792075097769 .label text,#publish-mermaid-0-1792075097769 span{fill:#333;color:#333;}#publish-mermaid-0-1792075097769 .node rect,#publish-mermaid-0-1792075097769 .node circle,#publish-mermaid-0-1792075097769 .node ellipse,#publish-mermaid-0-1792075097769 .node polygon,#publish-mermaid-0-1792075097769 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#publish-mermaid-0-1792075097769 .rough-node .label text,#publish-mermaid-0-1792075097769 .node .label text,#publish-mermaid-0-1792075097769 .image-shape .label,#publish-mermaid-0-1792075097769 .icon-shape .label{text-anchor:middle;}#publish-mermaid-0-1792075097769 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#publish-mermaid-0-1792075097769 .rough-node .label,#publish-mermaid-0-1792075097769 .node .label,#publish-mermaid-0-1792075097769 .image-shape .label,#publish-mermaid-0-1792075097769 .icon-shape .label{text-align:center;}#publish-mermaid-0-1792075097769 .node.clickable{cursor:pointer;}#publish-mermaid-0-1792075097769 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#publish-mermaid-0-1792075097769 .arrowheadPath{fill:#333333;}#publish-mermaid-0-1792075097769 .edgePath .path{stroke:#333333;stroke-width:1px;}#publish-mermaid-0-1792075097769 .flowchart-link{stroke:#333333;fill:none;}#publish-mermaid-0-1792075097769 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-0-1792075097769 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#publish-mermaid-0-1792075097769 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-0-1792075097769 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#publish-mermaid-0-1792075097769 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#publish-mermaid-0-1792075097769 .cluster text{fill:#333;}#publish-mermaid-0-1792075097769 .cluster span{color:#333;}#publish-mermaid-0-1792075097769 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#publish-mermaid-0-1792075097769 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#publish-mermaid-0-1792075097769 rect.text{fill:none;stroke-width:0;}#publish-mermaid-0-1792075097769 .icon-shape,#publish-mermaid-0-1792075097769 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-0-1792075097769 .icon-shape p,#publish-mermaid-0-1792075097769 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#publish-mermaid-0-1792075097769 .icon-shape .label rect,#publish-mermaid-0-1792075097769 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-0-1792075097769 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#publish-mermaid-0-1792075097769 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#publish-mermaid-0-1792075097769 .node .neo-node{stroke:#9370DB;}#publish-mermaid-0-1792075097769 [data-look=\”neo\”].node rect,#publish-mermaid-0-1792075097769 [data-look=\”neo\”].cluster rect,#publish-mermaid-0-1792075097769 [data-look=\”neo\”].node polygon{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-0-1792075097769 [data-look=\”neo\”].swimlane.cluster rect{filter:none;}#publish-mermaid-0-1792075097769 [data-look=\”neo\”].node path{stroke:#9370DB;stroke-width:1px;}#publish-mermaid-0-1792075097769 [data-look=\”neo\”].node .outer-path{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-0-1792075097769 [data-look=\”neo\”].node .neo-line path{stroke:#9370DB;filter:none;}#publish-mermaid-0-1792075097769 [data-look=\”neo\”].node circle{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-0-1792075097769 [data-look=\”neo\”].node circle .state-start{fill:#000000;}#publish-mermaid-0-1792075097769 [data-look=\”neo\”].icon-shape .icon{fill:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-0-1792075097769 [data-look=\”neo\”].icon-shape .icon-neo path{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-0-1792075097769 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}Galera同步复制

    客户端

    节点1

    节点2

    节点3

    主从复制

    客户端

    主节点

    从节点1

    从节点2

    该图清晰地展示了主从复制中主节点是唯一的写入点,而从节点被动接收数据;在Galera集群中,所有节点地位平等,均可处理写入请求,并且数据同步是同步进行的。

    2.2 写集与认证:Galera的同步机制

    Galera协议的核心机制包括写集和认证。当一个节点收到一个事务请求时,它会生成一个写集(包含所有修改的数据),并将该写集和事务ID发送给集群中的其他节点。其他节点收到后,会进行冲突检测和认证。如果认证通过,节点会应用该事务;如果认证失败,则事务被回滚。

    2.3 案例分析:一个事务的完整流程

    一个客户端在PXC集群中执行一个UPDATE操作,其完整流程如下。通过时序图可以清晰地看到每个节点的交互过程:

    节点3节点2节点1(协调者)客户端节点3节点2节点1(协调者)客户端#publish-mermaid-1-1792075097931{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#publish-mermaid-1-1792075097931 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#publish-mermaid-1-1792075097931 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#publish-mermaid-1-1792075097931 .error-icon{fill:#552222;}#publish-mermaid-1-1792075097931 .error-text{fill:#552222;stroke:#552222;}#publish-mermaid-1-1792075097931 .edge-thickness-normal{stroke-width:1px;}#publish-mermaid-1-1792075097931 .edge-thickness-thick{stroke-width:3.5px;}#publish-mermaid-1-1792075097931 .edge-pattern-solid{stroke-dasharray:0;}#publish-mermaid-1-1792075097931 .edge-thickness-invisible{stroke-width:0;fill:none;}#publish-mermaid-1-1792075097931 .edge-pattern-dashed{stroke-dasharray:3;}#publish-mermaid-1-1792075097931 .edge-pattern-dotted{stroke-dasharray:2;}#publish-mermaid-1-1792075097931 .marker{fill:#333333;stroke:#333333;}#publish-mermaid-1-1792075097931 .marker.cross{stroke:#333333;}#publish-mermaid-1-1792075097931 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#publish-mermaid-1-1792075097931 p{margin:0;}#publish-mermaid-1-1792075097931 .actor{stroke:#9370DB;fill:#ECECFF;stroke-width:1;}#publish-mermaid-1-1792075097931 rect.actor.outer-path[data-look=\”neo\”]{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1-1792075097931 rect.note[data-look=\”neo\”]{stroke:#aaaa33;fill:#fff5ad;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1-1792075097931 text.actor>tspan{fill:black;stroke:none;}#publish-mermaid-1-1792075097931 .actor-line{stroke:#9370DB;}#publish-mermaid-1-1792075097931 .innerArc{stroke-width:1.5;stroke-dasharray:none;}#publish-mermaid-1-1792075097931 .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#publish-mermaid-1-1792075097931 .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#publish-mermaid-1-1792075097931 [id$=\”-arrowhead\”] path{fill:#333;stroke:#333;}#publish-mermaid-1-1792075097931 .sequenceNumber{fill:white;}#publish-mermaid-1-1792075097931 [id$=\”-sequencenumber\”]{fill:#333;}#publish-mermaid-1-1792075097931 [id$=\”-crosshead\”] path{fill:#333;stroke:#333;}#publish-mermaid-1-1792075097931 .messageText{fill:#333;stroke:none;}#publish-mermaid-1-1792075097931 .labelBox{stroke:#9370DB;fill:#ECECFF;filter:none;}#publish-mermaid-1-1792075097931 .labelText,#publish-mermaid-1-1792075097931 .labelText>tspan{fill:black;stroke:none;}#publish-mermaid-1-1792075097931 .loopText,#publish-mermaid-1-1792075097931 .loopText>tspan{fill:black;stroke:none;}#publish-mermaid-1-1792075097931 .sectionTitle,#publish-mermaid-1-1792075097931 .sectionTitle>tspan{fill:black;stroke:none;}#publish-mermaid-1-1792075097931 .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:#9370DB;fill:#9370DB;}#publish-mermaid-1-1792075097931 .note{stroke:#aaaa33;fill:#fff5ad;}#publish-mermaid-1-1792075097931 .noteText,#publish-mermaid-1-1792075097931 .noteText>tspan{fill:black;stroke:none;font-weight:normal;}#publish-mermaid-1-1792075097931 .activation0{fill:#f4f4f4;stroke:#666;}#publish-mermaid-1-1792075097931 .activation1{fill:#f4f4f4;stroke:#666;}#publish-mermaid-1-1792075097931 .activation2{fill:#f4f4f4;stroke:#666;}#publish-mermaid-1-1792075097931 .actorPopupMenu{position:absolute;}#publish-mermaid-1-1792075097931 .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4));}#publish-mermaid-1-1792075097931 .actor-man circle,#publish-mermaid-1-1792075097931 line{fill:#ECECFF;stroke-width:2px;}#publish-mermaid-1-1792075097931 g rect.rect{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));stroke:#9370DB;}#publish-mermaid-1-1792075097931 .node .neo-node{stroke:#9370DB;}#publish-mermaid-1-1792075097931 [data-look=\”neo\”].node rect,#publish-mermaid-1-1792075097931 [data-look=\”neo\”].cluster rect,#publish-mermaid-1-1792075097931 [data-look=\”neo\”].node polygon{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1-1792075097931 [data-look=\”neo\”].swimlane.cluster rect{filter:none;}#publish-mermaid-1-1792075097931 [data-look=\”neo\”].node path{stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1-1792075097931 [data-look=\”neo\”].node .outer-path{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1-1792075097931 [data-look=\”neo\”].node .neo-line path{stroke:#9370DB;filter:none;}#publish-mermaid-1-1792075097931 [data-look=\”neo\”].node circle{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1-1792075097931 [data-look=\”neo\”].node circle .state-start{fill:#000000;}#publish-mermaid-1-1792075097931 [data-look=\”neo\”].icon-shape .icon{fill:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1-1792075097931 [data-look=\”neo\”].icon-shape .icon-neo path{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1-1792075097931 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}BEGIN TRANSACTION发送写集与认证请求认证通过发送写集与认证请求认证通过应用事务应用事务返回COMMIT确认

    该时序图展示了事务从开始到提交的完整生命周期,强调了Galera协议中“多数派确认”的同步特性。

    三、PXC集群组件详解:各司其职

    PXC集群由多个关键组件构成,它们协同工作以实现集群功能。

    3.1 Galera库:集群引擎核心

    Galera库是PXC集群的核心,它实现了Galera复制协议。它负责节点间的通信、事务认证、数据同步和状态管理。Galera库通过wsrep接口与MySQL服务器交互,将MySQL的事务转换为可在集群中复制的写集。

    3.2 MySQL服务器:数据存储层

    标准的MySQL服务器负责处理SQL查询、存储数据和执行事务。在PXC中,每个节点都是一个独立的MySQL实例,但它们通过Galera库连接成一个集群。

    3.3 状态机:节点状态与转换

    PXC集群中的每个节点都有一个状态机,用于管理其运行状态。节点状态包括Synced(已同步)、Donor/Desynced(捐赠者/未同步)、Joining(加入中)和Error(错误)等。节点状态会根据集群情况自动转换。

    以下状态图展示了PXC节点的典型状态转换过程:

    #publish-mermaid-2-1792075097966{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#publish-mermaid-2-1792075097966 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#publish-mermaid-2-1792075097966 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#publish-mermaid-2-1792075097966 .error-icon{fill:#552222;}#publish-mermaid-2-1792075097966 .error-text{fill:#552222;stroke:#552222;}#publish-mermaid-2-1792075097966 .edge-thickness-normal{stroke-width:1px;}#publish-mermaid-2-1792075097966 .edge-thickness-thick{stroke-width:3.5px;}#publish-mermaid-2-1792075097966 .edge-pattern-solid{stroke-dasharray:0;}#publish-mermaid-2-1792075097966 .edge-thickness-invisible{stroke-width:0;fill:none;}#publish-mermaid-2-1792075097966 .edge-pattern-dashed{stroke-dasharray:3;}#publish-mermaid-2-1792075097966 .edge-pattern-dotted{stroke-dasharray:2;}#publish-mermaid-2-1792075097966 .marker{fill:#333333;stroke:#333333;}#publish-mermaid-2-1792075097966 .marker.cross{stroke:#333333;}#publish-mermaid-2-1792075097966 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#publish-mermaid-2-1792075097966 p{margin:0;}#publish-mermaid-2-1792075097966 defs [id$=\”-barbEnd\”]{fill:#333333;stroke:#333333;}#publish-mermaid-2-1792075097966 g.stateGroup text{fill:#9370DB;stroke:none;font-size:10px;}#publish-mermaid-2-1792075097966 g.stateGroup text{fill:#333;stroke:none;font-size:10px;}#publish-mermaid-2-1792075097966 g.stateGroup .state-title{font-weight:bolder;fill:#131300;}#publish-mermaid-2-1792075097966 g.stateGroup rect{fill:#ECECFF;stroke:#9370DB;}#publish-mermaid-2-1792075097966 g.stateGroup line{stroke:#333333;stroke-width:1;}#publish-mermaid-2-1792075097966 .transition{stroke:#333333;stroke-width:1;fill:none;}#publish-mermaid-2-1792075097966 .stateGroup .composit{fill:white;border-bottom:1px;}#publish-mermaid-2-1792075097966 .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px;}#publish-mermaid-2-1792075097966 .state-note{stroke:#aaaa33;fill:#fff5ad;}#publish-mermaid-2-1792075097966 .state-note text{fill:black;stroke:none;font-size:10px;}#publish-mermaid-2-1792075097966 .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5;}#publish-mermaid-2-1792075097966 .edgeLabel .label rect{fill:#ECECFF;opacity:0.5;}#publish-mermaid-2-1792075097966 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-2-1792075097966 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#publish-mermaid-2-1792075097966 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-2-1792075097966 .edgeLabel .label text{fill:#333;}#publish-mermaid-2-1792075097966 .label div .edgeLabel{color:#333;}#publish-mermaid-2-1792075097966 .stateLabel text{fill:#131300;font-size:10px;font-weight:bold;}#publish-mermaid-2-1792075097966 .node circle.state-start{fill:#333333;stroke:#333333;}#publish-mermaid-2-1792075097966 .node .fork-join{fill:#333333;stroke:#333333;}#publish-mermaid-2-1792075097966 .node circle.state-end{fill:#9370DB;stroke:white;stroke-width:1.5;}#publish-mermaid-2-1792075097966 .end-state-inner{fill:white;stroke-width:1.5;}#publish-mermaid-2-1792075097966 .node rect{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#publish-mermaid-2-1792075097966 .node polygon{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#publish-mermaid-2-1792075097966 [id$=\”-barbEnd\”]{fill:#333333;}#publish-mermaid-2-1792075097966 .statediagram-cluster rect{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#publish-mermaid-2-1792075097966 .cluster-label,#publish-mermaid-2-1792075097966 .nodeLabel{color:#131300;}#publish-mermaid-2-1792075097966 .statediagram-cluster rect.outer{rx:5px;ry:5px;}#publish-mermaid-2-1792075097966 .statediagram-state .divider{stroke:#9370DB;}#publish-mermaid-2-1792075097966 .statediagram-state .title-state{rx:5px;ry:5px;}#publish-mermaid-2-1792075097966 .statediagram-cluster.statediagram-cluster .inner{fill:white;}#publish-mermaid-2-1792075097966 .statediagram-cluster.statediagram-cluster-alt .inner{fill:#f0f0f0;}#publish-mermaid-2-1792075097966 .statediagram-cluster .inner{rx:0;ry:0;}#publish-mermaid-2-1792075097966 .statediagram-state rect.basic{rx:5px;ry:5px;}#publish-mermaid-2-1792075097966 .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#f0f0f0;}#publish-mermaid-2-1792075097966 .note-edge{stroke-dasharray:5;}#publish-mermaid-2-1792075097966 .statediagram-note rect{fill:#fff5ad;stroke:#aaaa33;stroke-width:1px;rx:0;ry:0;}#publish-mermaid-2-1792075097966 .statediagram-note rect{fill:#fff5ad;stroke:#aaaa33;stroke-width:1px;rx:0;ry:0;}#publish-mermaid-2-1792075097966 .statediagram-note text{fill:black;}#publish-mermaid-2-1792075097966 .statediagram-note .nodeLabel{color:black;}#publish-mermaid-2-1792075097966 .statediagram .edgeLabel{color:red;}#publish-mermaid-2-1792075097966 [id$=\”-dependencyStart\”],#publish-mermaid-2-1792075097966 [id$=\”-dependencyEnd\”]{fill:#333333;stroke:#333333;stroke-width:1;}#publish-mermaid-2-1792075097966 .statediagramTitleText{text-anchor:middle;font-size:18px;fill:#333;}#publish-mermaid-2-1792075097966 [data-look=\”neo\”].statediagram-cluster rect{fill:#ECECFF;stroke:#9370DB;stroke-width:1;}#publish-mermaid-2-1792075097966 [data-look=\”neo\”].statediagram-cluster rect.outer{rx:5px;ry:5px;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-2-1792075097966 .node .neo-node{stroke:#9370DB;}#publish-mermaid-2-1792075097966 [data-look=\”neo\”].node rect,#publish-mermaid-2-1792075097966 [data-look=\”neo\”].cluster rect,#publish-mermaid-2-1792075097966 [data-look=\”neo\”].node polygon{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-2-1792075097966 [data-look=\”neo\”].swimlane.cluster rect{filter:none;}#publish-mermaid-2-1792075097966 [data-look=\”neo\”].node path{stroke:#9370DB;stroke-width:1px;}#publish-mermaid-2-1792075097966 [data-look=\”neo\”].node .outer-path{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-2-1792075097966 [data-look=\”neo\”].node .neo-line path{stroke:#9370DB;filter:none;}#publish-mermaid-2-1792075097966 [data-look=\”neo\”].node circle{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-2-1792075097966 [data-look=\”neo\”].node circle .state-start{fill:#000000;}#publish-mermaid-2-1792075097966 [data-look=\”neo\”].icon-shape .icon{fill:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-2-1792075097966 [data-look=\”neo\”].icon-shape .icon-neo path{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-2-1792075097966 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}认证成功认证失败开始数据捐赠捐赠完成发生致命错误重启后重新加入

    Joining

    Synced

    Error

    Donor/Desynced

    该图清晰地描绘了节点从启动到正常运行,以及在不同情况下(如数据捐赠、故障)的状态变迁路径。

    四、PXC集群部署与配置:实践指南

    部署PXC集群需要合理的网络规划和正确的配置参数。

    4.1 部署拓扑:节点间通信

    PXC集群要求所有节点之间能够相互通信。典型的部署拓扑是全连接网络,即每个节点都能直接与其他所有节点通信。这种拓扑确保了在任何节点发生故障时,剩余节点仍能形成多数派。

    #publish-mermaid-3-1792075098088{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#publish-mermaid-3-1792075098088 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#publish-mermaid-3-1792075098088 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#publish-mermaid-3-1792075098088 .error-icon{fill:#552222;}#publish-mermaid-3-1792075098088 .error-text{fill:#552222;stroke:#552222;}#publish-mermaid-3-1792075098088 .edge-thickness-normal{stroke-width:1px;}#publish-mermaid-3-1792075098088 .edge-thickness-thick{stroke-width:3.5px;}#publish-mermaid-3-1792075098088 .edge-pattern-solid{stroke-dasharray:0;}#publish-mermaid-3-1792075098088 .edge-thickness-invisible{stroke-width:0;fill:none;}#publish-mermaid-3-1792075098088 .edge-pattern-dashed{stroke-dasharray:3;}#publish-mermaid-3-1792075098088 .edge-pattern-dotted{stroke-dasharray:2;}#publish-mermaid-3-1792075098088 .marker{fill:#333333;stroke:#333333;}#publish-mermaid-3-1792075098088 .marker.cross{stroke:#333333;}#publish-mermaid-3-1792075098088 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#publish-mermaid-3-1792075098088 p{margin:0;}#publish-mermaid-3-1792075098088 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#publish-mermaid-3-1792075098088 .cluster-label text{fill:#333;}#publish-mermaid-3-1792075098088 .cluster-label span{color:#333;}#publish-mermaid-3-1792075098088 .cluster-label span p{background-color:transparent;}#publish-mermaid-3-1792075098088 .label text,#publish-mermaid-3-1792075098088 span{fill:#333;color:#333;}#publish-mermaid-3-1792075098088 .node rect,#publish-mermaid-3-1792075098088 .node circle,#publish-mermaid-3-1792075098088 .node ellipse,#publish-mermaid-3-1792075098088 .node polygon,#publish-mermaid-3-1792075098088 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#publish-mermaid-3-1792075098088 .rough-node .label text,#publish-mermaid-3-1792075098088 .node .label text,#publish-mermaid-3-1792075098088 .image-shape .label,#publish-mermaid-3-1792075098088 .icon-shape .label{text-anchor:middle;}#publish-mermaid-3-1792075098088 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#publish-mermaid-3-1792075098088 .rough-node .label,#publish-mermaid-3-1792075098088 .node .label,#publish-mermaid-3-1792075098088 .image-shape .label,#publish-mermaid-3-1792075098088 .icon-shape .label{text-align:center;}#publish-mermaid-3-1792075098088 .node.clickable{cursor:pointer;}#publish-mermaid-3-1792075098088 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#publish-mermaid-3-1792075098088 .arrowheadPath{fill:#333333;}#publish-mermaid-3-1792075098088 .edgePath .path{stroke:#333333;stroke-width:1px;}#publish-mermaid-3-1792075098088 .flowchart-link{stroke:#333333;fill:none;}#publish-mermaid-3-1792075098088 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-3-1792075098088 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#publish-mermaid-3-1792075098088 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-3-1792075098088 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#publish-mermaid-3-1792075098088 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#publish-mermaid-3-1792075098088 .cluster text{fill:#333;}#publish-mermaid-3-1792075098088 .cluster span{color:#333;}#publish-mermaid-3-1792075098088 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#publish-mermaid-3-1792075098088 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#publish-mermaid-3-1792075098088 rect.text{fill:none;stroke-width:0;}#publish-mermaid-3-1792075098088 .icon-shape,#publish-mermaid-3-1792075098088 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-3-1792075098088 .icon-shape p,#publish-mermaid-3-1792075098088 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#publish-mermaid-3-1792075098088 .icon-shape .label rect,#publish-mermaid-3-1792075098088 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-3-1792075098088 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#publish-mermaid-3-1792075098088 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#publish-mermaid-3-1792075098088 .node .neo-node{stroke:#9370DB;}#publish-mermaid-3-1792075098088 [data-look=\”neo\”].node rect,#publish-mermaid-3-1792075098088 [data-look=\”neo\”].cluster rect,#publish-mermaid-3-1792075098088 [data-look=\”neo\”].node polygon{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-3-1792075098088 [data-look=\”neo\”].swimlane.cluster rect{filter:none;}#publish-mermaid-3-1792075098088 [data-look=\”neo\”].node path{stroke:#9370DB;stroke-width:1px;}#publish-mermaid-3-1792075098088 [data-look=\”neo\”].node .outer-path{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-3-1792075098088 [data-look=\”neo\”].node .neo-line path{stroke:#9370DB;filter:none;}#publish-mermaid-3-1792075098088 [data-look=\”neo\”].node circle{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-3-1792075098088 [data-look=\”neo\”].node circle .state-start{fill:#000000;}#publish-mermaid-3-1792075098088 [data-look=\”neo\”].icon-shape .icon{fill:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-3-1792075098088 [data-look=\”neo\”].icon-shape .icon-neo path{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-3-1792075098088 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}PXC_Cluster

    Node 1

    Node 2

    Node 3

    客户端

    该图展示了客户端可以连接到任意节点,而集群内部节点之间通过全连接进行通信,确保了同步复制的效率。

    4.2 关键配置参数:影响集群行为

    PXC集群的配置文件中包含许多关键参数,这些参数直接影响集群的性能和行为。以下是一些重要的配置参数及其说明:

    参数描述
    wsrep_on=ON 启用Galera复制协议
    wsrep_provider 指定Galera库的路径
    wsrep_cluster_name 定义集群名称,所有节点必须相同
    wsrep_cluster_address 定义集群中所有节点的地址列表
    wsrep_sst_method 定义状态快照传输方法,如rsync或xtrabackup
    binlog_format=ROW 必须使用行格式二进制日志

    五、PXC集群运维与故障处理:保障稳定运行

    PXC集群的运维工作主要包括监控节点状态、处理节点故障和优化集群性能。

    5.1 节点状态监控:健康检查

    监控PXC集群中各节点的状态是运维的重要任务。通过查看wsrep_local_state状态变量,可以了解节点的当前状态。一个健康的集群,大部分节点应处于Synced状态。

    #publish-mermaid-4-1792075098134{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#publish-mermaid-4-1792075098134 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#publish-mermaid-4-1792075098134 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#publish-mermaid-4-1792075098134 .error-icon{fill:#552222;}#publish-mermaid-4-1792075098134 .error-text{fill:#552222;stroke:#552222;}#publish-mermaid-4-1792075098134 .edge-thickness-normal{stroke-width:1px;}#publish-mermaid-4-1792075098134 .edge-thickness-thick{stroke-width:3.5px;}#publish-mermaid-4-1792075098134 .edge-pattern-solid{stroke-dasharray:0;}#publish-mermaid-4-1792075098134 .edge-thickness-invisible{stroke-width:0;fill:none;}#publish-mermaid-4-1792075098134 .edge-pattern-dashed{stroke-dasharray:3;}#publish-mermaid-4-1792075098134 .edge-pattern-dotted{stroke-dasharray:2;}#publish-mermaid-4-1792075098134 .marker{fill:#333333;stroke:#333333;}#publish-mermaid-4-1792075098134 .marker.cross{stroke:#333333;}#publish-mermaid-4-1792075098134 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#publish-mermaid-4-1792075098134 p{margin:0;}#publish-mermaid-4-1792075098134 .pieCircle{stroke:black;stroke-width:2px;opacity:0.7;}#publish-mermaid-4-1792075098134 .pieCircle.highlighted{scale:1.05;opacity:1;}#publish-mermaid-4-1792075098134 .pieCircle.highlightedOnHover:hover{transition-duration:250ms;scale:1.05;opacity:1;}#publish-mermaid-4-1792075098134 .pieOuterCircle{stroke:black;stroke-width:2px;fill:none;}#publish-mermaid-4-1792075098134 .pieTitleText{text-anchor:middle;font-size:25px;fill:black;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}#publish-mermaid-4-1792075098134 .slice{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;fill:#333;font-size:17px;}#publish-mermaid-4-1792075098134 .legend text{fill:black;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:17px;}#publish-mermaid-4-1792075098134 .node .neo-node{stroke:#9370DB;}#publish-mermaid-4-1792075098134 [data-look=\”neo\”].node rect,#publish-mermaid-4-1792075098134 [data-look=\”neo\”].cluster rect,#publish-mermaid-4-1792075098134 [data-look=\”neo\”].node polygon{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-4-1792075098134 [data-look=\”neo\”].swimlane.cluster rect{filter:none;}#publish-mermaid-4-1792075098134 [data-look=\”neo\”].node path{stroke:#9370DB;stroke-width:1px;}#publish-mermaid-4-1792075098134 [data-look=\”neo\”].node .outer-path{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-4-1792075098134 [data-look=\”neo\”].node .neo-line path{stroke:#9370DB;filter:none;}#publish-mermaid-4-1792075098134 [data-look=\”neo\”].node circle{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-4-1792075098134 [data-look=\”neo\”].node circle .state-start{fill:#000000;}#publish-mermaid-4-1792075098134 [data-look=\”neo\”].icon-shape .icon{fill:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-4-1792075098134 [data-look=\”neo\”].icon-shape .icon-neo path{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-4-1792075098134 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}67%33%PXC节点状态分布示例SyncedDonorError

    该饼图展示了一个包含3个节点的PXC集群,其中2个节点处于正常同步状态,1个节点正在执行数据捐赠,集群整体运行健康。

    5.2 故障转移:节点宕机后的恢复

    当集群中的一个节点发生宕机时,PXC集群会自动进行故障转移。剩余的节点会检测到故障节点,并继续提供服务,确保业务的连续性。

    #publish-mermaid-5-1792075098148{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#publish-mermaid-5-1792075098148 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#publish-mermaid-5-1792075098148 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#publish-mermaid-5-1792075098148 .error-icon{fill:#552222;}#publish-mermaid-5-1792075098148 .error-text{fill:#552222;stroke:#552222;}#publish-mermaid-5-1792075098148 .edge-thickness-normal{stroke-width:1px;}#publish-mermaid-5-1792075098148 .edge-thickness-thick{stroke-width:3.5px;}#publish-mermaid-5-1792075098148 .edge-pattern-solid{stroke-dasharray:0;}#publish-mermaid-5-1792075098148 .edge-thickness-invisible{stroke-width:0;fill:none;}#publish-mermaid-5-1792075098148 .edge-pattern-dashed{stroke-dasharray:3;}#publish-mermaid-5-1792075098148 .edge-pattern-dotted{stroke-dasharray:2;}#publish-mermaid-5-1792075098148 .marker{fill:#333333;stroke:#333333;}#publish-mermaid-5-1792075098148 .marker.cross{stroke:#333333;}#publish-mermaid-5-1792075098148 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#publish-mermaid-5-1792075098148 p{margin:0;}#publish-mermaid-5-1792075098148 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#publish-mermaid-5-1792075098148 .cluster-label text{fill:#333;}#publish-mermaid-5-1792075098148 .cluster-label span{color:#333;}#publish-mermaid-5-1792075098148 .cluster-label span p{background-color:transparent;}#publish-mermaid-5-1792075098148 .label text,#publish-mermaid-5-1792075098148 span{fill:#333;color:#333;}#publish-mermaid-5-1792075098148 .node rect,#publish-mermaid-5-1792075098148 .node circle,#publish-mermaid-5-1792075098148 .node ellipse,#publish-mermaid-5-1792075098148 .node polygon,#publish-mermaid-5-1792075098148 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#publish-mermaid-5-1792075098148 .rough-node .label text,#publish-mermaid-5-1792075098148 .node .label text,#publish-mermaid-5-1792075098148 .image-shape .label,#publish-mermaid-5-1792075098148 .icon-shape .label{text-anchor:middle;}#publish-mermaid-5-1792075098148 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#publish-mermaid-5-1792075098148 .rough-node .label,#publish-mermaid-5-1792075098148 .node .label,#publish-mermaid-5-1792075098148 .image-shape .label,#publish-mermaid-5-1792075098148 .icon-shape .label{text-align:center;}#publish-mermaid-5-1792075098148 .node.clickable{cursor:pointer;}#publish-mermaid-5-1792075098148 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#publish-mermaid-5-1792075098148 .arrowheadPath{fill:#333333;}#publish-mermaid-5-1792075098148 .edgePath .path{stroke:#333333;stroke-width:1px;}#publish-mermaid-5-1792075098148 .flowchart-link{stroke:#333333;fill:none;}#publish-mermaid-5-1792075098148 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-5-1792075098148 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#publish-mermaid-5-1792075098148 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-5-1792075098148 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#publish-mermaid-5-1792075098148 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#publish-mermaid-5-1792075098148 .cluster text{fill:#333;}#publish-mermaid-5-1792075098148 .cluster span{color:#333;}#publish-mermaid-5-1792075098148 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#publish-mermaid-5-1792075098148 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#publish-mermaid-5-1792075098148 rect.text{fill:none;stroke-width:0;}#publish-mermaid-5-1792075098148 .icon-shape,#publish-mermaid-5-1792075098148 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-5-1792075098148 .icon-shape p,#publish-mermaid-5-1792075098148 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#publish-mermaid-5-1792075098148 .icon-shape .label rect,#publish-mermaid-5-1792075098148 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-5-1792075098148 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#publish-mermaid-5-1792075098148 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#publish-mermaid-5-1792075098148 .node .neo-node{stroke:#9370DB;}#publish-mermaid-5-1792075098148 [data-look=\”neo\”].node rect,#publish-mermaid-5-1792075098148 [data-look=\”neo\”].cluster rect,#publish-mermaid-5-1792075098148 [data-look=\”neo\”].node polygon{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-5-1792075098148 [data-look=\”neo\”].swimlane.cluster rect{filter:none;}#publish-mermaid-5-1792075098148 [data-look=\”neo\”].node path{stroke:#9370DB;stroke-width:1px;}#publish-mermaid-5-1792075098148 [data-look=\”neo\”].node .outer-path{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-5-1792075098148 [data-look=\”neo\”].node .neo-line path{stroke:#9370DB;filter:none;}#publish-mermaid-5-1792075098148 [data-look=\”neo\”].node circle{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-5-1792075098148 [data-look=\”neo\”].node circle .state-start{fill:#000000;}#publish-mermaid-5-1792075098148 [data-look=\”neo\”].icon-shape .icon{fill:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-5-1792075098148 [data-look=\”neo\”].icon-shape .icon-neo path{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-5-1792075098148 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}失去连接

    节点1(宕机)

    剩余节点检测到故障

    节点2 & 节点3

    继续对外提供服务

    集群自动恢复

    该流程图描述了当节点1宕机后,节点2和节点3检测到故障并继续处理请求,实现了无缝的故障转移。

    5.3 数据一致性保障:流控机制

    为了防止集群过载导致的数据不一致,Galera协议引入了流控机制。当某个节点处理事务的速度跟不上其他节点时,它会向集群广播流控信号,请求其他节点减慢事务提交速度,从而给该节点足够的时间来处理积压的事务,保证数据最终一致性。

    赞(0)
    未经允许不得转载:171主机测评 » MySQL PXC集群原理与Galera协议深度剖析:高可用数据库架构揭秘
    分享到: 更多 (0)

    评论 抢沙发

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址