[es] Fix address binding for Swarm Mode

This commit is contained in:
Geoff Bourne 2017-01-23 10:25:50 -06:00
parent 4a7ecffcbb
commit b8d69278e4
3 changed files with 18 additions and 14 deletions

View File

@ -15,8 +15,6 @@ EXPOSE 9200 9300
ENV ES_HOME=/usr/share/elasticsearch-$ES_VERSION \ ENV ES_HOME=/usr/share/elasticsearch-$ES_VERSION \
DEFAULT_ES_USER=elasticsearch \ DEFAULT_ES_USER=elasticsearch \
DISCOVER_TRANSPORT_IP=eth0 \
DISCOVER_HTTP_IP=eth0 \
ES_JAVA_OPTS="-Xms1g -Xmx1g" ES_JAVA_OPTS="-Xms1g -Xmx1g"
RUN adduser -S -s /bin/sh $DEFAULT_ES_USER RUN adduser -S -s /bin/sh $DEFAULT_ES_USER

View File

@ -182,20 +182,16 @@ Using the Docker Compose file above, a value of `2` is appropriate when scaling
docker-compose scale master=3 docker-compose scale master=3
## Auto transport/http discovery with Swarm Mode ## Multiple Network Binding, such as Swarm Mode
When using Docker Swarm mode (starting with 1.12), the overlay and ingress network interfaces are assigned When using Docker Swarm mode the container is presented with multiple ethernet
multiple IP addresses. As a result, it creates confusion for the transport publish logic even when using devices. By default, all global, routable IP addresses are configured for
the special value `_eth0_`. Elasticsearch to use as `network.host`.
To resolve this, add That discovery can be overridden by providing a specific ethernet device name
to `DISCOVER_TRANSPORT_IP` and/or `DISCOVER_HTTP_IP`, such as
-e DISCOVER_TRANSPORT_IP=eth0 -e DISCOVER_TRANSPORT_IP=eth0
replacing `eth0` with another interface within the container, if needed.
The same can be done for publish/binding of the http module by adding:
-e DISCOVER_HTTP_IP=eth2 -e DISCOVER_HTTP_IP=eth2
## Heap size and other JVM options ## Heap size and other JVM options

View File

@ -19,6 +19,11 @@ discoverIpFromLink() {
OPTS="$OPTS -E $mode.host=$ip" OPTS="$OPTS -E $mode.host=$ip"
} }
discoverAllGlobalIps() {
ips=`ipaddr show scope global|awk '$1 == "inet" { if (!match($2,"/32")) { gsub("/.*","",$2) ; addrs[length(addrs)] = $2 } } END { for (i in addrs) { if (i>0) printf "," ; printf addrs[i] } }'`
OPTS="$OPTS -E network.host=$ips"
}
setup_clustering() { setup_clustering() {
if [ -n "$CLUSTER" ]; then if [ -n "$CLUSTER" ]; then
@ -112,8 +117,13 @@ OPTS="$OPTS \
-E transport.tcp.port=9300 \ -E transport.tcp.port=9300 \
-E http.port=9200" -E http.port=9200"
discoverIpFromLink $DISCOVER_TRANSPORT_IP transport discoverAllGlobalIps
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
setup_personality setup_personality
setup_clustering setup_clustering