curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
"persistent": {
"cluster.routing.allocation.enable": "primaries"
}
}
curl -X POST "localhost:9200/_flush/synced?pretty"
::注意查看返回的结果中,是否有失败的信息,如果有的话,再执行一次;(执行失败也会返回 200 状态码的,还是要注意看内容)::
通过kill 对应的 pid 进行关闭;
执行完操作后逐个启动节点
cd [your es home path]
./bin/elasticsearch -d -p [your es home path]/pid.txt
等所有节点启动完成后,可以通过执行如下请求查看集群状态:
curl -X GET "localhost:9200/_cat/health?pretty"
curl -X GET "localhost:9200/_cat/nodes?pretty"
状态分别有:red,yellow,green。
启用分片自动分布
curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
"persistent": {
"cluster.routing.allocation.enable": null
}
}
重新启用分配后,集群便开始将副本分片分配给数据节点。此时,恢复索引和搜索是安全的,但是如果您可以等待直到成功分配了所有主分片和副本分片并且所有节点的状态为,集群就会恢复得更快green。