云原生多模数据库 Lindorm搜索引擎支持跨集群复制,可用于灾难恢复与数据容灾、读写分离等场景。本文介绍在云原生多模数据库 Lindorm搜索引擎中如何使用跨集群复制能力。
注意事项
Lindorm搜索引擎跨集群复制目前处于公测阶段,如需体验该功能,请联系Lindorm技术支持(钉钉号:s0s3eg3)后台开启。
前置说明
搜索引擎版本不能低于3.10.4。
当前跨集群复制支持以下能力:
主备集群同步:确保主备集群间数据实时同步
主集群写入支持:
批量写入(bulk)
单文档操作(put)
按ID删除(delete by id)
最终一致性操作(不保证实时完全一致):
按ID更新(update by id)
按条件更新(update by query)
按条件删除(delete by query)
跨集群复制
目前跨集群复制需要通过ES API进行配置,暂未提供页面配置。
创建leader索引
用于在主集群上创建leader索引。
语法
PUT /leaderindex参数说明
参数名称 | 说明 |
ccr_mode | 指定跨集群复制模式。 parallel:表示并行同步,主集群通过多partition同步到备集群。 |
ccr_id | 自定义集群id。 注意:双向同步时,区分不同集群的数据流,主备集群id不能一致。 |
示例
curl -XPUT "host:port/leaderindex" -H 'Content-Type: application/json' -d'{
"settings": {
"index": {
"ccr_mode": "parallel",
"ccr_id": 1
}
},
"mappings": {
"properties": {
"title": {
"type": "keyword"
},
"date": {
"type": "date"
}
}
}
}'创建follow索引
用于在备集群上创建follow索引。
语法
PUT /followindex参数说明
参数名称 | 说明 |
ccr_mode | 指定跨集群复制模式。 parallel:表示并行同步,主集群通过多partition同步到备集群。 |
ccr_id | 自定义集群id。 注意:双向同步时,区分不同集群的数据流,主备集群id不能一致。 |
示例
curl -XPUT "host:port/followindex" -H 'Content-Type: application/json' -d'{
"settings": {
"index": {
"ccr_mode": "parallel",
"ccr_id": 2
}
},
"mappings": {
"properties": {
"title": {
"type": "keyword"
},
"date": {
"type": "date"
}
}
}
}'启动同步数据
在备集群上执行命令,followindex 从 leaderindex开始同步数据。
语法
POST _plugins/_ccr/followindex/start_follow参数说明
参数名称 | 说明 |
message_cluster | 指定消息引擎地址。 默认使用内置的消息引擎,message_cluster地址可以通过leader集群的 |
leader_index | 主集群的leaderindex。 指定follow索引从主集群某个索引同步数据。 |
示例
curl -XPOST --header 'Content-Type: application/json' -d '{
"message_cluster" : "ld-txxxx-solr-001.lindorm.rds.aliyuncs.com/172.21.64.28:30080",
"leader_index" : "leaderindex"
}' 'http://host:port/_plugins/_ccr/followindex/start_follow'停止同步数据
在备集群上执行命令,followindex 从 leaderindex停止同步数据。
语法
POST _plugins/_ccr/followindex/stop_follow参数说明
参数名称 | 说明 |
message_cluster | 指定消息引擎地址。 默认使用内置的消息引擎,message_cluster地址可以通过leader集群的 |
leader_index | 主集群的leaderindex。 指定follow索引停止主集群某个索引的数据同步。 |
示例
curl -XPOST "host:port/_plugins/_ccr/followindex/stop_follow" -H 'Content-Type: application/json' -d'{
"leader_index" : "leaderindex",
"message_cluster" : "ld-xxx.lindorm.rds.aliyuncs.com/172.xx.xx.xx:30080"
}'诊断链路信息
创建leader索引和follow索引后,可以分别在两个集群使用下面命令检查主备链路情况。
语法
GET _plugins/_ccr/info?pretty示例
curl -XGET host:port/_plugins/_ccr/info?pretty