[关闭]
@gy-ban 2017-06-25T07:28:14.000000Z 字数 2884 阅读 466

elasticsearch 升级步骤

ES


elasticsearch升级有两种方式,rolling upgrades and full cluster restarts
根据不同版本选择不同升级方式

  1. Upgrade From Upgrade To Supported Upgrade Type
  2. 0.90.x 2.x Full cluster restart
  3. 1.x 2.x Full cluster restart
  4. 2.x 2.y Rolling upgrade (where `y > x `)

这次我们是要将1.x升级到2.x,所以选择full cluster restart

升级步骤

一、备份数据

  1. A snapshot of an index created in 2.x can be restored to 5.x.
  2. A snapshot of an index created in 1.x can be restored to 2.x.
  3. A snapshot of an index created in 1.x can not be restored to 5.x.

1、创建仓库

  1. curl -XPUT localhost:9200/_snapshot/my_backup -d '
  2. {
  3. "type": "fs",
  4. "settings": {
  5. "location": "/mount/backups/my_backup"
  6. }
  7. }'

查看仓库

  1. curl -XGET 'localhost:9200/_snapshot/my_backup?pretty'

2、创建索引快照

  1. curl -XPUT 'localhost:9200/_snapshot/my_backup/snapshot_1

这个会备份所有打开的索引到 my_backup 仓库下一个命名为 snapshot_1 的快照里。这个调用会立刻返回,然后快照会在后台运行。

  1. curl -XPUT 'localhost:9200/_snapshot/my_backup/snapshot_1?wait_for_completion=true&pretty'

不过有时候你会希望在你的脚本中一直等待到完成。这可以通过添加一个 wait_for_completion 标记实现

给指定索引快照

  1. curl -XPUT 'localhost:9200/_snapshot/my_backup/snapshot_2 -d'
  2. {
  3. "indices": "index_1,index_2",
  4. "ignore_unavailable": true,
  5. "include_global_state": false
  6. }
  7. '

这个快照命令现在只会备份 index1 和 index2 了。

快照状态查看

  1. curl -XGET 'localhost:9200/_snapshot/_status?pretty'
  2. curl -XGET 'localhost:9200/_snapshot/my_backup/_status?pretty'
  3. curl -XGET 'localhost:9200/_snapshot/my_backup/snapshot_1/_status?pretty'
  4. curl -XGET 'localhost:9200/_snapshot/my_backup/snapshot_1,snapshot_2/_status?pretty'

列出快照相关信息

  1. curl -XGET 'localhost:9200/_snapshot/my_backup/snapshot_1?pretty'

要获取一个仓库中所有快照的完整列表,使用 _all 占位符替换掉具体的快照名称

  1. curl -XGET 'localhost:9200/_snapshot/my_backup/_all?pretty'

删除快照

  1. curl -XDELETE 'localhost:9200/_snapshot/my_backup/snapshot_1?pretty'

删除仓库

  1. curl -XDELETE 'localhost:9200/_snapshot/my_backup?pretty'

快照还原

  1. curl -XPOST 'localhost:9200/_snapshot/my_backup/snapshot_1/_restore?pretty'

二、禁用碎片分配

正常情况下,Elasticsearch 希望你的数据被完全的复制和均衡的分布。如果你手动关闭了一个节点,集群会立刻发现节点的丢失并开始再平衡。如果节点的维护是短期工作的话,这一点就很烦人了,因为大型分片的再平衡需要花费相当的时间(想想尝试复制 1TB 的数据——即便在高速网络上也是不一般的事情了)。

禁止分片分配。这一步阻止 Elasticsearch 再平衡缺失的分片,直到我们手动开启

  1. curl -XPUT 'localhost:9200/_cluster/settings?pretty' -H 'Content-Type: application/json' -d'
  2. {
  3. "persistent": {
  4. "cluster.routing.allocation.enable": "none"
  5. }
  6. }
  7. '

三、执行同步刷新

  1. curl -XPOST 'localhost:9200/_flush/synced?pretty'

如果停止了索引并且执行了 synced-flush,这样可以加快分片恢复

四、关闭所有节点并升级

停止集群中的所有节点上的Elasticsearch服务
这里我们采用tar包进行安装,解压tar压缩包到一个新的目录,以确保不会覆盖配置或数据目录,默认情况下,配置文件,数据目录,日志文件和插件目录放置在Elasticsearch主目录中
复制原来的配置文件和数据文件到新的目录,同时更新插件
这里需要注意一点,我们用的中文分词器插件是elasticsearch-analysis-mmseg, 版本严格对应elasticsearch版本,并且ES 2.x的plugins目录结构也有变化

  1. ll /data/elasticsearch-2.4.4/plugins/analysis-mmseg/
  2. 总用量 68
  3. drwxrwxr-x. 3 bhuser bhuser 4096 2 13 03:40 config
  4. -rwxrwxr-x. 1 bhuser bhuser 59379 2 13 03:41 elasticsearch-analysis-mmseg-1.10.4.jar
  5. -rw-rw-r--. 1 bhuser bhuser 2679 2 13 03:41 plugin-descriptor.properties

五、启动集群

启动所有节点,并观察是否加入到集群

  1. curl -XGET 'localhost:9200/_cat/health?pretty'
  2. curl -XGET 'localhost:9200/_cat/nodes?pretty'

等待集群状态别称黄色

六、重新启用分片分配

  1. curl -XPUT 'localhost:9200/_cluster/settings?pretty' -H 'Content-Type: application/json' -d'
  2. {
  3. "persistent": {
  4. "cluster.routing.allocation.enable": "all"
  5. }
  6. }
  7. '

等待集群状态变成绿色

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注