docker-compose部署elasticsearch集群
一、准备基础镜像
docker pull elasticsearch:7.3.2
二、dockerfile(Dockerfile-elasticsearch),为了保护原生的镜像
FROM elasticsearch:7.3.2 MAINTAINER lilin RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
三、集群配置
version: '2'
services:
es-1: build: context: ./ dockerfile: ./Dockerfile/Dockerfile-elasticsearch image: es-1 restart: always container_name: es-1 environment: - ES_JAVA_OPTS=-Xms1g -Xmx1g -XX:+HeapDumpOnOutOfMemoryError - cluster.name=cluster - node.name=es-1 - node.master=true
- node.data=true - network.host=0.0.0.0 - http.port=9200 - transport.tcp.port=9300 - discovery.seed_hosts=es-1:9300 - cluster.initial_master_nodes=es-1
- xpack.sql.enabled=false volumes: - /usr/share/elasticsearch/data-1:/usr/share/elasticsearch/data - /usr/share/elasticsearch/plugins-1:/usr/share/elasticsearch/plugins ports: - 9200:9200 es-2: build: context: ./ dockerfile: ./Dockerfile/Dockerfile-elasticsearch image: es-2 restart: always container_name: es-2 environment: - ES_JAVA_OPTS=-Xms1g -Xmx1g -XX:+HeapDumpOnOutOfMemoryError - cluster.name=cluster - node.name=es-2 - node.master=true
- node.data=true - network.host=0.0.0.0 - http.port=9201 - transport.tcp.port=9301 - discovery.seed_hosts=es-1:9300,es-2:9301 - cluster.initial_master_nodes=es-1,es-2
- xpack.sql.enabled=false volumes: - /usr/share/elasticsearch/data-2:/usr/share/elasticsearch/data - /usr/share/elasticsearch/plugins-2:/usr/share/elasticsearch/plugins ports: - 9201:9201
四、启动测试