美文网首页Elasticsearch 入门教程程序员
Elasticsearch(四)简单的集群管理

Elasticsearch(四)简单的集群管理

作者: 与蟒唯舞 | 来源:发表于2017-08-25 16:12 被阅读227次

    以下都是在 Kibana 的 Dev Tools 界面操作 Elasticsearch。

    快速检查集群的健康状况

    命令:GET _cat/health?v

    epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
    1503367503 10:05:03  elasticsearch yellow          1         1      1   1    0    0        1             0                  -                 50.0%
    
    快速了解集群的健康状况

    集群有三种状态:greenyellowred

    • green:每个索引的 primary shard 和 replica shard 都是 active

    • yellow:每个索引的 primary shard 都是 active,但是部分 replica shard 不是 active(即不可用)

    • red:不是所有索引的 primary shard 都是 active(即部分索引有数据丢失了)

    解释:为什么现在处于 yellow 状态?
    因为现在只启动了一个 Elasticsearch 进程,相当于只有一个 node 节点,现在 Elasticsearch 中有一个 Index 索引,就是 Kibana 自己内置建立的 Index。现在 Kibana 自己建立的 Index 索引是 1 个 primary shard 和 1 个 replica shard。当前就一个node 节点,由于 primary shard 和 replica shard 不能在同一台机器上(为了容错), 所以只有 primary shard 被分配到 node 节点上并启动了,replica shard 没有被分配到 node 节点上并启动,所以 active_shards_percent 是 50%,状态是 yellow。

    此时只要启动第二个 Elasticsearch 进程,集群中就会有 2 个 node 节点,然后那 1 个 replica shard 就会自动分配过去,然后集群的状态就会变成 green。

    epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
    1503368887 10:28:07  elasticsearch green           2         2      2   1    0    0        0             0                  -                100.0%
    

    对比两次结果,当只有一个 Elasticsearch 进程时:yellow,50%,当启动第二个 Elasticsearch 进程时:green,100%。

    快速查看集群中的索引

    命令:GET /_cat/indices?v

    health status index   uuid                   pri rep docs.count docs.deleted store.size pri.store.size
    yellow open   .kibana ZNJy2-qsRGehTmaYqDF_FQ   1   1          1            0      3.2kb          3.2kb
    
    简单的索引操作

    创建索引:PUT /test_index?pretty

    health status index      uuid                   pri rep docs.count docs.deleted store.size pri.store.size
    yellow open   test_index urdYXybbRpiW7OOaUki7Ig   5   1          0            0       810b           810b
    yellow open   .kibana    ZNJy2-qsRGehTmaYqDF_FQ   1   1          1            0      3.2kb          3.2kb
    

    删除索引:DELETE /test_index?pretty

    health status index   uuid                   pri rep docs.count docs.deleted store.size pri.store.size
    yellow open   .kibana ZNJy2-qsRGehTmaYqDF_FQ   1   1          1            0      3.2kb          3.2kb
    

    相关文章

      网友评论

        本文标题:Elasticsearch(四)简单的集群管理

        本文链接:https://www.haomeiwen.com/subject/zvgudxtx.html