elasticsearch 2.x 부터 Root로 보안상문제로 아래와 같이 실행되지 않음


Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.


그리고 shutdown 관련되서 기존 curl로 shutdown가 되지 않음 


https://www.elastic.co/guide/en/elasticsearch/reference/2.1/cluster-nodes-shutdown.html

The _shutdown API has been removed. Instead, setup Elasticsearch to run as a service (see Running as a Service on Linux or Running as a Service on Windows) or use the -p command line option to write the PID to a file.


yum(rpm)으로 설치 할 경우  init.d 스크립트를 만들어줘서 상관 없지만 그냥 소스 파일 가져다가 내가 원하는 위치에 압축풀어서 사용하므로 간단하게 만들었음 현재로서는 내가 원하는 기능만 간략하게~
상황에 따라서 추후 업데이트 예정

#!/bin/sh

DIR=$(echo $(cd $(dirname $0); pwd))

ES_HOME=${DIR}
ES_USER=elasticsearch
ES_HEAP_SIZE=1g
MAX_LOCKED_MEMORY=unlimited
MAX_OPEN_FILES=65535
MAX_MAP_COUNT=200000
PID=${ES_HOME}/elasticsearch.pid

if ! id -u "$ES_USER" >/dev/null 2>&1; then
    groupadd $ES_USER
    useradd -s /sbin/nologin -g $ES_USER $ES_USER
fi

case "$1" in
  start)
    chown -R ${ES_USER}.${ES_USER} ${DIR}

    if [ -n "$MAX_OPEN_FILES" ]; then
        ulimit -n $MAX_OPEN_FILES
    fi

    if [ -n "$MAX_LOCKED_MEMORY" ]; then
        ulimit -l $MAX_LOCKED_MEMORY
    fi

    if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then
        sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
    fi

    if [ -e ${PID} ] && [ ps -p `cat ${PID}` > /dev/null 2>&1 ]; then
       echo "Error - elasticsearch Running"
    else
       sudo -u ${ES_USER} ES_HEAP_SIZE="${ES_HEAP_SIZE}" ${ES_HOME}/bin/elasticsearch -d -p ${PID}
    fi

    ;;
  stop)
    if [ -e ${PID} ] ; then
       kill `cat ${PID}`
    fi
    ;;
  *)
    echo $"Usage: $0 {start | stop}"
    exit 1
esac
exit 0


추가로 host 처리 디폴트 localhost(127.0.0.1) 또는 아이피 동시 안되는 문제는 network.host 아래와 같이 하면됨

Allow binding to multiple addresses

https://github.com/elastic/elasticsearch/issues/13592

network.host: 0.0.0.0


Posted by 시니^^