用docker镜像部署的es,更换了镜像里的log4j包,整个集群更换镜像的步骤。
根据es的版本选择不同的官方指导:
https://www.elastic.co/guide/en/elasticsearch/reference/6.4/setup-upgrade.html
如果升级版本,要考虑原来的索引是否可用,但本次操作无需考虑。

要点如下:
0)备份
如果没有快照仓库,需要创建一个
# PUT /_snapshot/my_backup/,在快照仓库my_backup,创建一个索引,格式为snapshot-2018.05.11
curl -X PUT “localhost:9200/_snapshot/my_backup/%3Csnapshot-%7Bnow%2Fd%7D%3E?pretty”
参考:https://www.elastic.co/guide/en/elasticsearch/reference/6.4/modules-snapshots.html

0)观察集群状态
1)集群停止分片
2)节点升级
a)内存写入磁盘
b)停节点服务
c)更换文件或镜像
d)起服务
e)观察节点状态
f)升下一个节点
3)观察集群状态和测试业务

参考:
https://www.cnblogs.com/bonelee/p/7443823.html
https://www.jianshu.com/p/252d97a94200
https://www.cnblogs.com/powerwu/articles/12034098.html
https://www.jianshu.com/p/9752709bfea4
https://www.cnblogs.com/bonelee/p/7285878.html

观察集群状态

  1. curl -XGET "http://127.0.0.1:9200/_cluster/health?pretty=true"
  2. {
  3. "cluster_name" : "xxx",
  4. "status" : "green",
  5. "timed_out" : false,
  6. "number_of_nodes" : 3,
  7. "number_of_data_nodes" : 3,
  8. "active_primary_shards" : 20,
  9. "active_shards" : 40,
  10. "relocating_shards" : 0,
  11. "initializing_shards" : 0,
  12. "unassigned_shards" : 0,
  13. "delayed_unassigned_shards" : 0,
  14. "number_of_pending_tasks" : 0,
  15. "number_of_in_flight_fetch" : 0,
  16. "task_max_waiting_in_queue_millis" : 0,
  17. "active_shards_percent_as_number" : 100.0
  18. }
  19. #or curl -XGET http://localhost:9200/_cluster/health?pretty
  20. #状态:
  21. curl -XGET "http://127.0.0.1:9200/_cluster/stats?pretty=true"
  22. ……
  23. 太多,略

1)集群停止分片和重新平衡

  1. curl -H "Content-Type:application/json" -XPOST 'http://localhost:9200/_cluster/settings' -d '
  2. {
  3. "transient": {
  4. "cluster.routing.allocation.enable": "none",
  5. "cluster.routing.rebalance.enable": "none"
  6. }
  7. }
  8. '

2)节点升级

a)内存写入磁盘

  1. curl -XGET 'http://localhost:9200/_nodes/flush/synced'

有时候会出错,再次执行又成功了。
curl: (56) Recv failure: Connection reset by peer
延迟响应

  1. curl -H Content-Type:application/json -XPUT http://localhost:9200/_all/_settings -d '{ "settings": { "index.unassigned.node_left.delayed_timeout": "5m" } }'
  2. 提示:{"acknowledged":true}

b)停节点服务

  1. curl -XPOST http://localhost:9200/_cluster/nodes/_local/_shutdown

c)更换文件或镜像

d)起服务

e)观察节点状态

  1. curl -XGET http://localhost:9200/_nodes/process?pretty

f)升下一个节点

3)恢复设置

  1. curl -H "Content-Type:application/json" -XPOST 'http://localhost:9200/_cluster/settings' -d '
  2. {
  3. "transient": {
  4. "cluster.routing.allocation.enable": "all",
  5. "cluster.routing.rebalance.enable": "all"
  6. }
  7. }

4)观察集群状态和测试业务

可能的报错和处理:

x-www-form-urlencoded is not supported

curl时加上-H “Content-Type:application/json”

其他一些查询:

  1. curl -XGET http://localhost:9200/_cat
  2. =^.^=
  3. /_cat/allocation
  4. /_cat/shards
  5. /_cat/shards/{index}
  6. /_cat/master
  7. /_cat/nodes
  8. /_cat/tasks
  9. /_cat/indices
  10. /_cat/indices/{index}
  11. /_cat/segments
  12. /_cat/segments/{index}
  13. /_cat/count
  14. /_cat/count/{index}
  15. /_cat/recovery
  16. /_cat/recovery/{index}
  17. /_cat/health
  18. /_cat/pending_tasks
  19. /_cat/aliases
  20. /_cat/aliases/{alias}
  21. /_cat/thread_pool
  22. /_cat/thread_pool/{thread_pools}
  23. /_cat/plugins
  24. /_cat/fielddata
  25. /_cat/fielddata/{fields}
  26. /_cat/nodeattrs
  27. /_cat/repositories
  28. /_cat/snapshots/{repository}
  29. /_cat/templates