Linux版本:Ubuntu 16.04.2 LTS
Docker版本:Docker version 17.09.0-ce, build afdb6d4
Docker Compose版本:docker-compose version 1.22.0, build f46880fe
JDK版本:java version "1.8.0_102"
ElasticSearch版本:elasticsearch-7.3.0
相关构建配置文件如下:
ElasticSearch Dockerfile
From jdk:1.8.0.102
MAINTAINER xxxxx
RUN useradd --create-home --no-log-init --shell /bin/bash esserver
ADD elasticsearch-7.3.0.tar.gz /home/esserver/
COPY elasticsearch.yml /home/esserver/elasticsearch-7.3.0/config/
COPY analysis-ik-config /home/esserver/elasticsearch-7.3.0/config/analysis-ik
COPY analysis-ik-plugin /home/esserver/elasticsearch-7.3.0/plugins/analysis-ik
ENV ELASTICSEARCH_HOME=/home/esserver/elasticsearch-7.3.0 \
ELASTICSEARCH_CONF_DIR=/home/esserver/elasticsearch-7.3.0/config \
ES_NODE_NAME=node \
ES_NODE_MASTER=false \
ES_NODE_DATA=true \
ES_NETWORK_HOST=0.0.0.0 \
ES_CLUSTER_INITIAL_MASTER_NODES=[] \
ES_DISCOVERY_ZEN_PING_UNICAST_HOSTS=[]
RUN chown -R esserver:esserver /home/esserver
USER esserver
WORKDIR $ELASTICSEARCH_HOME
EXPOSE 9200 9300
COPY elasticsearch-entrypoint.sh /home/esserver/
ENTRYPOINT ["/home/esserver/elasticsearch-entrypoint.sh"]
elasticsearch.yml
cluster.name: cluster-application
path.data: /home/esserver/elasticsearch-7.3.0/data
path.logs: /home/esserver/elasticsearch-7.3.0/logs
bootstrap.memory_lock: true
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
transport.tcp.compress: true
http.cors.enabled: true
http.cors.allow-origin: "*"
analysis-ik
elasticsearch-entrypoint.sh
#!/bin/bash
set -e
CONFIG="$ELASTICSEARCH_CONF_DIR/elasticsearch.yml"
if [[ -f "$CONFIG" ]]; then
echo "" >> "$CONFIG"
echo "node.name: $ES_NODE_NAME" >> "$CONFIG"
echo "node.master: $ES_NODE_MASTER" >> "$CONFIG"
echo "node.data: $ES_NODE_DATA" >> "$CONFIG"
echo "discovery.zen.ping.unicast.hosts: $ES_DISCOVERY_ZEN_PING_UNICAST_HOSTS" >> "$CONFIG"
echo "cluster.initial_master_nodes: $ES_CLUSTER_INITIAL_MASTER_NODES" >> "$CONFIG"
fi
$ELASTICSEARCH_HOME/bin/elasticsearch -d
exec "$@"
docker build --no-cache --file Dockerfile -t elasticsearch:7.3.0 .
docker-compose.yml
version: '2'
services:
node1:
image: elasticsearch:7.3.0
restart: always
hostname: node1
container_name: node1
ports:
- 19201:9200
- 19301:9300
volumes:
- "/home/ym/Software/elasticsearch-7.3.0/cluster/node1/data:/usr/local/elasticsearch-7.3.0/data"
- "/home/ym/Software/elasticsearch-7.3.0/cluster/node1/logs:/usr/local/elasticsearch-7.3.0/logs"
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "ES_NODE_NAME=node1"
- "ES_NODE_MASTER=true"
- "ES_NODE_DATA=false"
- "ES_CLUSTER_INITIAL_MASTER_NODES=[\"node1\"]"
- "ES_DISCOVERY_ZEN_PING_UNICAST_HOSTS=[\"node1:9300\", \"node2:9300\", \"node3:9300\"]"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
mem_limit: 1g
node2:
image: elasticsearch:7.3.0
restart: always
hostname: node2
container_name: node2
ports:
- 19202:9200
- 19302:9300
volumes:
- "/home/ym/Software/elasticsearch-7.3.0/cluster/node2/data:/usr/local/elasticsearch-7.3.0/data"
- "/home/ym/Software/elasticsearch-7.3.0/cluster/node2/logs:/usr/local/elasticsearch-7.3.0/logs"
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "ES_NODE_NAME=node2"
- "ES_NODE_MASTER=false"
- "ES_NODE_DATA=true"
- "ES_CLUSTER_INITIAL_MASTER_NODES=[\"node1\"]"
- "ES_DISCOVERY_ZEN_PING_UNICAST_HOSTS=[\"node1:9300\", \"node2:9300\", \"node3:9300\"]"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
mem_limit: 1g
node3:
image: elasticsearch:7.3.0
restart: always
hostname: node3
container_name: node3
ports:
- 19203:9200
- 19303:9300
volumes:
- "/home/ym/Software/elasticsearch-7.3.0/cluster/node3/data:/usr/local/elasticsearch-7.3.0/data"
- "/home/ym/Software/elasticsearch-7.3.0/cluster/node3/logs:/usr/local/elasticsearch-7.3.0/logs"
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "ES_NODE_NAME=node3"
- "ES_NODE_MASTER=false"
- "ES_NODE_DATA=true"
- "ES_CLUSTER_INITIAL_MASTER_NODES=[\"node1\"]"
- "ES_DISCOVERY_ZEN_PING_UNICAST_HOSTS=[\"node1:9300\", \"node2:9300\", \"node3:9300\"]"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
mem_limit: 1g
networks:
bridge:
external:
name: bridge
docker-compose up -d
在宿主服务器上验证ElasticSearch集群
$ curl -XGET 'http://192.168.0.1:19201'
{
"name" : "node1",
"cluster_name" : "cluster-application",
"cluster_uuid" : "VAuWyQ_AQgOx0i-m8kTofA",
"version" : {
"number" : "7.3.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "de777fa",
"build_date" : "2019-07-24T18:30:11.767338Z",
"build_snapshot" : false,
"lucene_version" : "8.1.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
$ curl -XGET 'http://192.168.0.1:19201/_cat/master?v'
id host ip node
WguL_hAyRfyF7KHF-Wj4Iw 172.20.0.2 172.20.0.2 node1
$ curl -XGET 'http://192.168.0.1:19201/_cat/nodes?v'
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
172.20.0.3 24 95 3 0.31 0.50 0.75 di - node3
172.20.0.2 22 95 3 0.31 0.50 0.75 im * node1
172.20.0.4 22 95 3 0.31 0.50 0.75 di - node2
$ curl -XGET 'http://192.168.0.1:19201/_cat/health?v'
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1566455028 06:23:48 cluster-application green 3 2 0 0 0 0 0 0 - 100.0%