【发布时间】:2022-01-04 14:03:53
【问题描述】:
我有一个使用 elasticsearch db 和 mongodb 的 spring boot 应用程序。我想在一个 docker-container 上对它进行 dockerize,为此我编写了一个 docker-compose yml 文件,如下所示
version : "3"
services:
eswmongodb:
image: mongo:latest
container_name: mongocont
ports:
- "27017:27017"
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.9.3
container_name: elasticsearch
environment:
- node.name=elasticsearch
- discovery.type=single-node
- cluster.name=docker-cluster
ports:
- "9200:9200"
- "9300:9300"
esw:
image: esw
container_name: eswrapper
ports:
- "8071:8071"
links:
- elasticsearch
- eswmongodb
只有 mongodb 与 spring boot 应用程序连接,我可以访问它,但是当我点击一个使用 elasticsearch 的 api 时。我收到一个错误
出现异常:[连接被拒绝]
java.net.ConnectException:连接被拒绝
我在 application.properties 文件中提供了必要的信息。
spring.data.elasticsearch.cluster-node=elasticsearch:9200
spring.data.elasticsearch.cluster-name=docker-cluster
spring.data.mongodb.uri=mongodb://eswmongodb:27017/esw
关于为什么 elasticsearch 无法连接的任何想法。 我已经看到堆栈溢出中提供的早期答案,但问题仍然存在。
所有容器都显示正在运行。
也试过spring.data.elasticsearch.cluster-nodes这个属性,但它变成了禁用,所以我选择了spring.data.elasticsearch.cluster-node。
当我点击一个使用弹性搜索的 api 端点时,我还添加了日志中存在的实际异常,以便在需要时提供进一步的帮助。
2022-01-04 13:44:45,354 | ERROR | TxId=1641303885129000010435 |
IndexOperationsImpl.createIndexWithCustomSettingAndMapping:62 |
Exception Occurred with exception:[Connection refused]
java.net.ConnectException: Connection refused at
org.elasticsearch.client.RestClient.
extractAndWrapCause(RestClient.java:849)
at org.elasticsearch.client.RestClient.
performRequest(RestClient.java:259)
at org.elasticsearch.client.RestClient.
performRequest(RestClient.java:246)
点击docker-compose logs elasticsearch时elasticsearch容器的一些日志
Attaching to elasticsearch
elasticsearch | {"type": "server", "timestamp": "2022-01-
04T16:03:59,187Z", "level": "INFO", "component": "o.e.n.Node",
"cluster.name": "docker-cluster", "node.name": "elasticsearch",
"message": "version[7.9.3], pid[7],
[default/docker/c4138e51121ef06a6404866cddc601906fe5c868/2020
10-16T13:34:25.304557Z], OS[Linux/5.10.25-linuxkit/aarch64],
JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/15/15+36-1562]" }
elasticsearch | {"type": "server", "timestamp": "2022-01-
04T16:03:59,189Z", "level": "INFO", "component": "o.e.n.Node",
"cluster.name": "docker-cluster", "node.name": "elasticsearch",
"message": "JVM home [/usr/share/elasticsearch/jdk]" }
【问题讨论】:
-
您能否将“docker-compose logs elasticsearch”的输出粘贴到您的问题中?如果日志中有错误,您可以只粘贴错误即可。
-
刚开始就闻起来像死了的弹性容器。
-
links:是一个过时且不必要的 Compose 选项,它可能会干扰网络设置。删除links:块(或将其更改为depends_on:)有帮助吗?应用程序是否在 Elasticsearch 可用之前启动? -
是的应用程序正在运行,但仅使用 mongodb,如果我点击使用弹性搜索的 api,它会说连接被拒绝
-
@gohm'c,有很多日志。所以在问题中添加了一些部分。
标签: mongodb spring-boot docker elasticsearch docker-compose