不停機遷移 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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM