一、官网下载Elasticsearch,解压到指定路径paht,启动单个/多个elasticsearch节点,配置相同的cluster_name
./path/elasticsearch-xx/bin/elasticsearch -d
二、检查启动是否成功:
curl "http://localhost:9200"
三、集群健康状态检查
status枚举
green-所有主分片和副本分片都正常
yellow-所有主分片正常,有副本分片不正常
red-有主分片不正常
curl "http://localhost:9200/_cluster/health"
{
"cluster_name":"yyc-elasticsearch",
"status":"yellow",//green-正常,yellow-所有主正常,有分片不正常,red-有主不正常
"timed_out":false,
"number_of_nodes":1,
"number_of_data_nodes":1,
"active_primary_shards":5,
"active_shards":5,
"relocating_shards":0,
"initializing_shards":0,
"unassigned_shards":5,
"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
}
四、集群修复
red状态时通过下面连接查看所有索引信息确定是那个索引导致集群red,如果索引不重要可删除索引,集群回复
curl "http://localhost:9200/_cluster/health?level=indices"
{
"...":"...",
"indices":{
"person":{
"status":"yellow",//索引状态,与集群状态一致
"number_of_shards":5,
"number_of_replicas":1,
"active_primary_shards":5,
"active_shards":5,
"relocating_shards":0,
"initializing_shards":0,
"unassigned_shards":5
}
}
}
yellow状态时是有副本分片不正常,就是有索引未分配。Elasticsearch默认有1个副本且主分片和副本不能在同一节点上,所以单节点时集群状态是yellow,副本未分配
curl "http://localhost:9200/_cat/shards"
索引名 分片编号 p(主分片)/r(副本) S(已分配)/U(未分配)
person 2 p STARTED 1 4.8kb 127.0.0.1 NQvFqpC
person 2 r UNASSIGNED
person 3 p STARTED 0 262b 127.0.0.1 NQvFqpC
person 3 r UNASSIGNED
person 1 p STARTED 0 264b 127.0.0.1 NQvFqpC
person 1 r UNASSIGNED
person 4 p STARTED 1 5.5kb 127.0.0.1 NQvFqpC
person 4 r UNASSIGNED
person 0 p STARTED 0 264b 127.0.0.1 NQvFqpC
person 0 r UNASSIGNED
查询出未分配的索引后,手动分配即可解决问题