/images/avatar.png

半生戎码

Elasticsearch 常用命令

状态查询

获取所有 _cat 系列的操作

curl http://localhost:9200/_cat
=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates

集群状态

curl -X GET "localhost:9200/_cluster/health?pretty"

节点状态

  • 节点简要信息
curl -X GET "localhost:9200/_cat/nodes?pretty&v"
ip          heap.percent ram.percent cpu load_1m load_5m load_15m node.role   master name
172.25.64.5           38          97   6    0.18    0.14     0.56 cdfhilmrstw -      es02
172.25.64.3           54          97   6    0.18    0.14     0.56 cdfhilmrstw -      es03
172.25.64.2           52          97   6    0.18    0.14     0.56 cdfhilmrstw *      es01
  • 节点详细信息
curl -X GET "localhost:9200/_nodes/stats/http?pretty"

后面的 http 是查看的属性,另外还有 indices, fs, http, jvm, os, process, thread_pool, discovery 等,支持组合(如 indices,fs,http)

Elasticsearch 性能优化

硬件配置优化

CPU 配置

一般说来,CPU 繁忙的原因有以下几个:

  • 线程中有无限空循环、无阻塞、正则匹配或者单纯的计算;
  • 发生了频繁的 GC;
  • 多线程的上下文切换;

大多数 Elasticsearch 部署往往对 CPU 要求不高(写入的时候比较耗 CPU)。因此,相对其它资源,具体配置多少个(CPU)不是那么关键。你应该选择具有多个内核的现代处理器,常见的集群使用 2 到 8 个核的机器。