Elasticsearch跨集群搜索(Cross Cluster Search)
1、简介
Elasticsearch在5.3版本中引入了Cross Cluster Search(CCS 跨集群搜索)功能,用来替换掉要被废弃的Tribe Node。类似Tribe Node,Cross Cluster Search用来实现跨集群的数据搜索。
2、配置Cross Cluster Search
假设我们有2个ES集群:
Node
|
Address
|
Port
|
Transport Port
|
Cluster
|
elasticsearch01
|
127.0.0.1
|
9201
|
9301
|
America
|
elasticsearch02
|
127.0.0.1
|
9202
|
9302
|
America
|
elasticsearch03
|
127.0.0.1
|
9203
|
9303
|
Europe
|
elasticsearch04
|
127.0.0.1
|
9204
|
9304
|
Europe
|
有2种方式可以用来配置CCS:
1)配置elasticsearch.yml
search:
remote:
america:
seeds: 127.0.0.1:9301
seeds: 127.0.0.1:9302
europe:
seeds: 127.0.0.1:9303
seeds: 127.0.0.1:9304
注意:以上方式,在配置的时候,需要remote cluster处在运行状态。比如在配置“america”的集群的时候,需要“europe”集群处在运行状态,否则节点无法启动成功。
2)使用 Cluster Settings API配置
curl -XPUT -H'Content-Type: application/json' localhost:9201/_cluster/settings -d '
{
"persistent": {
"search.remote": {
"america": {
"skip_unavailable": "true",
"seeds": ["127.0.0.1:9301","127.0.0.1:9302"]
},
"europe": {
"skip_unavailable": "true",
"seeds": ["127.0.0.1:9303","127.0.0.1:9304"]
}
}
}
}'
推荐使用API方式,可以方便的修改remote cluster的seeds和其他配置。
3、验证Cross Cluster Search
1)使用_remote/info查看CCS连接状态:
[root@localhost elasticsearch01]# curl -XGET -H 'Content-Type: application/json' localhost:9201/_remote/info?pretty
{
"america" : {
"seeds" : [
"127.0.0.1:9301",
"127.0.0.1:9302"
],
"http_addresses" : [
"127.0.0.1:9201",
"127.0.0.1:9202"
],
"connected" : true,
"num_nodes_connected" : 2,
"max_connections_per_cluster" : 3,
"initial_connect_timeout" : "30s"
},
"europe" : {
"seeds" : [
"127.0.0.1:9303",
"127.0.0.1:9304"
],
"http_addresses" : [
"127.0.0.1:9203",
"127.0.0.1:9204"
],
"connected" : true,
"num_nodes_connected" : 2,
"max_connections_per_cluster" : 3,
"initial_connect_timeout" : "30s"
}
}
2)使用跨集群搜索:
同时查询2个集群的数据:
GET /cluster_name:index,cluster_name:index/_search
GET */index/_search
java API 示例:
//查询所有集群,以appIndex-开头的数据 SearchRequest searchRequest = Requests.searchRequest("*:appIndex-*"); SearchResponse response = es.getClient().search(searchRequest).get();
4、Disable Cross Cluster Search
使用API设置:
curl -XPUT -H'Content-Type: application/json' localhost:9201/_cluster/settings -d '
{
"persistent": {
"search.remote": {
"america": {
"skip_unavailable": null,
"seeds": null
},
"europe": {
"skip_unavailable": null,
"seeds": null
}
}
}
}'
5、CCS的配置
search.remote.${cluster_alias}.skip_unavailable:查询的时候skip不可达的集群,默认false,推荐设置为true
search.remote.connect:默认true,即任何node都作为一个cross-cluster client去连接remote cluster,跨集群搜索的请求必须发给cross-cluster client。
search.remote.node.attr:设置remote node的属性,比如search.remote.node.attr:gateway这样设置,只有node.attr.gateway: true的node才会被该node连接用来做CCS查询。
6、问题
实际使用中遇到的一个问题:https://discuss.elastic.co/t/elasticsearch-ccs-client-get-timeout-when-remote-cluster-is-isolated-by-firewall/152019
因此引入的issue:https://github.com/elastic/elasticsearch/issues/34405
参考:
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/modules-cross-cluster-search.html
http://kelonsoftware.com/elasticsearch-cross-cluster-search/
作者:阿凡卢
出处:https://www.cnblogs.com/luxiaoxun/p/9865389.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App