Search code examples
elasticsearch

Elasticsearch : 2 Node Cluster- Best way to shutdown one of the node


I'm currently using a 2 node elastic cluster on RHEL. Both nodes are data nodes and one eligible master nodes. Currently I have a script to find the process id of the elasticsearch process and killing it as a way of stopping the elasticsearch. Is there any other way of safely stopping one of the node while another one is running.

Elasticsearch version 6.2.1


Solution

  • There are two ways to stop your Elasticsearch node depending on how you're starting it.

    If you're using service management functionality, you can simply issue a stop command for the elasticsearch service.

    Otherwise, if you're running it in your terminal using bin/elasticsearch &, you can simply store the PID in a temporary file that you can lookup when you want to stop the node down.

    You start your node like this by storing the PID of the process in /tmp/elasticsearch-pid

    ./bin/elasticsearch -p /tmp/elasticsearch-pid -d
    

    And then when you need to shut down the node, you can simply retrieve the PID from the temporary file and kill the process.

    $ cat /tmp/elasticsearch-pid && echo
    15516
    $ kill -SIGTERM 15516