Elasticsearch 如何实现跨数据中心的数据同步?

实战场景

双数据中心容灾,要求RPO<5分钟,RTO<30分钟

‌RPO(Recovery Point Objective)‌:

RPO指的是灾难发生后,系统能够恢复到的数据更新点的时间。简单来说,它衡量的是数据丢失的量。在你的例子中,RPO<5分钟意味着在灾难发生后,系统能够恢复到灾难发生前5分钟内的数据状态,从而确保数据丢失量控制在5分钟以内。

‌RTO(Recovery Time Objective)‌:

RTO则是指从灾难发生到业务系统完全恢复并可以重新提供服务所需的时间。它衡量的是业务中断的时间长度。在你的例子中,RTO<30分钟意味着在灾难发生后,系统能够在30分钟内完全恢复并重新提供服务,从而将业务中断的时间控制在30分钟以内。

1. CCR核心配置(北京->上海 单向同步)

bash:ccr_setup.sh 复制代码
# 建立集群间安全连接
PUT /_cluster/settings
{
  "persistent": {
    "cluster.remote.shanghai_cluster.seeds": "es-sh-node1:9300,es-sh-node2:9300",
    "cluster.remote.shanghai_cluster.skip_unavailable": true
  }
}

# 创建跟随策略(同步订单索引)
PUT /_ccr/auto_follow/jd_orders
{
  "remote_cluster" : "shanghai_cluster",
  "leader_index_patterns" : ["jd_orders-*"],
  "follow_index_pattern" : "sh_{{leader_index}}",
  "max_read_request_operation_count" : 5120,
  "max_outstanding_read_requests" : 24
}

2. Logstash增量备份(双向同步商品索引)

ruby:logstash/pipeline/jd_goods.conf 复制代码
input {
  elasticsearch {
    hosts => ["http://es-bj-node1:9200"]
    index => "jd_goods"
    query => '{ "query": { "range": { "@timestamp": { "gte": "now-5m" }}}}'
    docinfo => true
    size => 500
    scroll => "5m"
  }
}

output {
  # 上海集群写入
  elasticsearch {
    hosts => ["http://es-sh-node1:9200"]
    index => "%{[@metadata][_index]}"
    document_id => "%{[@metadata][_id]}"
    pipeline => "timestamp_pipeline"
  }
  
  # 本地备份
  elasticsearch {
    hosts => ["http://localhost:9200"]
    index => "jd_goods_backup"
  }
}

3. 网络优化配置

yaml:config/elasticsearch.yml 复制代码
# 跨数据中心专用线程池
thread_pool.search.size: 32
thread_pool.search.queue_size: 2000

# 传输层参数优化
transport.tcp.compress: true
transport.profiles.default.tcp_keep_alive: true
transport.profiles.default.tcp_no_delay: true

监控方案(基于Kibana):

json:.kibana/monitoring.json 复制代码
{
  "alert": {
    "name": "CCR延迟告警",
    "conditions": {
      "script": "ctx.results[0].hits.hits[0]._source.follower_lag > 300000"
    },
    "actions": {
      "webhook": "http://alert.jd.com/ccr_warn"
    }
  }
}

实战经验

  1. 使用专用10Gbps通道,实测同步延迟120-180ms
  2. 索引分片数=数据中心数量×2(北京8节点集群使用24分片)
  3. 采用时间戳管道统一时区:
bash 复制代码
PUT _ingest/pipeline/timestamp_pipeline
{
  "processors": [{
    "date": {
      "field": "bj_timestamp",
      "target_field": "@timestamp",
      "timezone": "Asia/Shanghai",
      "formats": ["ISO8601"]
    }
  }]
}
相关推荐
yczn12333 分钟前
3D可视化数字孪生智能服务平台-物联网智控节能控、管、维一体化技术架构
大数据·网络·人工智能
静听山水35 分钟前
PostgreSQL/Hologres 系统表 pg_class 详解
大数据
远方160935 分钟前
57-Oracle SQL Profile(23ai)实操
大数据·数据库·sql·oracle·database
Blossom39 分钟前
Apache Iceberg Delete File 解析
大数据
189228048613 小时前
NW849NX721美光固态闪存NX745NX751
大数据·服务器·科技
致Great9 小时前
MCP出现的意义是什么?让 AI 智能体更模块化
大数据·人工智能·rag
远方16099 小时前
53-Oracle sqlhc多版本实操含(23 ai)
大数据·数据库·sql·oracle·database
金融小师妹11 小时前
基于LSTM-GARCH混合模型的“获利了结”量化解析:黄金单日1.27%跌幅的技术性归因
大数据·人工智能·算法
人大博士的交易之路12 小时前
龙虎榜——20250620
大数据·数学建模·数据挖掘·程序员创富·缠中说禅·龙虎榜
hwj运维之路12 小时前
大数据系统架构实践(一):Zookeeper集群部署
大数据·zookeeper·系统架构