docker-compose 编排es
时间: 2023-10-21 08:06:56 浏览: 157
通过docker-compose编排一系列环境进行一键快速部署运行,小白运维神器
要使用 docker-compose 编排 Elasticsearch 集群,可以参考以下步骤:
1. 创建一个 docker-compose.yml 文件,定义 Elasticsearch 服务的配置。例如:
```
version: '3'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.14.0
container_name: es01
environment:
- node.name=es01
- cluster.name=my-es-cluster
- discovery.seed_hosts=es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata01:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- esnet
es02:
image: docker.elastic.co/elasticsearch/elasticsearch:7.14.0
container_name: es02
environment:
- node.name=es02
- cluster.name=my-es-cluster
- discovery.seed_hosts=es01,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata02:/usr/share/elasticsearch/data
networks:
- esnet
es03:
image: docker.elastic.co/elasticsearch/elasticsearch:7.14.0
container_name: es03
environment:
- node.name=es03
- cluster.name=my-es-cluster
- discovery.seed_hosts=es01,es02
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata03:/usr/share/elasticsearch/data
networks:
- esnet
volumes:
esdata01:
esdata02:
esdata03:
networks:
esnet:
```
2. 在终端中进入 docker-compose.yml 文件所在的目录,运行以下命令启动 Elasticsearch 集群:
```
docker-compose up -d
```
3. 等待一段时间,直到 Elasticsearch 集群启动完成。可以通过以下命令查看集群状态:
```
curl http://localhost:9200/_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
1630459477 08:31:17 my-es-cluster green 3 3 15 15 0 0 0 0 - 100.0%
```
阅读全文