Remove Elasticsearch node.
Simply exclude Elasticsearch node to remove it from cluster.
List nodes.
$ curl -u elastic:************ https://192.168.8.153:9200/_cat/nodes?v
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name 192.168.8.153 32 93 8 0.08 0.13 0.18 dm * elastic-1 192.168.8.163 61 96 0 0.48 0.11 0.04 dm - elastic-3 192.168.8.159 20 92 4 0.16 0.14 0.09 dm - elastic-2 192.168.8.166 53 95 3 0.05 0.09 0.06 d - elastic-5 192.168.8.165 57 95 0 0.12 0.08 0.02 d - elastic-4
List indices on node elastic-5
.
$ curl -s -u elastic:************ "https://192.168.8.153:9200/_cat/shards?format=json" | jq --raw-output '.[] | select(.node == "elastic-5") | .index'
.ds-metricbeat-8.8.2-2023.07.23-000001 .internal.alerts-observability.logs.alerts-default-000001 .ds-.monitoring-es-8-mb-2023.07.23-000001 .kibana_security_session_1 .internal.alerts-observability.uptime.alerts-default-000001 .internal.alerts-observability.metrics.alerts-default-000001 .kibana_task_manager_8.8.2_001 .ds-ilm-history-5-2023.07.23-000001 .kibana_8.8.2_001 .security-profile-8 .fleet-files-agent-000001 .security-7 .apm-custom-link .kibana_ingest_8.8.2_001 .internal.alerts-observability.slo.alerts-default-000001 .ds-.logs-deprecation.elasticsearch-default-2023.07.23-000001 .apm-source-map
Count indices on node elastic-5
.
$ curl -s -u elastic:************ "https://192.168.8.153:9200/_cat/shards?format=json" | jq --raw-output '. | map(select(.node == "elastic-5")) | length'
17
Exclude allocation on two nodes elastic-4
and elastic-5
. The most common attributes to match nodes are _ip
, name
$ curl -X PUT -u elastic:************ "https://192.168.8.153:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'{"persistent": {"cluster.routing.allocation.exclude._name": "elastic-4,elastic-5"}}'
{ "acknowledged" : true, "persistent" : { "cluster" : { "routing" : { "allocation" : { "exclude" : { "_name" : "elastic-4,elastic-5" } } } } }, "transient" : { } }
Verify applied settings.
$ curl -u elastic:************ "https://192.168.8.153:9200/_cluster/settings?pretty"
{ "persistent" : { "cluster" : { "routing" : { "allocation" : { "exclude" : { "_name" : "elastic-4,elastic-5" } } } } }, "transient" : { } }
Wait for a while as the shards will be transferred to other servers.
Check whether the nodes are empty.
$ curl -s -u elastic:************ "https://192.168.8.153:9200/_cat/shards?format=json" | jq --raw-output '. | map(select(.node == "elastic-4")) | length'
0
$ curl -s -u elastic:************ "https://192.168.8.153:9200/_cat/shards?format=json" | jq --raw-output '. | map(select(.node == "elastic-5")) | length'
0
Disable elasticsearch service on these nodes and update configuration if needed.
List nodes.
$ curl -u elastic:************ https://192.168.8.153:9200/_cat/nodes?v
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name 192.168.8.159 74 95 1 0.01 0.04 0.07 dm - elastic-2 192.168.8.153 23 96 4 0.01 0.05 0.14 dm * elastic-1 192.168.8.163 61 95 3 0.00 0.03 0.09 dm - elastic-3
Disable allocation exclude.
$ curl -X PUT -u elastic:************ "https://192.168.8.153:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'{"persistent": {"cluster.routing.allocation.exclude._name": null}}'
{ "acknowledged" : true, "persistent" : { }, "transient" : { } }