Elasticsearch 跨集群复制的实现

跨集群复制,是发生在集群的索引级别,将一个集群的索引数据可以同步复制到另一个集群。有两种角色,Leader和Follower。其中Leader是数据的源头,Follower是数据的副本方。设置了跨集群复制,那么在Leader方索引发生了增删改等,在Follower方该对应索引数据都能得到及时体现,但是在Follower方是不可对该索引数据进行增删改操作的。

测试环境

两个es集群,每个集群有一个节点,均配置了kibana

角色es集群节点索引
Leadertest-1192.168.52.127test
Followertest-2192.168.52.128test_copy

 

 

 

 

演示流程

具体步骤

首先确保俩个es集群均有CCR权限,可以通过GET _xpack查看,确保CCR的available和enabled均为true。没有权限的话,可以先尝试使用30天的试用期。如下图,是已经打开30天试用期的效果。

1.在Leader对应的集群test-1创建索引test,并批量写入数据。
PUT test
{
    "settings" : {
        "number_of_shards" : 3,
        "number_of_replicas" : 0
    }
}

POST /test/_bulk
{ "index" : {"_id" : "1" } }
{ "msg" : "value1" }
{ "index" : {"_id" : "2" } }
{ "msg" : "value2" }
{ "index" : {"_id" : "3" } }
{ "msg" : "value3" }

GET test/_search

2.在Follower创建follower,并查看对应索引test_copy与索引test是否配置一样、数据一样。创建follower可以通过kibana界面操作,也可以通过es api操作。
1)通过kibana界面操作

2)通过es api操作
PUT /test_copy/_ccr/follow?wait_for_active_shards=1
{
  "remote_cluster" : "test-1",
  "leader_index" : "test",
  "max_read_request_operation_count" : 1024,
  "max_outstanding_read_requests" : 16,
  "max_read_request_size" : "1024k",
  "max_write_request_operation_count" : 32768,
  "max_write_request_size" : "16k",
  "max_outstanding_write_requests" : 8,
  "max_write_buffer_count" : 512,
  "max_write_buffer_size" : "512k",
  "max_retry_delay" : "10s",
  "read_poll_timeout" : "30s"
}

3)查看对应索引test_copy与索引test是否配置一样、数据一样
GET test_copy/_search

GET test_copy/_settings

3.在Leader端对索引test执行删除、更新、写入操作
DELETE /test/_doc/1?pretty

PUT test/_doc/2
{
    "msg" : "value2 new"
}

PUT test/_doc/4
{
    "msg" : "value4"
}

GET test/_search

4.在Follower端查看索引test_copy是否变化,发现索引数据已发生改动
GET test_copy/_search

5.在Follower端对索引test_copy执行删除、更新、写入操作,发现会报错
DELETE /test_copy/_doc/2?pretty

PUT test_copy/_doc/3
{
    "msg" : "value3 new"
}

PUT test_copy/_doc/5
{
    "msg" : "value5"
}

GET test_copy/_search

参考:Elasticsearch:跨集群复制 Cross-cluster replication(CCR)

           官网

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值