B i M A P

Elasticsearch|Rolling Upgrades your ES Cluster Node

elasticsearch logo



Elasticsearch Version:From 6.8 to 7.13

OS:CentOS

Notice:

  1. Elasticsearch 如果低於 6.8,則需先升級至 6.8 版本
  2. 新版本 ES 可以加入舊版本 ES Cluster,反之則否


Disable shard allocation

當停止了 data-node,shard 的分配會依照 index.unassigned.node_left.delayed_timeout 的配置做等待 (預設一分鐘),假如超過時間,則分配至其他的 data-node,過程式可能造成許多不必要的 I/O 消耗,最好在停止 data-node 之前,將此工作設定停用,所以:

curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d' { "persistent": { "cluster.routing.allocation.enable": "primaries" } } '



Stop non-essential indexing and perform a synced flush. (Optional)

停止不必要的 indexing 並同步刷新,雖然可以在升級期間繼續有 indexing 的動作,但透過此操作可以讓 shard 恢復得更快。

過程中,儘管此操作回傳 status 200 ok,但有可能會在回傳的 body 中看到含有錯誤的訊息,這時後再次執行此操作即可。

需注意的是,ES 7.6 版後,該操作已沒有使用的必要性,並會在 ES 8.0 之後的版本將此操作移除。

curl -X POST "localhost:9200/_flush/synced?pretty"


Temporarily stop the tasks associated with active machine learning jobs and datafeeds. (Optional)

注意:您的版本低於 6.8,需要 reindex the indices
你可以在升級的過程式繼續執行 ML 的相關工作,如果停止節點的機器剛好有 ML 工作正在執行,ES 會自動即其轉移至其他節點,並以當時的 ML model 狀態繼續工作,但有可能會需要消耗更多的資源。
暫時機器學習及資料傳送的相關工作,可以避免新的工作一直被創建,所以:
curl -X POST "localhost:9200/_ml/set_upgrade_mode?enabled=true&pretty"

當您停用升級模式後,工作將會以自動儲存的最新 model 狀態繼續執行。



Shut down a single node

停用服務,所以:

systemctl stop elasticsearch



Upgrade the node you shut down

下載安裝 7.13.2 Elasticsearch 安裝包,所以:

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.13.2-x86_64.rpm
sudo rpm -Uvh elasticsearch-7.13.2-x86_64.rpm



Restart a single node

重啟服務,所以:

systemctl daemon-reload
systemctl start elasticsearch



Check the upgrade node

檢查更新後的 node 是否正常加入了 cluster 中,所以:

curl -X GET "localhost:9200/_cat/nodes?pretty"



Reenable shard allocation

重新分派 shard,所以:

curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d' { "persistent": { "cluster.routing.allocation.enable": null } } '



Wait for the node to recover

在繼續升級下一個 node 之前,需確認 shard 已經被重新分配,所以:

curl -X GET "localhost:9200/_cat/health?v=true&pretty"

等待狀態變為綠燈,即代表 shard 分配完成,但假如沒有執行先前的 synced flush 操作,等待時間會稍久,不過 7.6 版以後應該不會差別太大。



Restart machine learning jobs

如果先前有暫停 ML 的工作,則可以重新開始工作,所以:

curl -X POST "localhost:9200/_ml/set_upgrade_mode?enabled=false&pretty"



Repeat

重覆上面的動作開始進行滖動式更新。



有任何問題,或是想看新主題? 聯絡我們

延伸閱讀
winstonlu的大頭照
ELK 達人

我們致力於 ELK 的各種應用,協助企業建置相關服務。我們也提供基於 ELK 的各種解決方案,有任何問題,歡迎加入我們的官方 Line,或來信詢問,期待與您面對面的機會。