elasticsearch提供的一种复制索引的API。可以在集群内进行索引的复制,也可以跨集群进行索引的复制。
#不携带任何参数,将my-index索引的数据复制到new-index中。
POST _reindex
{
"source": {
"index": "my-index"#源索引
},
"dest": {
"index": "new-index"#目的索引
}
}
#指定match查询,只同步在源索引的查询结果至目的索引中。同时对目的索引的路由进行了设置。
POST _reindex
{
"source": {
"index": "source-index",
"query": {
"match": {
"company": "cat"
}
}
},
"dest": {
"index": "dest-index",
"routing": "=cat"
}
}
全称"cross cluster Replication",CCR是elasticsearch提供的一种将一个集群的数据实时的复制到另一个集群的功能,也称为跨集群复制。需要在elasticsearch中配置remote cluster(远端集群)。CCR使用的是追随者模式,在使用CCR时,首先我们需要将elasticsearch集群分别划分为leader集群和follower集群。同时对索引也需要进行指定leader索引与follower索引。
#设置远端集群
PUT _cluster/settings
{
"persistent": {
"cluster": {
"remote": {
"cluster_one": {
"seeds": [
"127.0.0.1:9300"
]
},
"cluster_two": {
"mode": "sniff",
"seeds": [
"127.0.0.1:9301"
],
"transport.compress": true,
"skip_unavailable": true
},
"cluster_three": {
"mode": "proxy",
"proxy_address": "127.0.0.1:9302"
}
}
}
}
}
#在CCR中指定远端集群的角色为leader,并设置需要同步哪些索引
PUT /_ccr/auto_follow/beats
{
"remote_cluster" : "leader",
"leader_index_patterns" :
[
"metricbeat-*",
"packetbeat-*"
],
"follow_index_pattern" : "{{leader_index}}-copy"
}
cos快照这里主要使用的是elasticsearch的snapshot功能,通过在对象存储中创建仓库,将elasticsearch集群中的数据备份至对象存储系统中,实现数据的备份。同时还可以将对象存储系统中的快照恢复至其他集群。
#在对象存储中创建一个仓库。如果使用云厂商的对象存储服务,则根据各云厂商的API进行仓库的创建。
PUT /_snapshot/my_repository
{
"type": "fs",
"settings": {
"location": "my_backup_location"
}
}
#在名为my_repository仓库中创建一个名为my_snapshot的快照
PUT /_snapshot/my_repository/my_snapshot
#对index_1,index_2进行备份
PUT /_snapshot/my_repository/snapshot_2?wait_for_completion=true
{
"indices": "index_1,index_2",
"ignore_unavailable": true,
"include_global_state": false,
"metadata": {
"taken_by": "user123",
"taken_because": "backup before upgrading"
}
}
#指定快照进行恢复
POST /_snapshot/my_repository/my_snapshot/_restore
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。