一、簡介html
Elasticsearch在5.3版本中引入了Cross Cluster Search(CCS 跨集羣搜索)功能,用來替換掉要被廢棄的Tribe Node。相似Tribe Node,Cross Cluster Search用來實現跨集羣的數據搜索。java
二、配置Cross Cluster Searchnode
假設咱們有2個ES集羣:json
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:app
1)配置elasticsearch.ymlcurl
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」集羣處在運行狀態,不然節點沒法啓動成功。elasticsearch
2)使用 Cluster Settings API配置ide
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和其餘配置。ui
三、驗證Cross Cluster Searchurl
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();
四、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
}
}
}
}'
五、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查詢。
參考:
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/modules-cross-cluster-search.html
http://kelonsoftware.com/elasticsearch-cross-cluster-search/