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

浪尽此生 提交于 2019-12-03 15:50:29

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

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!