以下都是在 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%
快速了解集群的健康狀況
集群有三種狀態(tài):green确虱、yellow凶掰、red
green:每個索引的 primary shard 和 replica shard 都是 active
yellow:每個索引的 primary shard 都是 active橘原,但是部分 replica shard 不是 active(即不可用)
red:不是所有索引的 primary shard 都是 active(即部分索引有數(shù)據(jù)丟失了)
解釋:為什么現(xiàn)在處于 yellow
狀態(tài)娃承?
因為現(xiàn)在只啟動了一個 Elasticsearch 進(jìn)程,相當(dāng)于只有一個 node 節(jié)點(diǎn),現(xiàn)在 Elasticsearch 中有一個 Index 索引,就是 Kibana 自己內(nèi)置建立的 Index∠捅冢現(xiàn)在 Kibana 自己建立的 Index 索引是 1 個 primary shard 和 1 個 replica shard。當(dāng)前就一個node 節(jié)點(diǎn)埠忘,由于 primary shard 和 replica shard 不能在同一臺機(jī)器上(為了容錯)脾拆, 所以只有 primary shard 被分配到 node 節(jié)點(diǎn)上并啟動了,replica shard 沒有被分配到 node 節(jié)點(diǎn)上并啟動莹妒,所以 active_shards_percent 是 50%名船,狀態(tài)是 yellow。
此時只要啟動第二個 Elasticsearch 進(jìn)程旨怠,集群中就會有 2 個 node 節(jié)點(diǎn)渠驼,然后那 1 個 replica shard 就會自動分配過去,然后集群的狀態(tài)就會變成 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%
對比兩次結(jié)果迷扇,當(dāng)只有一個 Elasticsearch 進(jìn)程時:yellow,50%拘哨,當(dāng)啟動第二個 Elasticsearch 進(jìn)程時: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
簡單的索引操作
創(chuàng)建索引: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