不停机迁移 elasticsearch 集群

一、背景

 ES 集群不停机迁移,迁移过程中不影响业务使用。 所用集群版本为 6.3.0 。

二、方案

1、业务通过域名访问集群;

2、在新的机器搭建集群;

3、对原有集群进行快照,万一数据有丢失可以从快照进行恢复;

4、新旧集群进行合并,并强制使旧集群数据通过数据均衡的方式迁移到新集群;

5、下线原有旧集群。

三、实施

1、在新的机器搭建集群的方法

1)机器准备(root设置):参考官网

vim  /etc/security/limits.conf
解除文件与内存限制
* soft memlock unlimited
* hard memlock unlimited
* - nofile 65536
* - core unlimited
生效: 退出再登入
vim /etc/sysctl.conf 
添加
vm.max_map_count = 262144
vm.swappiness = 1
生效:sysctl -p
View Code

2)配置节点:参考官网

The order of precedence for cluster settings is:
transient cluster settings
persistent cluster settings
settings in the elasticsearch.yml configuration file.
View Code

注意事项:

1)ES 堆内存需要在32G 以内,最好是26G。

官网  网友说法 参考1 参考2

2)shard越多,QPS就会越低(详情),Shard大小官方推荐值为20-40GB(详情),每1GB堆内存对应集群的分片在20-25之间(26G 可以存储520个 shard)(详情);

每个节点上可以存储的分片数量与可用的堆内存大小成正比关系,但是 Elasticsearch 并未强制规定固定限值。这里有一个很好的经验法则:确保对于节点上已配置的每个 GB,将分片数量保持在 20 以下。如果某个节点拥有 30GB 的堆内存,那其最多可有 600 个分片,但是在此限值范围内,您设置的分片数量越少,效果就越好(详情)。每个节点的 shard 数量设置方法,集群中 shard 分配策略设置方法

3)master 与 client 节点的内存与 CPU 都用量比较少,相应的参数可以设小些。

2、集群快照的方法:通过自己搭建Hadoop 集群实现(需要安装 hdfs 插件)

curl -XPUT http://XXX/_snapshot/hdfs_repo -H 'Content-Type: application/json' -d '
    {
    "type": "hdfs",
    "settings": {
        "uri": "hdfs://XXX:8800/",
        "path": "hdfs_repo",
        "compress": true
    }
    }'
View Code

3、新旧集群合并:可以启动一个能够连接两个集群的 master, 这样两个集群就能合并成一个集群

注意:相同的索引会覆盖,如果集群有部分索引 RED 了,确认无影响后可以通过 reroute 重新分配分片

POST /_cluster/reroute?retry_failed=true&pretty
{
}
View Code

4、集群数据迁移的方法:通过分片配置过滤实现,使数据从旧机器中迁移走。

curl -XPUT http://XXX/_cluster/settings -H 'Content-Type: application/json' -d '
    {
  "transient": {
    "cluster.routing.allocation.exclude._name": "XXX"
  }
}'
View Code

四、其他

1、数据冷热分离

1、使所有分片都不能分配在 ssd 上;
curl -XPUT "http://XXX/*/_settings?master_timeout=120s" -H 'Content-Type: application/json' -d'
{
  "index.routing.allocation.exclude.box_type": "hot"
}'
2、使 test 能够分配在 ssd 上;
PUT test/_settings
{
  "index.routing.allocation.include.box_type": "hot"
}
3、启用 tag 感知策略(不设也没关系)
PUT /_cluster/settings
{
    "transient" : {
        "cluster.routing.allocation.awareness.attributes": "box_type"
    }
}
View Code

 2、使用 esrally 进行压测

3、kibana

4、滚动重启

1、暂停集群数据均衡
PUT _cluster/settings
{
  "transient": {
    "cluster.routing.rebalance.enable": "none"
  }
}
2、禁止分片分配
PUT _cluster/settings
{
  "transient": {
    "cluster.routing.allocation.enable": "none"
  }
}
3、刷新索引(可选)
curl -XPOST http://XXX/_flush/synced
 
4、此处进行节点更新操作后再重启

5、重新允许分片分配
PUT _cluster/settings
{
  "persistent": {
    "cluster.routing.allocation.enable": null
  }
}
6、待集群恢复 green 后再重复2~5步,直到完成所有节点的更新重启
7、恢复集群数据均衡
View Code

 

posted @ 2019-09-28 22:47  YoZane  阅读(1352)  评论(0编辑  收藏  举报