目录结构
├── config 配置目录
│ ├── es.yml es配置文件
│ ├── es1.yml es1配置文件
│ ├── es2.yml es2配置文件
└── docker-compose.yml docker-compose配置文件
docker-compose.yml
version: "2"
services:
es:
image: elasticsearch:5.6-alpine
container_name: es
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
ports:
- "9200:9200"
- "9300:9300"
volumes:
- ./config/es.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
networks:
- net-es
es1:
image: elasticsearch:5.6-alpine
container_name: es1
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
ports:
- "9201:9200"
- "9301:9300"
volumes:
- ./config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
networks:
- net-es
es2:
image: elasticsearch:5.6-alpine
container_name: es2
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
ports:
- "9202:9200"
- "9302:9300"
volumes:
- ./config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
networks:
- net-es
networks:
net-es:
es.yml
cluster.name: my-test
node.name: es
node.master: true
node.data: true
network.host: es
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.ping.unicast.hosts: ["es:9300", "es1:9300", "es2:9300"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s
bootstrap.memory_lock: true
action.destructive_requires_name: true
es1.yml
cluster.name: my-test
node.name: es1
node.master: true
node.data: true
network.host: es1
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.ping.unicast.hosts: ["es:9300", "es1:9300", "es2:9300"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s
bootstrap.memory_lock: true
action.destructive_requires_name: true
es2.yml
cluster.name: my-test
node.name: es2
node.master: false
node.data: true
network.host: es2
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.ping.unicast.hosts: ["es:9300", "es1:9300", "es2:9300"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s
bootstrap.memory_lock: true
action.destructive_requires_name: true
使用
安装 docker 和 docker-compose
执行命令 docker-compose up -d
打开 chrome 浏览器的插件 ElasticSearch Head, 效果如下图
本例子选择了 es 和 es1 为 master
若想方便看日志, 也可将 logs 挂载出来, 例如在 docker-compose.yml 中 es 的 volumes 加上
- ./logs/es/:/usr/share/elasticsearch/logs/:rw
同理 data 挂载出来可加上
- ./data/es/:/usr/share/elasticsearch/data/:rw