概述

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

测试环境

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

Leader test-1 192.168.52.127 test
Follower test-2 192.168.52.128 test_copy

演示流程

image.png

具体步骤

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

1.在Leader对应的集群test-1创建索引test,并批量写入数据。

  1. PUT test
  2. {
  3. "settings" : {
  4. "number_of_shards" : 3,
  5. "number_of_replicas" : 0
  6. }
  7. }
  8. POST /test/_bulk
  9. { "index" : {"_id" : "1" } }
  10. { "msg" : "value1" }
  11. { "index" : {"_id" : "2" } }
  12. { "msg" : "value2" }
  13. { "index" : {"_id" : "3" } }
  14. { "msg" : "value3" }
  15. GET test/_search

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

1)通过kibana界面操作

image.png
image.png

2)通过es api操作

  1. PUT /test_copy/_ccr/follow?wait_for_active_shards=1
  2. {
  3. "remote_cluster" : "test-1",
  4. "leader_index" : "test",
  5. "max_read_request_operation_count" : 1024,
  6. "max_outstanding_read_requests" : 16,
  7. "max_read_request_size" : "1024k",
  8. "max_write_request_operation_count" : 32768,
  9. "max_write_request_size" : "16k",
  10. "max_outstanding_write_requests" : 8,
  11. "max_write_buffer_count" : 512,
  12. "max_write_buffer_size" : "512k",
  13. "max_retry_delay" : "10s",
  14. "read_poll_timeout" : "30s"
  15. }

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

  1. GET test_copy/_search
  2. GET test_copy/_settings

3.在Leader端对索引test执行删除、更新、写入操作

  1. DELETE /test/_doc/1?pretty
  2. PUT test/_doc/2
  3. {
  4. "msg" : "value2 new"
  5. }
  6. PUT test/_doc/4
  7. {
  8. "msg" : "value4"
  9. }
  10. GET test/_search

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

  1. GET test_copy/_search

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

  1. DELETE /test_copy/_doc/2?pretty
  2. PUT test_copy/_doc/3
  3. {
  4. "msg" : "value3 new"
  5. }
  6. PUT test_copy/_doc/5
  7. {
  8. "msg" : "value5"
  9. }
  10. GET test_copy/_search

版权声明:本文为CSDN博主「蜗牛^_^」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/yuyinghua0302/article/details/107295206