概述
跨集群复制,是发生在集群的索引级别,将一个集群的索引数据可以同步复制到另一个集群。有两种角色,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 |
演示流程
具体步骤
首先确保俩个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/_searchGET test_copy/_settings
3.在Leader端对索引test执行删除、更新、写入操作
DELETE /test/_doc/1?prettyPUT 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?prettyPUT test_copy/_doc/3{"msg" : "value3 new"}PUT test_copy/_doc/5{"msg" : "value5"}GET test_copy/_search
版权声明:本文为CSDN博主「蜗牛^_^」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/yuyinghua0302/article/details/107295206
