Elasticsearch

Installing elasticsearch on Debian

Elasticsearch bash init file:[1]

create file "/etc/init.d/elasticsearch"

#! /bin/sh
### BEGIN INIT INFO
# Provides:          elasticsearch
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts elasticsearch
# Description:       Starts elasticsearch using start-stop-daemon
### END INIT INFO

NAME=elasticsearch
DESC=elasticsearch
ES_HOME=/usr/local/elasticsearch
ES_MIN_MEM=256m
ES_MAX_MEM=2g
DAEMON=$ES_HOME/bin/elasticsearch
PID_FILE=/var/run/$NAME.pid
LOG_DIR=/var/log/$NAME
DATA_DIR=/var/lib/$NAME
WORK_DIR=/tmp/$NAME
CONFIG_FILE=/etc/$NAME/elasticsearch.yml
DAEMON_OPTS="-p $PID_FILE -Des.config=$CONFIG_FILE -Des.path.home=$ES_HOME -Des.path.logs=$LOG_DIR -Des.path.data=$DATA_DIR -Des.path.work=$WORK_DIR -Des.max-open-files=true  -Xms2g -Xmx3g"
USER=elasticsearch

test -x $DAEMON || exit 0

set -e

case "$1" in
  start)
    echo -n "Starting $DESC:"
    mkdir -p $LOG_DIR $DATA_DIR $WORK_DIR
    touch $PID_FILE
    chown -R $USER: $LOG_DIR $DATA_DIR $WORK_DIR $PID_FILE
    if sudo -u $USER start-stop-daemon --start --pidfile $PID_FILE --chuid $USER --startas $DAEMON -- $DAEMON_OPTS &> /dev/null
    then
      echo -e "\e[1;32m started.\e[0m"
    else
      echo -e "\e[1;31m failed.\e[0m"
      ${0} status
    fi
    ;;
  stop)
    echo -n "Stopping $DESC:"
    if sudo -u $USER start-stop-daemon --stop --pidfile $PID_FILE &> /dev/null
    then
      echo -e "\e[1;32m stopped.\e[0m"
    else
      echo -e "\e[1;31m failed.\e[0m"
      ${0} status
    fi
    ;;
  status)
    echo -n $DESC "is"
    if [ -f $PID_FILE ]
    then
      if kill -0 `cat $PID_FILE` &> /dev/null
      then
        echo -e "\e[1;32m running\e[0m";
      else
        echo -e "\e[1;31m not running\e[0m";
      fi;
    else
      echo -e "\e[1;31m not running\e[0m";
    fi
    ;;
  restart|force-reload)
    ${0} stop
    sleep 2
    ${0} start
    sleep 1
    ${0} status
    ;;
  *)
    N=/etc/init.d/$NAME
    echo "Usage: $N {start|stop|status|restart|force-reload}" >&2
    exit 1
    ;;
esac

exit 0

Install the script:

sudo chmod +x /etc/init.d/elasticsearch
sudo update-rc.d elasticsearch defaults

to remove autoload:

sudo update-rc.d -f elasticsearch remove

Rise file limit for "elasticsearch" user:[2]

edit file "/etc/security/limits.conf"

elasticsearch soft nofile 32000
elasticsearch hard nofile 32000

and check new limits

sudo -u elasticsearch -s ulimit -Sn
sudo -u elasticsearch -s ulimit -Hn

Warning: DEBIAN libpam-modules (1.0.1-5) is bugged and limits set in /etc/security/limits.conf are ignored (more info #515673 and #597225)

Well it still wont work for me… and after a two days of fighting with file limits I figured out a trick:
without "sudo -u $USER" in start script:

[2011-11-10 12:40:01,366][INFO ][bootstrap                ] max_open_files [996]
[2011-11-10 12:40:01,383][INFO ][node                     ] [Contemplator] {elasticsearch/0.17.9}[14841]: initializing ...
[2011-11-10 12:40:01,388][INFO ][plugins                  ] [Contemplator] loaded [], sites []
[2011-11-10 12:40:03,473][INFO ][node                     ] [Contemplator] {elasticsearch/0.17.9}[14841]: initialized
[2011-11-10 12:40:03,473][INFO ][node                     ] [Contemplator] {elasticsearch/0.17.9}[14841]: starting ...
[2011-11-10 12:40:03,539][INFO ][transport                ] [Contemplator] bound_address {inet[/0:0:0:0:0:0:0:0:9300]}, publish_address {inet[/172.18.0.3:9300]}
[2011-11-10 12:40:06,567][INFO ][cluster.service          ] [Contemplator] new_master [Contemplator][0B76toscTh-9D4lrnzEP3w][inet[/172.18.0.3:9300]], reason: zen-disco-join (elected_a
s_master)
[2011-11-10 12:40:06,614][INFO ][discovery                ] [Contemplator] es_migomat/0B76toscTh-9D4lrnzEP3w
[2011-11-10 12:40:06,715][INFO ][http                     ] [Contemplator] bound_address {inet[/0:0:0:0:0:0:0:0:9200]}, publish_address {inet[/172.18.0.3:9200]}
[2011-11-10 12:40:06,716][INFO ][node                     ] [Contemplator] {elasticsearch/0.17.9}[14841]: started
[2011-11-10 12:40:07,290][INFO ][gateway                  ] [Contemplator] recovered [1] indices into cluster_state

with "sudo -u $USER" in start script:

[2011-11-10 12:46:44,959][INFO ][bootstrap                ] max_open_files [31981]
[2011-11-10 12:46:44,976][INFO ][node                     ] [Dmitri Bukharin] {elasticsearch/0.17.9}[15724]: initializing ...
[2011-11-10 12:46:44,982][INFO ][plugins                  ] [Dmitri Bukharin] loaded [], sites []
[2011-11-10 12:46:46,879][INFO ][node                     ] [Dmitri Bukharin] {elasticsearch/0.17.9}[15724]: initialized
[2011-11-10 12:46:46,880][INFO ][node                     ] [Dmitri Bukharin] {elasticsearch/0.17.9}[15724]: starting ...
[2011-11-10 12:46:46,938][INFO ][transport                ] [Dmitri Bukharin] bound_address {inet[/0:0:0:0:0:0:0:0:9300]}, publish_address {inet[/172.18.0.3:9300]}
[2011-11-10 12:46:49,976][INFO ][cluster.service          ] [Dmitri Bukharin] new_master [Dmitri Bukharin][lpW7XAgjTwSpM6cejwtssg][inet[/172.18.0.3:9300]], reason: zen-disco-join (elected_as_master)
[2011-11-10 12:46:50,018][INFO ][discovery                ] [Dmitri Bukharin] es_migomat/lpW7XAgjTwSpM6cejwtssg
[2011-11-10 12:46:50,110][INFO ][http                     ] [Dmitri Bukharin] bound_address {inet[/0:0:0:0:0:0:0:0:9200]}, publish_address {inet[/172.18.0.3:9200]}
[2011-11-10 12:46:50,111][INFO ][node                     ] [Dmitri Bukharin] {elasticsearch/0.17.9}[15724]: started
[2011-11-10 12:46:50,781][INFO ][gateway                  ] [Dmitri Bukharin] recovered [1] indices into cluster_state
Add a New Comment
or Sign in as Wikidot user
(will not be published)
- +
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License