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查詢。
參考:
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/modules-cross-cluster-search.html