---
title: "elasticsearch如何安全重启节点"
author: "fireinwind"
date: "2016-05-11T14:08:24Z"
tags: []
categories: ["开源软件"]
slug: "elasticsearch"
draft: false
lastmod: "2016-05-11T14:08:24Z"
id: 2297442
url: "https://fireinwind.iteye.com/blog/2297442"
---

### elasticsearch如何安全重启节点

[大岩不灿](http://zhaoyanblog.com/archives/author/johnyannj "View all posts by 大岩不灿") 发表于 [2014年10月14日](http://zhaoyanblog.com/archives/555.html "下午7:17") 浏览 6,568 次

elasticsearch集群，有时候可能需要修改配置，增加硬盘，扩展内存等操作，需要对节点进行维护升级。但是业务不能停，如果直接kill掉节点，可能导致数据丢失。而且集群会认为该节点挂掉了，就开始转移数据，当重启之后，它又会恢复数据，如果你当前的数据量已经很大了，这是很耗费机器和网络资源的。  
本文转载官方提供的安全重启集群节点的方法：

第一步：先暂停集群的shard自动均衡。

```
1
2
3
4
5
6
```

```
curl -XPUT http://192.168.1.2:9200/_cluster/settings -d'
{
    "transient" : {
        "cluster.routing.allocation.enable" : "none"
    }
}'
```

第二步：shutdown你要升级的节点

```
1
```

```
curl -XPOST http://192.168.1.3:9200/_cluster/nodes/_local/_shutdown
```

第三步：升级重启该节点，并确认该节点重新加入到了集群中

第四步：重复2-3步，升级重启其它要升级的节点。

第五步：重启启动集群的shard均衡

```
1
2
3
4
5
6
```

```
curl -XPUT http://192.168.1.2/_cluster/settings -d'
{
    "transient" : {
        "cluster.routing.allocation.enable" : "all"
    }
}'
```

到此整个集群安全升级并且重启结束。

除非注明，[赵岩的博客](http://zhaoyanblog.com/ "赵岩的博客")文章均为原创，转载请以链接形式标明本文地址  
本文地址：[http://zhaoyanblog.com/archives/555.html](http://zhaoyanblog.com/archives/555.html "elasticsearch如何安全重启节点")