Elasticsearch核心技术与实战学习笔记 36 | 配置跨集群搜索

一 序

本文属于极客时间Elasticsearch核心技术与实战学习笔记系列。

二 水平扩展的痛点

单集群 - 当水平扩展时,节点数不能无限增加

  • 当集群的 meta 信息(节点,索引,集群状态)过多,会导致更新压力变大,单个 Active Master 会成为性能瓶颈,导致整个集群无法正常工作

早期版本,通过 Tribe Node 可以实现多集群访问的需求,但是还存在一定的问题

  • Tribe Node 会以 Client Node 的方式加入集群。集群中 Master 节点的任务变更需要 Tribe Node 的回应才能继续
  • Tribe Node 不保存 Cluster State 信息,一旦重启,初始化很慢
  • 当多个集群存在索引重名的情况下,只能设置一种 Perfer 规则

2.1 跨集群搜索 - Cross Cluster Search

早期 Tribe Node 的方案存在一定的问题,现已被 Deprecated
ES5.3 引入跨集群搜索的功能(Cross Cluster Search),推荐使用

  • 允许任何节点扮演 federated 节点,以轻量的方式,将搜索请求进行代理
  • 不需要以 Client Node 的形式加入其它集群

2.2 集群的配置

2.3 demo

//启动3个集群

bin/elasticsearch -E node.name=cluster0node -E cluster.name=cluster0 -E path.data=cluster0_data -E discovery.type=single-node -E http.port=9200 -E transport.port=9300
bin/elasticsearch -E node.name=cluster1node -E cluster.name=cluster1 -E path.data=cluster1_data -E discovery.type=single-node -E http.port=9201 -E transport.port=9301
bin/elasticsearch -E node.name=cluster2node -E cluster.name=cluster2 -E path.data=cluster2_data -E discovery.type=single-node -E http.port=9202 -E transport.port=9302


//在每个集群上设置动态的设置
PUT _cluster/settings
{
  "persistent": {
    "cluster": {
      "remote": {
        "cluster0": {
          "seeds": [
            "127.0.0.1:9300"
          ],
          "transport.ping_schedule": "30s"
        },
        "cluster1": {
          "seeds": [
            "127.0.0.1:9301"
          ],
          "transport.compress": true,
          "skip_unavailable": true
        },
        "cluster2": {
          "seeds": [
            "127.0.0.1:9302"
          ]
        }
      }
    }
  }
}

我没有测试。

#cURL
curl -XPUT "http://localhost:9200/_cluster/settings" -H 'Content-Type: application/json' -d'
{"persistent":{"cluster":{"remote":{"cluster0":{"seeds":["127.0.0.1:9300"],"transport.ping_schedule":"30s"},"cluster1":{"seeds":["127.0.0.1:9301"],"transport.compress":true,"skip_unavailable":true},"cluster2":{"seeds":["127.0.0.1:9302"]}}}}}'

curl -XPUT "http://localhost:9201/_cluster/settings" -H 'Content-Type: application/json' -d'
{"persistent":{"cluster":{"remote":{"cluster0":{"seeds":["127.0.0.1:9300"],"transport.ping_schedule":"30s"},"cluster1":{"seeds":["127.0.0.1:9301"],"transport.compress":true,"skip_unavailable":true},"cluster2":{"seeds":["127.0.0.1:9302"]}}}}}'

curl -XPUT "http://localhost:9202/_cluster/settings" -H 'Content-Type: application/json' -d'
{"persistent":{"cluster":{"remote":{"cluster0":{"seeds":["127.0.0.1:9300"],"transport.ping_schedule":"30s"},"cluster1":{"seeds":["127.0.0.1:9301"],"transport.compress":true,"skip_unavailable":true},"cluster2":{"seeds":["127.0.0.1:9302"]}}}}}'


#创建测试数据
curl -XPOST "http://localhost:9200/users/_doc" -H 'Content-Type: application/json' -d'
{"name":"user1","age":10}'

curl -XPOST "http://localhost:9201/users/_doc" -H 'Content-Type: application/json' -d'
{"name":"user2","age":20}'

curl -XPOST "http://localhost:9202/users/_doc" -H 'Content-Type: application/json' -d'
{"name":"user3","age":30}'


#查询
GET /users,cluster1:users,cluster2:users/_search
{
  "query": {
    "range": {
      "age": {
        "gte": 20,
        "lte": 40
      }
    }
  }
}

当然在Kibana中,打开“Management管理”,然后单击“Index Patterns索引模式”。 

这个比较实用,比如通常的日志搜集,Logstash通常以logstash-YYYY.MMM.DD格式创建一系列索引,这个可以适配多天的。索引模式包含通配符(*)以匹配多个索引。

猜你喜欢

转载自blog.csdn.net/bohu83/article/details/106877716