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"]
    }
  }]
}
相关推荐
aliprice11 分钟前
逆向拆解:用速卖通图片搜索破解竞品设计,找到你的差异化定价空间
大数据·跨境电商·电商
hg011829 分钟前
埃及:在变局中重塑发展韧性
大数据·人工智能·物联网
向量引擎小橙1 小时前
“2026数据枯竭”警报拉响:合成数据如何成为驱动AI进化的“新石油”?
大数据·人工智能·深度学习·集成学习
飞Link1 小时前
【大数据】SparkSQL常用操作
大数据·数据挖掘·spark
阿里云大数据AI技术1 小时前
Agentic Search: AI驱动的下一代企业搜索
搜索引擎
m0_466525291 小时前
东软添翼AI 2.0获评医疗健康标杆AI Agent TOP10
大数据·人工智能
光算科技2 小时前
AI重写工具导致‘文本湍流’特征|如何人工消除算法识别标记
大数据·人工智能·算法
geoqiye3 小时前
2026官方认证:贵阳宠物行业短视频运营TOP5评测
大数据·python·宠物
Elastic 中国社区官方博客3 小时前
JINA AI 与 Elasticsearch 的集成
大数据·人工智能·elasticsearch·搜索引擎·全文检索·jina
TOWE technology4 小时前
聚焦价值 重塑增长
大数据·人工智能·企业