Database - Elasticsearch
Commands
Custom Elastic vars:
# Custom elastic vars
el_host=$(hostname --fqdn)
el_user="elastic"
el_password="passwd"
el_cacert="/etc/elasticsearch/certs/ca.crt"
alias ecurl="curl --user $el_user:$el_password --cacert $el_cacert"
Globals
Cluster Health:
Available storage:
Cluster Version:
Display master node:
Display shards:
# All shards
ecurl -X GET "https://$el_host:9200/_cat/shards"
# Shards with reloc in Progress
ecurl -X GET -s "https://$el_host:9200/_cat/shards" | grep RELOC
# Count par state
ecurl -X GET -s "https://$el_host:9200/_cat/shards?h=state" | sort | uniq -c
# Check reloc in Progress
ecurl -X GET -s "https://$el_host:9200/_cat/shards" | awk '/RELOC/ && $NF == "'"$(hostname)"'"'
Snapshot
Create snapshot:
ecurl -X PUT "https://$el_host:9200/_snapshot/es_snapshot/{snapshot-name}" \
-H 'Content-Type: application/json' \
-d '{ "accepted": true }'
Display available snapshot:
Delete snapshot:
Procedures
Elasticsearch HQ
Start Elasticsearch HQ in container:
host="myhost"
user="elastic"
password="passwd"
cacert="/home/lkone/elastic-ca.crt"
docker run -d \
-p 5000:5000 \
--name elasticsearch-hq \
-v $cacert:/etc/ssl/certs/elastic-ca.crt \
-e HQ_DEFAULT_URL="https://$user:$password@$host:9200" \
-e HQ_CA_CERTS=/etc/ssl/certs/elastic-ca.crt \
-e HQ_VERIFY_CERTS=True \
-e HQ_ENABLE_SSL=True \
elastichq/elasticsearch-hq
Sortir un noeud
Vérifier l'état du cluster (green):
Vérifier ou se situe le master:
Warning
Si le node est le master s'assurer que la bascule se fait bien après l'arrêt du service elasticsearch
Mettre les règles d'allocation uniquement sur les shards primaires pour éviter la re-balance (relocating) des shards durant l'arrêt du node:
ecurl -X PUT "https://$el_host:9200/_cluster/settings" \
-H "Content-Type: application/json" \
-d '{"persistent": {"cluster.routing.allocation.enable": "primaries"}}'
Flusher les index du cluster:
Arréter le noeud:
Note
Faire les actions sur le noeud stoppé
Démarrer le noeud:
Vérifier l'état du cluster (yellow):
Note
Le cluster doit voir tous ses noeuds mais reste en yellow
Remettre les règles d'allocation routing:
ecurl -X PUT "https://$el_host:9200/_cluster/settings" \
-H "Content-Type: application/json" \
-d '{"persistent": {"cluster.routing.allocation.enable": null}}'
Vérifier l'état du cluster (green):
Note
Après que les unassigned shards passent actives le statut passe en green
Problem
Blocked index to read-only
By default, Elasticsearch installed goes into read-only mode when you have less than 5% of free disk space. If you see errors similar to this:
{
"error": {
"reason": "blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];",
"root_cause": [
{
"reason": "blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];",
"type": "cluster_block_exception"
}
],
"type": "cluster_block_exception"
},
"status": 403
}
Resolution: