Skip to content

Instantly share code, notes, and snippets.

@jeduoliveira
Last active October 26, 2021 17:23
Show Gist options
  • Save jeduoliveira/5878600b3f11c0959bd67c5a16c9a6c8 to your computer and use it in GitHub Desktop.
Save jeduoliveira/5878600b3f11c0959bd67c5a16c9a6c8 to your computer and use it in GitHub Desktop.
curl -XPOST 'localhost:9200/_cluster/reroute' -d '{
"commands": [{
"allocate": {
"index": "XXXXXXXXXXXXXXXXXXXXXXX",
"shard": 1,
"node": "node-1",
"allow_primary": 1
}
}]
}'
0 - Rodar curl -XGET http://localhost:9200/_cluster/health?pretty e printar a resposta, será util no fim
1 - Desabilitar as réplicas e confirmar se apenas shards primárias mantem-se ativas:
curl -XPUT -H 'Content-Type: application/json' localhost:9200/_settings -d '{"number_of_replicas": 0}'
Confirmar com: curl -XGET localhost:9200/_cat/shards?h=prirep,index,node,state
2 - Removendo o nó (Nesse caso os shards serão realocados para outros nós ativos)
curl -XPUT localhost:9200/_cluster/settings -H 'Content-Type: application/json' -d '{
"transient" :{
"cluster.routing.allocation.exclude._ip" : "172.31.93.10"
}
}'
Conferindo como está o Cluster > curl -X GET "localhost:9200/_cluster/health?pretty"
2.1 - Aguardar até o Cluster sair de yellow ou red e rodar:
curl -XGET localhost:9200/_cat/shards?h=prirep,index,node,state
curl -XGET localhost:9200/_cat/shards?h=index,shard,prirep,state | grep RELOCATING (não deve retornar nada)
curl -XGET localhost:9200/_cat/shards?h=prirep,index,node,state | grep NOME DO QUE FOI REMOVIDO (não deve retornar nada)
curl -XGET localhost:9200/_cat/shards?h=index,node,prirep,state | wc -l
curl -XGET localhost:9200/_cat/shards?h=prirep,index,node,state | grep node1 | wc -l
2.2 - Comentar no arquivo /etc/elasticsearch/elasticsearch.yml o campo discovery.zen.ping.unicast.hosts
2.3 - Adicionar um novo campo discovery.zen.ping.unicast.hosts: com os ips ativos no momento (sem o ip da maquina que foi removida)
OBS: passo 2.3 necessario somente se o elastic seguir em cluster se ele voltar a single mode não é necessario o passo acima
2.4 - Parar o elasticsearch de TODAS as maquinas, startar somente das maquinas que vão entrar no cluster
curl -XGET localhost:9200/_cat/master (descobrir qual é o nó master)
2.5 - Checar no log do elasticsearch se o mesmo subiu como esperado: (possivelmente em /lumis/elasticsearch/logs/NOME-DO-CLUSTER.log
2.6 - Caso ainda exista servidores a remover efetuar o passo 2 novamente
3 - Caso tenha terminado de reduzir o tamanho do cluster agora rodar um curl -XGET http://localhost:9200/_cluster/health?pretty e conferir se o campo,
active_shards bate com o inicio da redução (utilizar print tirado no inicio)
4 - Habilitar novamente as replicas:
curl -XPUT -H 'Content-Type: application/json' localhost:9200/_settings -d '{"number_of_replicas": 1}'
4.1 - Rodando curl -XGET http://localhost:9200/_cluster/health?pretty você verá que tem o dobro de active_shards
Aguardar Green, pronto seu cluster foi reduzido de X para X-n servidores
referencias:
https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-master.html
https://www.elastic.co/guide/en/elasticsearch/reference/7.x/high-availability-cluster-small-clusters.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-cluster.html#cluster-shard-allocation-filtering
https://logz.io/blog/elasticsearch-cheat-sheet/
https://stackoverflow.com/questions/17268495/how-to-remove-node-from-elasticsearch-cluster-on-runtime-without-down-time/23905040
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment