Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run multiple elasticsearch nodes as a service on one Ubuntu-Server

I have a server running Ubuntu 14.04 with 220 GB of ram on which I'd like to run elasticsearch. According to the documentation, one node should not have more than 32 GB of RAM, so I guess I have to run several nodes on this one machine in order to make use of all that RAM. I'm considering running 4 nodes with 28 GB of memory for each.

How do I set this up as an ubuntu service, so that all of the nodes automatically come back up after a system reboot for example? I guess I have to edit /etc/init.d/elasticsearch in some way - can anyone help me out?

Thank you guys so much!

like image 571
user167172 Avatar asked Oct 02 '14 14:10

user167172


People also ask

How do I run multiple instances of Elasticsearch on the same server?

You can create multiple config dirs if you wish and then start elasticsearch with -Epath. conf=config1 . For each instance you need to create 'config, data, and logs' folders. e.g. create config1, config2, ...

Can I run multiple Elasticsearch nodes on the same machine?

In this case is better to have a larger node instance. But to run multiple nodes in the same hosts you need to have a different elasticsearch. yml for every node with separated data and log folders, there isn't a way to use the same elasticsearch. yml to run multiple nodes at the same time.


2 Answers

I gave up after a while, removed the elasticsearch repo-installation and downloaded the zip-file instead. Then I created two upstart-jobs and everythings works smoothly so far.

  1. Wrapper

    description "Start several ES-instances at once (this is a wrapper)."

    start on (local-filesystems and net-device-up IFACE!=lo)
    stop on runlevel [06] 
    respawn

    # Give up respawn if restart occurs 5 times in 120 seconds
    respawn limit 5 120

    env NUM_INSTANCES=4

    pre-start script
        for i in $(seq 1 $NUM_INSTANCES)
        do
            start elasticsearch-instance ID=$i
        done
    end script

    pre-stop script
        curl -XPOST "http://localhost:9200/_cluster/nodes/_local/_shutdown"
    end script

  1. Instances

    description "starts up an elasticsearch instance (node)"

    stop on stopping elasticsearch
    respawn

    instance $ID

    limit nofile 64000 64000

    setuid elasticsearch
    setgid elasticsearch

    env JAVA_OPTS="-XX:+UseCompressedOops"
    env ES_HEAP_SIZE=28G
    exec /data/elasticsearch/bin/elasticsearch -Des.config=/data/elasticsearch/config/elasticsearch.yml
like image 131
user167172 Avatar answered Sep 27 '22 23:09

user167172


Assuming your rpm or deb created an init.d script, to start a second node on the same machine do as follows:

cd /etc/init.d
cp --preserve elasticsearch elasticsearch2

Edit elasticsearch2 script:

  1. change # elasticsearch to # elasticsearch2
  2. add node="2" after line prog="elasticsearch"
  3. change pidfile=/var/run/elasticsearch/${prog}.pid to pidfile=/var/run/elasticsearch/${prog}${node}.pid
  4. change lockfile=/var/lock/subsys/$prog to lockfile=/var/lock/subsys/$prog$node
  5. change echo -n $"Starting $prog: " to echo -n $"Starting $prog: (node $node)"
  6. change echo -n $"Stopping $prog: " to echo -n $"Stopping $prog: (node $node)"

Save the file. Execute

chkconfig --add elasticsearch2
service elasticsearch2 start
like image 29
gnom1gnom Avatar answered Sep 27 '22 23:09

gnom1gnom