From d4a888073b77e10bf580f2b6beae5049de55a4be Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Fri, 4 Nov 2016 20:18:43 -0500 Subject: [PATCH] [es] Upgrade to 5.0.0 --- elasticsearch/Dockerfile | 16 ++- elasticsearch/log4j2.properties | 74 ++++++++++++ elasticsearch/start | 192 ++++++++++++++++++-------------- 3 files changed, 190 insertions(+), 92 deletions(-) create mode 100644 elasticsearch/log4j2.properties diff --git a/elasticsearch/Dockerfile b/elasticsearch/Dockerfile index 670d8137..2c7258d8 100755 --- a/elasticsearch/Dockerfile +++ b/elasticsearch/Dockerfile @@ -2,20 +2,21 @@ FROM java:8u92-jre-alpine MAINTAINER itzg -ENV ES_VERSION=2.4.1 +RUN apk -U add bash -ADD https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/$ES_VERSION/elasticsearch-$ES_VERSION.tar.gz /tmp/es.tgz +ENV ES_VERSION=5.0.0 + +ADD https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-$ES_VERSION.tar.gz /tmp/es.tgz RUN cd /usr/share && \ tar xf /tmp/es.tgz && \ rm /tmp/es.tgz -COPY start /start - EXPOSE 9200 9300 ENV ES_HOME=/usr/share/elasticsearch-$ES_VERSION \ - OPTS=-Dnetwork.host=_non_loopback_ \ - DEFAULT_ES_USER=elasticsearch + DEFAULT_ES_USER=elasticsearch \ + DISCOVER_TRANSPORT_IP=eth0 \ + DISCOVER_HTTP_IP=eth0 RUN adduser -S -s /bin/sh $DEFAULT_ES_USER @@ -23,4 +24,7 @@ VOLUME ["/data","/conf"] WORKDIR $ES_HOME +COPY start /start +COPY log4j2.properties $ES_HOME/config/ + CMD ["/start"] diff --git a/elasticsearch/log4j2.properties b/elasticsearch/log4j2.properties new file mode 100644 index 00000000..e1cf3521 --- /dev/null +++ b/elasticsearch/log4j2.properties @@ -0,0 +1,74 @@ +status = error + +# log action execution errors for easier debugging +logger.action.name = org.elasticsearch.action +logger.action.level = debug + +appender.console.type = Console +appender.console.name = console +appender.console.layout.type = PatternLayout +appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%m%n + +appender.rolling.type = RollingFile +appender.rolling.name = rolling +appender.rolling.fileName = ${sys:es.logs}.log +appender.rolling.layout.type = PatternLayout +appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%.10000m%n +appender.rolling.filePattern = ${sys:es.logs}-%d{yyyy-MM-dd}.log +appender.rolling.policies.type = Policies +appender.rolling.policies.time.type = TimeBasedTriggeringPolicy +appender.rolling.policies.time.interval = 1 +appender.rolling.policies.time.modulate = true + +rootLogger.level = info +rootLogger.appenderRef.console.ref = console +#rootLogger.appenderRef.rolling.ref = rolling + +appender.deprecation_rolling.type = RollingFile +appender.deprecation_rolling.name = deprecation_rolling +appender.deprecation_rolling.fileName = ${sys:es.logs}_deprecation.log +appender.deprecation_rolling.layout.type = PatternLayout +appender.deprecation_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%.10000m%n +appender.deprecation_rolling.filePattern = ${sys:es.logs}_deprecation-%i.log.gz +appender.deprecation_rolling.policies.type = Policies +appender.deprecation_rolling.policies.size.type = SizeBasedTriggeringPolicy +appender.deprecation_rolling.policies.size.size = 1GB +appender.deprecation_rolling.strategy.type = DefaultRolloverStrategy +appender.deprecation_rolling.strategy.max = 4 + +logger.deprecation.name = org.elasticsearch.deprecation +logger.deprecation.level = warn +#logger.deprecation.appenderRef.deprecation_rolling.ref = deprecation_rolling +logger.deprecation.additivity = false + +appender.index_search_slowlog_rolling.type = RollingFile +appender.index_search_slowlog_rolling.name = index_search_slowlog_rolling +appender.index_search_slowlog_rolling.fileName = ${sys:es.logs}_index_search_slowlog.log +appender.index_search_slowlog_rolling.layout.type = PatternLayout +appender.index_search_slowlog_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %marker%.10000m%n +appender.index_search_slowlog_rolling.filePattern = ${sys:es.logs}_index_search_slowlog-%d{yyyy-MM-dd}.log +appender.index_search_slowlog_rolling.policies.type = Policies +appender.index_search_slowlog_rolling.policies.time.type = TimeBasedTriggeringPolicy +appender.index_search_slowlog_rolling.policies.time.interval = 1 +appender.index_search_slowlog_rolling.policies.time.modulate = true + +logger.index_search_slowlog_rolling.name = index.search.slowlog +logger.index_search_slowlog_rolling.level = trace +logger.index_search_slowlog_rolling.appenderRef.index_search_slowlog_rolling.ref = console +logger.index_search_slowlog_rolling.additivity = false + +appender.index_indexing_slowlog_rolling.type = RollingFile +appender.index_indexing_slowlog_rolling.name = index_indexing_slowlog_rolling +appender.index_indexing_slowlog_rolling.fileName = ${sys:es.logs}_index_indexing_slowlog.log +appender.index_indexing_slowlog_rolling.layout.type = PatternLayout +appender.index_indexing_slowlog_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %marker%.10000m%n +appender.index_indexing_slowlog_rolling.filePattern = ${sys:es.logs}_index_indexing_slowlog-%d{yyyy-MM-dd}.log +appender.index_indexing_slowlog_rolling.policies.type = Policies +appender.index_indexing_slowlog_rolling.policies.time.type = TimeBasedTriggeringPolicy +appender.index_indexing_slowlog_rolling.policies.time.interval = 1 +appender.index_indexing_slowlog_rolling.policies.time.modulate = true + +logger.index_indexing_slowlog.name = index.indexing.slowlog.index +logger.index_indexing_slowlog.level = trace +logger.index_indexing_slowlog.appenderRef.index_indexing_slowlog_rolling.ref = console +logger.index_indexing_slowlog.additivity = false diff --git a/elasticsearch/start b/elasticsearch/start index d76cb8d6..6595f45a 100755 --- a/elasticsearch/start +++ b/elasticsearch/start @@ -1,5 +1,98 @@ #!/bin/sh +pre_checks() { + mmc=$(sysctl vm.max_map_count|sed 's/.*= //') + if [[ $mmc -lt 262144 ]]; then + echo " +ERROR: As of 5.0.0 Elasticsearch requires increasing mmap counts. +Refer to https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html +" + exit 1 + fi +} + +discoverIpFromLink() { + dev=$1 + mode=$2 + ip=`ipaddr show dev $dev scope global|awk '$1 == "inet" { if (!match($2,"/32")) { gsub("/.*","",$2) ; print $2 } }'` + echo "Discovered $mode address $ip for $dev" + OPTS="$OPTS -E $mode.host=$ip" +} + +setup_clustering() { + + if [ -n "$CLUSTER" ]; then + OPTS="$OPTS -E cluster.name=$CLUSTER" + if [ -n "$CLUSTER_FROM" ]; then + if [ -d /data/$CLUSTER_FROM -a ! -d /data/$CLUSTER ]; then + echo "Performing cluster data migration from $CLUSTER_FROM to $CLUSTER" + mv /data/$CLUSTER_FROM /data/$CLUSTER + fi + fi + fi + + if [ -n "$NODE_NAME" ]; then + OPTS="$OPTS -E node.name=$NODE_NAME" + fi + + if [ -n "$MULTICAST" ]; then + OPTS="$OPTS -E discovery.zen.ping.multicast.enabled=$MULTICAST" + fi + + if [ -n "$UNICAST_HOSTS" ]; then + OPTS="$OPTS -E discovery.zen.ping.unicast.hosts=$UNICAST_HOSTS" + fi + + if [ -n "$PUBLISH_AS" ]; then + OPTS="$OPTS -E transport.publish_host=$(echo $PUBLISH_AS | awk -F: '{print $1}')" + OPTS="$OPTS -E transport.publish_port=$(echo $PUBLISH_AS | awk -F: '{if ($2) print $2; else print 9300}')" + fi + + if [ -n "$MIN_MASTERS" ]; then + OPTS="$OPTS --discovery.zen.minimum_master_nodes=$MIN_MASTERS" + fi + +} + +install_plugins() { + + if [ -n "$PLUGINS" ]; then + for p in $(echo $PLUGINS | awk -v RS=, '{print}') + do + echo "Installing the plugin $p" + $ES_HOME/bin/elasticsearch-plugin install $p + done + else + mkdir -p $ES_HOME/plugins + fi +} + +setup_personality() { + + if [ -n "$TYPE" ]; then + case $TYPE in + MASTER) + OPTS="$OPTS --node.master=true --node.data=false" + ;; + + GATEWAY) + OPTS="$OPTS --node.master=false --node.data=false" + ;; + + DATA|NON_MASTER) + OPTS="$OPTS --node.master=false --node.data=true" + ;; + + *) + echo "Unknown node type. Please use MASTER|GATEWAY|DATA|NON_MASTER" + exit 1 + esac + fi + +} + +pre_checks + if [ -f /conf/env ]; then . /conf/env fi @@ -8,95 +101,23 @@ if [ ! -e /conf/elasticsearch.* ]; then cp $ES_HOME/config/elasticsearch.yml /conf fi -if [ ! -e /conf/logging.* ]; then - cp $ES_HOME/config/logging.yml /conf +if [ ! -e /conf/log4j2.properties ]; then + cp $ES_HOME/config/log4j2.properties /conf fi -OPTS="$OPTS -Des.path.conf=/conf \ - -Des.path.data=/data \ - -Des.path.logs=/data \ - -Des.transport.tcp.port=9300 \ - -Des.http.port=9200" +OPTS="$OPTS \ + -E path.conf=/conf \ + -E path.data=/data \ + -E path.logs=/data \ + -E transport.tcp.port=9300 \ + -E http.port=9200" -discoverIpFromLink() { - dev=$1 - mode=$2 - ip=`ipaddr show dev $dev scope global|awk '$1 == "inet" { if (!match($2,"/32")) { gsub("/.*","",$2) ; print $2 } }'` - echo "Discovered $mode address $ip for $dev" - OPTS="$OPTS -Des.$mode.host=$ip" -} +discoverIpFromLink $DISCOVER_TRANSPORT_IP transport +discoverIpFromLink $DISCOVER_HTTP_IP http -if [ "$DISCOVER_TRANSPORT_IP" != "" ]; then - discoverIpFromLink $DISCOVER_TRANSPORT_IP transport -fi -if [ "$DISCOVER_HTTP_IP" != "" ]; then - discoverIpFromLink $DISCOVER_HTTP_IP http -fi - -if [ -n "$CLUSTER" ]; then - OPTS="$OPTS -Des.cluster.name=$CLUSTER" - if [ -n "$CLUSTER_FROM" ]; then - if [ -d /data/$CLUSTER_FROM -a ! -d /data/$CLUSTER ]; then - echo "Performing cluster data migration from $CLUSTER_FROM to $CLUSTER" - mv /data/$CLUSTER_FROM /data/$CLUSTER - fi - fi -fi - -if [ -n "$NODE_NAME" ]; then - OPTS="$OPTS -Des.node.name=$NODE_NAME" -fi - -if [ -n "$MULTICAST" ]; then - OPTS="$OPTS -Des.discovery.zen.ping.multicast.enabled=$MULTICAST" -fi - -if [ -n "$UNICAST_HOSTS" ]; then - OPTS="$OPTS -Des.discovery.zen.ping.unicast.hosts=$UNICAST_HOSTS" -fi - -if [ -n "$PUBLISH_AS" ]; then - OPTS="$OPTS -Des.transport.publish_host=$(echo $PUBLISH_AS | awk -F: '{print $1}')" - OPTS="$OPTS -Des.transport.publish_port=$(echo $PUBLISH_AS | awk -F: '{if ($2) print $2; else print 9300}')" -fi - -if [ -n "$TYPE" ]; then - case $TYPE in - MASTER) - OPTS="$OPTS --node.master=true --node.data=false" - ;; - - GATEWAY) - OPTS="$OPTS --node.master=false --node.data=false" - ;; - - DATA|NON_MASTER) - OPTS="$OPTS --node.master=false --node.data=true" - ;; - - *) - echo "Unknown node type. Please use MASTER|GATEWAY|DATA|NON_MASTER" - exit 1 - esac -fi - -if [ -n "$MIN_MASTERS" ]; then - OPTS="$OPTS --discovery.zen.minimum_master_nodes=$MIN_MASTERS" -fi - -mkdir -p /conf/plugins -OPTS="$OPTS --path.plugins=/conf/plugins" - -if [ -n "$PLUGINS" ]; then - PLUGIN_OPTS="-Des.path.conf=/conf -Des.path.plugins=/conf/plugins" - for p in $(echo $PLUGINS | awk -v RS=, '{print}') - do - echo "Installing the plugin $p" - $ES_HOME/bin/plugin $PLUGIN_OPTS install $p -t 1m -b - done -else - mkdir -p /conf/plugins -fi +setup_personality +setup_clustering +install_plugins mkdir -p /conf/scripts @@ -105,7 +126,6 @@ CMD="$ES_HOME/bin/elasticsearch $OPTS" if [ `id -u` = 0 ]; then echo "Running as non-root..." chown -R $DEFAULT_ES_USER /data - set -x su -c "$CMD" $DEFAULT_ES_USER else $CMD