• ElasticSearch集群介绍二


    ElasticSearch集群

    一个运行中的 Elasticsearch 实例称为一个 节点,而集群是由一个或者多个拥有相同 cluster.name 配置的节点组成, 它们共同承担数据和负载的压力。当有节点加入集群中或者从集群中移除节点时,集群将会重新平均分布所有的数据。

    当一个节点被选举成为 主 节点时, 它将负责管理集群范围内的所有变更,例如增加、删除索引,或者增加、删除节点等。 而主节点并不需要涉及到文档级别的变更和搜索等操作,所以当集群只拥有一个主节点的情况下,即使流量的增加它也不会成为瓶颈。 任何节点都可以成为主节点。我们的示例集群就只有一个节点,所以它同时也成为了主节点。

    作为用户,我们可以将请求发送到 集群中的任何节点 ,包括主节点。 每个节点都知道任意文档所处的位置,并且能够将我们的请求直接转发到存储我们所需文档的节点。 无论我们将请求发送到哪个节点,它都能负责从各个包含我们所需文档的节点收集回数据,并将最终结果返回給客户端。 Elasticsearch 对这一切的管理都是透明的。

    ElasticSearch集群健康状态:

    查看集群状态:

    curl -XGET http://localhost:9200/_cluster/health

    显示结果如下:

    {
       "cluster_name":          "elk-cluster",
       "status":                "green", 
       "timed_out":             false,
       "number_of_nodes":       1,
       "number_of_data_nodes":  1,
       "active_primary_shards": 0,
       "active_shards":         0,
       "relocating_shards":     0,
       "initializing_shards":   0,
       "unassigned_shards":     0
    }

    其中,status字段记录了当前集群的健康状态,共有三种类型:

    green:所有的主分片和副本分片都运行正常。

    yellow:所有的主分片运行正常,但有副本分片运行不正常。

    red:有主分片没有正常运行。

    查看但节点的集群健康状态,"status"字段的值是"yellow"。"unassigned_shards"字段记录了有多少个副本分片没有被分配到任何节点中。

    因为集群中只有一个节点,如果主分片和副本分片都在该节点上是没有任何意义的。

    {
      "cluster_name": "elasticsearch",
      "status": "yellow", 
      "timed_out": false,
      "number_of_nodes": 1,
      "number_of_data_nodes": 1,
      "active_primary_shards": 3,
      "active_shards": 3,
      "relocating_shards": 0,
      "initializing_shards": 0,
      "unassigned_shards": 3, 
      "delayed_unassigned_shards": 0,
      "number_of_pending_tasks": 0,
      "number_of_in_flight_fetch": 0,
      "task_max_waiting_in_queue_millis": 0,
      "active_shards_percent_as_number": 50
    }

    为了试验,我们在一个节点上运行两个elasticsearch实例:

    将已经运行的es目录拷贝一份,修改配置文件:

    cluster.name: elk-cluster
    node.name: node-2
    path.data: /data/local/elasticsearch-node2/data
    path.logs: /data/local/elasticsearch-node2/logs
    http.port: 9201

    注意,要保持cluster.name的值一致。

    同时,由于node2目录是从node1复制过来的,需要删除data目录下的数据。

    修改完成后,就可以启动es实例了。启动成功后,副本分片自动转移到了node2上,此时再查看集群健康状态:

    curl -XGET http://localhost:9200/_cluster/health

    结果如下:

    {
      "cluster_name": "elk-cluster",
      "status": "green",
      "timed_out": false,
      "number_of_nodes": 2,
      "number_of_data_nodes": 2,
      "active_primary_shards": 16,
      "active_shards": 32,
      "relocating_shards": 0,
      "initializing_shards": 0,
      "unassigned_shards": 0,
      "delayed_unassigned_shards": 0,
      "number_of_pending_tasks": 0,
      "number_of_in_flight_fetch": 0,
      "task_max_waiting_in_queue_millis": 0,
      "active_shards_percent_as_number": 100
    }

    可以看到,"status"字段已经变成了"green"。通过elasticsearch-head查看:

    在水平扩容时,如果节点的数量多于现在的主分片和副本分片数量的和该怎么办?

    由于主分片的数量在创建索引的时候就已确定了。此时可以通过增加副本分片的数量,来水平扩容集群节点数量。

    curl -XPUT http://localhost:9200/people/_settings -d'
    {
       "number_of_replicas" : 3
    }'

    上例中,将副本分片的数量设置为3(默认为1)。

    读操作——搜索和返回数据——可以同时被主分片或副本分片所处理,所以当集群总拥有越多的副本分片时,也将拥有越高的吞吐量。

  • 相关阅读:
    关于WP7的Loaded事件[转]
    皮皮书屋的变态验证码
    近期学习内容for mobile
    一个js问题引发的同时吐槽
    powerdesigner 概念模型转物理模型时的丢表问题
    偶的处女文近期学习计划
    web布局实现圆角,兼容所有的浏览器
    最近面试asp.net碰到的一些题
    网站推广心得
    兼容ie6的png格式图片的背景透明问题
  • 原文地址:https://www.cnblogs.com/ahaii/p/8276708.html
Copyright © 2020-2023  润新知