From 1e2760a2051bf6b11281592b4ab4b6a20cef7c78 Mon Sep 17 00:00:00 2001 From: schneefux Date: Sat, 26 Aug 2017 19:41:18 +0200 Subject: scaling elasticsearch --- content/tech/scaling-elasticsearch.md | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 content/tech/scaling-elasticsearch.md (limited to 'content/tech') diff --git a/content/tech/scaling-elasticsearch.md b/content/tech/scaling-elasticsearch.md new file mode 100644 index 0000000..88ab1e6 --- /dev/null +++ b/content/tech/scaling-elasticsearch.md @@ -0,0 +1,51 @@ +--- +categories: +- software +date: 2017-08-26 +title: Scaling down an Elasticsearch cluster +--- + +[Elasticsearch](https://elastic.co) is a NoSQL database optimized for searching. + +A cluster is created by sharing the same `cluster.name` for every node. Data is distributed automatically and redundantly. + +Taking nodes out of the cluster is more challenging. First, make sure that the cluster status is green. Take down a node, wait for the cluster to rebalance and redistribute the data (status yellow), then repeat until only three nodes are left (fewer or more depending on your replication settings). Freeze the cluster by preventing shard rebalancing: + +```bash +curl -XPUT 'localhost:9200/_cluster/settings' -d '{ + "transient" : { + "cluster.routing.allocation.enable" : "none" + } +}' +``` + +Data is divided into indexes, which can be compared to database tables, and those are divided into shards which are spread across the cluster. Get the shards for the indexes you want to move: + +```bash +curl -XGET '192.168.2.35:9200/_cat/shards/yourindex' +yourindex 1 p STARTED 537256 1.9gb 192.168.0.45 anothernode +yourindex 2 p STARTED 537506 2gb 192.168.0.35 laptop +yourindex 4 p STARTED 536696 1.9gb 192.168.0.35 laptop +yourindex 3 p STARTED 537859 1.9gb 192.168.0.35 laptop +yourindex 0 p STARTED 537282 1.9gb 192.168.0.35 laptop +``` + +Finally, force the reallocation: + +```bash +curl -XPOST 'localhost:9200/_cluster/reroute' -d '{ "commands": + [{ "move" : + { "index" : "yourindex", "shard" : 1, "from_node": "anothernode", "to_node": "laptop" } + }] +}' +``` + +Take the node down as soon as the cluster status is green again and reactivate balancing. Transient settings are lost after restarting the service. + +```bash +curl -XPUT 'localhost:9200/_cluster/settings' -d '{ + "transient" : { + "cluster.routing.allocation.enable" : "all" + } +}' +``` -- cgit v1.3.1