【发布时间】:2021-04-17 15:11:41
【问题描述】:
我想在单个 docker-compose 文件中创建 2 个 elasticsearch 集群,这样我就可以只在新的 es 集群上测试一些更改,
我的 docker-compose 文件是这样的
version: "2.2"
services:
elasticsearch-master:
image: elasticsearch:6.6.0
volumes:
- esdata1:/usr/share/elasticsearch/data
ports:
- "9200:9200"
mem_limit: '2048M'
new-elasticsearch-master:
image: elasticsearch:6.6.0
volumes:
- esdata2:/usr/share/elasticsearch/data
ports:
- "9400:9200"
mem_limit: '2048M'
search:
image: search:latest
entrypoint: java -Delasticsearch.host=elasticsearch-master -DnewElasticsearch.host=new-elasticsearch-master -DnewElasticsearch.port=9400 -jar app.jar
ports:
- "8083:8083"
depends_on:
- elasticsearch-master
- new-elasticsearch-master
mem_limit: '500M'
volumes:
esdata1:
esdata2:
我有 1 个 java 服务,我在其中添加具有不同环境变量的主机
- -Delasticsearch.host=elasticsearch-master
- -DnewElasticsearch.host=new-elasticsearch-master
但是当我从 java 搜索服务运行代码如下
new RestTemplate().getForEntity("http://elasticsearch-master:9200/_cat/indices?v",String.class)
这给了我正确的回应。
但是当我尝试连接到 9400 上的另一台主机时。
new RestTemplate().getForEntity("http://new-elasticsearch-master:9400/_cat/indices?v",String.class)
我收到连接被拒绝错误
当我尝试使用 9200 的同一主机时,会得到 200 响应。
new RestTemplate().getForEntity("http://new-elasticsearch-master:9200/_cat/indices?v",String.class)
谁能告诉我如何用不同的端口进行 2 个不同的连接,如下所示。
- http://elasticsearch-master:9200
- http://new-elasticsearch-master:9400
谢谢
【问题讨论】:
标签: docker elasticsearch docker-compose