summaryrefslogtreecommitdiff
path: root/content/tech
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-08-26 19:41:18 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2017-08-26 19:41:18 +0200
commit1e2760a2051bf6b11281592b4ab4b6a20cef7c78 (patch)
tree2ffd8261339279de30518acd8c816dcbb6edaf0a /content/tech
parenta7633db038904d7a15d8499c532b13a3a02735e1 (diff)
downloadblog-1e2760a2051bf6b11281592b4ab4b6a20cef7c78.tar.gz
blog-1e2760a2051bf6b11281592b4ab4b6a20cef7c78.zip
scaling elasticsearch
Diffstat (limited to 'content/tech')
-rw-r--r--content/tech/scaling-elasticsearch.md51
1 files changed, 51 insertions, 0 deletions
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.<!--more-->
+
+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"
+ }
+}'
+```