วิธีปิดเครื่อง Elasticsearch cluster
1 min read

วิธีปิดเครื่อง Elasticsearch cluster


1) Disable shard allocation

รัน command ต่อไปนี้ที่เครื่องที่ต้องการปิด เพื่อปิด shard ของ elasticsearch

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

2) Stop indexing and perform a synced flush

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


3) หลังจากรันคำสั่งหมดแล้ว สามารถสั่ง shutdown โหนดหรือ  restart ได้

เมื่อเครื่องกลับมาแล้วให้สั่งรัน command นี้ บนเครื่องที่ปิดไป

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

4) เช็ค cluster ว่าเครื่องกลับมาไหมโดยใช้ command

curl http://ip-address:9200/_cluster/health?pretty

curl http://ip-address:9200/_cat/nodes?v


Reference

https://www.elastic.co/guide/en/elasticsearch/reference/current/restart-cluster.html#restart-cluster-full