ElasticSearch正确的重启方式
[toc]
# ES安全完整的重启步骤
# 命令行curl方式
- 关闭集群自动均衡、禁止集群写入
#关闭集群自动均衡
curl -XPUT "http://集群任意IP:9200/_cluster/settings?pretty" -H 'Content-Type:application/json' -d
'{
"persistent" :{
"cluster.routing.rebalance.enable": "none"
},
"transient" :{
"cluster.routing.rebalance.enable": "none"
}
}'
#检查集群自动均衡是否关闭
curl -XGET "http://集群任意IP:9200/_cluster/settings?pretty"
#禁止集群写入
curl -XPUT "http://集群任意IP:9200/_cluster/settings?pretty" -H 'Content-Type:application/json' -d '
{
"persistent" :{
"cluster.blocks.read_only" : "true"
},
"transient" :{
"cluster.blocks.read_only" : "true"
}
}'
#检查集群写入是否已经关闭
curl -XGET "http://集群任意IP:9200/_cluster/settings?pretty"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
- 重启es集群
#停es服务
ssh ip -C 'ps -ef|grep org.elasticsearch.bootstrap.Elasticsearch|grep -v grep|awk '{print \$2}'|xargs kill -9'
#启动es服务
ssh ip -C 'su - es -c "cd /home/es/software/elasticsearch/bin;sh elasticsearch -d"'
1
2
3
4
5
2
3
4
5
- 打开集群自动均衡、开启集群写入
--先打开写入,再打开自动均衡
#打开集群写入
curl -XPUT "http://集群任意IP:9200/_cluster/settings?pretty" -H 'Content-Type:application/json' -d '{"persistent" :{"cluster.blocks.read_only" : "false"}}'
curl -XPUT "http://集群任意IP:9200/_cluster/settings?pretty" -H 'Content-Type:application/json' -d '{"transient" :{"cluster.blocks.read_only" : "false"}}'
#检查集群写入是否已经打开
curl -XGET "http://集群任意IP:9200/_cluster/settings?pretty"
#打开集群自动均衡
curl -XPUT "http://集群任意IP:9200/_cluster/settings?pretty" -H 'Content-Type:application/json' -d '{"persistent" :{"cluster.routing.rebalance.enable": "all"}}'
curl -XPUT "http://集群任意IP:9200/_cluster/settings?pretty" -H 'Content-Type:application/json' -d '{"transient" :{"cluster.routing.rebalance.enable": "all"}}'
#检查集群自动均衡是否打开
curl -XGET "http://集群任意IP:9200/_cluster/settings?pretty"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Kibana执行
- 关闭集群自动均衡、禁止集群写入
#关闭集群自动均衡
PUT /_cluster/settings 启动时候,禁自动均衡
{
"persistent": {
"cluster.routing.rebalance.enable": "none"
},
"transient": {
"cluster.routing.rebalance.enable": "none"
}
}
#检查集群自动均衡是否关闭
GET /_cluster/settings?pretty
#禁止集群写入
PUT /_cluster/settings //启动时候,禁写
{
"persistent": {
"cluster.blocks.read_only": true
},
"transient": {
"cluster.blocks.read_only": true
}
}
#检查集群写入是否已经关闭
GET /_cluster/settings?pretty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
- 重启es集群
#停es服务
ssh ip -C 'ps -ef|grep org.elasticsearch.bootstrap.Elasticsearch|grep -v grep|awk '{print \$2}'|xargs kill -9'
#启动es服务
ssh ip -C 'su - es -c "cd /home/es/software/elasticsearch/bin;sh elasticsearch -d"'
1
2
3
4
5
2
3
4
5
- 打开集群自动均衡、开启集群写入
--先打开写入,再打开自动均衡
#打开集群写入
PUT /_cluster/settings
{
"persistent": {
"cluster.blocks.read_only": false
}
}
PUT /_cluster/settings
{
"transient": {
"cluster.blocks.read_only": false
}
}
#检查集群写入是否已经打开
GET /_cat/shards?v&pretty&s=ip:desc
#打开集群自动均衡
PUT /_cluster/settings
{
"persistent": {
"cluster.routing.rebalance.enable": "ALL"
},
"transient": {
"cluster.routing.rebalance.enable": "ALL"
}
}
#检查集群自动均衡是否打开
GET /_cluster/settings?pretty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#
上次更新: 2023/03/10, 20:58:04