elasticsearch

Elasticsearch 服务启动与集群运维

补充说明

elasticsearch 是分布式搜索与分析引擎,提供 REST API。它负责索引、分片、副本和集群状态;客户端通常用 curl、Kibana 或语言 SDK。

常用示例

elasticsearch
curl -s http://127.0.0.1:9200/
curl -s http://127.0.0.1:9200/_cluster/health?pretty
curl -s http://127.0.0.1:9200/_cat/nodes?v
curl -s http://127.0.0.1:9200/_cat/indices?v
curl -s http://127.0.0.1:9200/_cat/shards?v
curl -X PUT http://127.0.0.1:9200/app -H 'Content-Type: application/json' \
  -d '{"settings":{"number_of_shards":3,"number_of_replicas":1}}'
curl -s 'http://127.0.0.1:9200/_cluster/allocation/explain?pretty'

常见配置

cluster.name: app-search
node.name: es-1
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 0.0.0.0
discovery.seed_hosts: ["es-1", "es-2", "es-3"]
cluster.initial_master_nodes: ["es-1", "es-2", "es-3"]

易错点与排错

相关命令

读完自测

合上页面,先回答,再展开对照。

  1. 集群出现 red/yellow 且部分分片未分配时,第一步应该做什么?
  2. JVM 堆内存配置有什么上限建议,原因是什么?
  3. 把副本数调大是否等于有了备份?
答案
  1. 先看 _cluster/health、_cat/shards 和 _cluster/allocation/explain 定位原因,不要盲目重启全部节点。
  2. 建议不超过物理内存的 50%,且不要超过 31g;堆外还有文件缓存需要内存。
  3. 不等于,副本不是备份,快照仓库要单独配置并验证恢复。