欢迎光临
我们一直在努力

Apache Doris 高可用与容灾:构建稳定可靠的数据分析平台

Apache Doris 高可用与容灾:构建稳定可靠的数据分析平台

  • Doris FE 高可用架构设计
  • Apache Doris 的 Frontend (FE) 节点主要负责元数据管理、查询解析、查询计划生成和查询调度等。在高可用架构中,FE 节点通常采用 Master-Observer 模式来实现高可用性。

    FE 节点角色与职责

    • Master: 负责处理所有写操作,管理元数据,进行负载均衡
    • Observer: 仅处理读请求,不参与选举,与 Master 保持数据同步
    • Follower: 参与选举,处理读写请求

    FE 高可用配置步骤

  • 修改 fe.conf 配置文件:
  • ```

    # 设置元数据存储目录

    METADATA_STORAGE_ROOT = /path/to/metadata

    # 设置节点角色为 Observer

    ROLE = OBSERVER

    # 设置 Master 节点地址

    MASTER_ADDRESSES = master_ip:port1,master_ip:port2

    # 设置选举超时时间

    ELECTION_TIMEOUT_MS = 5000

    ```

  • 启动 FE 节点:
  • ```

    sh start_fe.sh –daemon

    ```

  • 验证集群状态:
  • ```sql

    SHOW PROC '/cluster';

    ```

    检查各节点状态是否正常,确保 Observer 已成功加入集群。

    FE 高可用关键机制

    Doris FE 的高可用主要基于以下机制:

    • 选举机制:当 Master 节点宕机时,Follower 节点会进行选举,选出新 Master
    • 元数据同步:所有 FE 节点实时同步元数据,确保元数据一致性
    • 读写分离:Observer 节点分担读压力,Master 专注于处理写操作
  • Doris BE 副本机制详解
  • Backend (BE) 节点是 Doris 的数据存储节点,负责数据存储和查询执行。BE 副本机制是 Doris 高可用的核心保障。

    BE 副本机制原理

    Doris 使用多副本存储机制来确保数据高可用,默认情况下每个数据块有 3 个副本,分布在不同的 BE 节点上。

    副本状态管理

    Doris 将副本状态分为以下几种:

    副本状态描述处理方式
    OK 副本正常 无需处理
    COPIED 副本已复制 可转为 OK
    DECOMMISSIONED 节点下线 自动修复副本
    MISSING 副本丢失 触发修复流程
    ERROR 副本错误 需要人工干预

    BE 副本配置与管理

  • 配置副本数量:
  • 在 be.conf 中设置:

    ```

    # 默认副本数

    default_replication_num = 3

    ```

  • 设置存储介质:
  • ```

    # 存储根路径

    storage_root_path = /path/to/storage1

    # 冷热数据分离

    storage_root_path = /path/to/hot1:/path/to/cold1

    ```

  • 副本修复流程:
  • Doris 会自动检测副本状态,并在副本不足时自动复制:

    ```sql

    — 手动触发副本修复

    ALTER TABLE TABLE_NAME SET ("replication_num" = 3);

    — 查看复制任务状态

    SHOW REPAIR TABLE FROM db_name;

    ```

    BE 故障恢复流程

    当 BE 节点发生故障时,Doris 会自动执行以下流程:

  • 检测到 BE 节点心跳超时
  • 标记该节点上的副本为不可用
  • 根据复制策略在其他节点创建副本
  • 更新元数据,平衡负载
  • Doris 跨集群备份与恢复
  • 跨集群备份是保障数据安全的重要手段,Doris 提供了完整的备份恢复机制。

    备份原理与策略

    Doris 备份基于时间点快照,支持全量和增量备份。备份可以存储在本地的文件系统,也可以存储在远程对象存储服务中。

    备份类型特点适用场景
    全量备份 备份整个数据库 定期全量备份,数据量较小
    增量备份 仅备份变化数据 频繁备份,数据量大
    快照备份 基于时间点快照 需要精确恢复到某个时间点

    跨集群备份配置

  • 配置远程存储:
  • ```

    # 在 fe.conf 中配置

    REPOSITORY_FOR_BACKUP = hdfs://namenode:8020/doris_backup

    # 或使用云存储

    REPOSITORY_FOR_BACKUP = s3://bucket/doris_backup

    ```

  • 创建备份仓库:
  • ```sql

    CREATE REPOSITORY repo1

    WITH BROKER 'broker_name'

    PROPERTIES ("broker_username" = "user", "broker_password" = "password");

    ```

    备份与恢复流程

    下面是 Doris 跨集群备份与恢复的流程图:

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

    准备备份

    创建备份任务

    系统快照元数据

    传输数据到远程存储

    验证备份完整性

    完成备份

    启动恢复过程

    选择备份源

    创建恢复任务

    下载备份数据

    加载到目标集群

    验证恢复数据

    完成恢复

    备份完成

    恢复完成

    备份与恢复命令

  • 执行备份:
  • ```sql

    BACKUP DATABASE db_name TO repo1;

    ```

  • 查看备份任务:
  • ```sql

    SHOW BACKUP;

    ```

  • 执行恢复:
  • ```sql

    RESTORE FROM repo1 backup_id;

    ```

  • 示例:最小可用备份脚本
  • 下面是一个简单的 Bash 脚本,用于定期执行 Doris 备份:

    #!/bin/bash
    # 设置变量
    BACKUP_DATE=$(date +%Y%m%d)
    BACKUP_PATH="/data/doris_backup/$BACKUP_DATE"
    REPO="repo1"
    # 创建备份目录
    mkdir -p $BACKUP_PATH
    # 执行 Doris 备份
    mysql -h<fe_host> -P<port> -u<user> -p<password> -e "
    BACKUP DATABASE db_name TO $REPO WITH ('backup_format' = 'json');
    "
    # 等待备份完成
    mysql -h<fe_host> -P<port> -u<user> -p<password> -e "
    SHOW BACKUP;
    " | grep -q "FINISHED"
    # 检查备份结果
    if [ $? -eq 0 ]; then
    echo "Backup completed successfully"
    # 压缩备份文件
    tar -czf $BACKUP_PATH.tar.gz $BACKUP_PATH
    rm -rf $BACKUP_PATH
    else
    echo "Backup failed" >&2
    exit 1
    fi

    注意事项:

  • 执行备份前确保远程存储已正确配置且有足够空间
  • 定期验证备份数据的完整性和可恢复性
  • 备份过程对集群性能有一定影响,建议在业务低峰期执行
  • 增量备份需基于上一次全量备份,确保备份链完整性
  • 赞(0)
    未经允许不得转载:171主机测评 » Apache Doris 高可用与容灾:构建稳定可靠的数据分析平台
    分享到: 更多 (0)

    评论 抢沙发

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