无法从在Docker合成外部本地运行的Java应用程序连接到在Docker合成设置上启动的elasticsearch

mzaanser  于 2023-03-16  发布在  Java
关注(0)|答案(1)|浏览(116)

我有下面的docker-compose yml文件,我用它来启动所需的所有基础设施:

version: "3.9"
services:
  redis:
    image: redis:3
    ports:
      - "6379:6379"
    #network_mode: host
  rabbitmq:
    image: rabbitmq:3-management
    ports:
      - "5672:5672"
      - "15672:15672"
    #network_mode: host
  mongo:
    image: mongo:3.6.3
    ports:
      - "27017:27017"
    #network_mode: host
  elasticsearch:
    image: xxxx/elasticsearch:latest
    ports:
      - "9200:9200"
      - "9300:9300"
  x-service:
    build:
      context: ../../x-service
      dockerfile: Dockerfile
    environment:
      - CONFIG_FILE=x-service.ini
    ports:
      - "4003:4003"

当我执行命令docker-compose start时,一切都正确启动。x服务java应用程序与elasticsearch成功连接,并且能够启动,没有任何问题。
同时,本地启动的同一个x-service java应用程序(没有docker-compose)无法连接到ElasticSearch,无法启动。下面是我尝试启动x-service时的错误:

14:47:36.107 [WARN] io.dexi.search.index.SearchEngineIndex - [main] Failed while looking up index
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{127.0.0.1}{localhost/127.0.0.1:9300}]
    at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:290) ~[elasticsearch-2.1.1.jar:2.1.1]
    at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:207) ~[elasticsearch-2.1.1.jar:2.1.1]
    at org.elasticsearch.client.transport.support.TransportProxyClient.execute(TransportProxyClient.java:55) ~[elasticsearch-2.1.1.jar:2.1.1]
    at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:283) ~[elasticsearch-2.1.1.jar:2.1.1]
    at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:347) ~[elasticsearch-2.1.1.jar:2.1.1]
    at org.elasticsearch.client.support.AbstractClient$IndicesAdmin.execute(AbstractClient.java:1183) ~[elasticsearch-2.1.1.jar:2.1.1]
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:85) ~[elasticsearch-2.1.1.jar:2.1.1]
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:59) ~[elasticsearch-2.1.1.jar:2.1.1]
    at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:67) ~[elasticsearch-2.1.1.jar:2.1.1]

下图显示了ElasticSearch可以从localhost访问,因为我可以连接ElasticSearch头客户端:

我不明白为什么会发生这个错误。我已经检查了在使用docker-compose设置运行和在本地运行java应用程序时,集群名称是否与java应用程序上配置的相同。
以下是来自elasticsearch的详细信息:

"name": "Sally Floyd",
"transport_address": "172.18.0.5:9300",
"host": "172.18.0.5",
"ip": "172.18.0.5",
"version": "2.1.1",
"build": "40e2c53",
"http_address": "172.18.0.5:9200",
"settings": {
"name": "Sally Floyd",
"client": {
"type": "node"
},
"cluster": {
"name": "elasticsearch"
},
"path": {
"logs": "/usr/share/elasticsearch/logs",
"home": "/usr/share/elasticsearch"
},
"config": {
"ignore_system_properties": "true"
},
"network": {
"host": "0.0.0.0"
}
},
"os": {
"refresh_interval_in_millis": 1000,
"name": "Linux",
"arch": "amd64",
"version": "5.10.102.1-microsoft-standard-WSL2",
"available_processors": 8,
"allocated_processors": 8
},
"process": {
"refresh_interval_in_millis": 1000,
"id": 1,
"mlockall": false
},
"jvm": {
"pid": 1,
"version": "1.8.0_66-internal",
"vm_name": "OpenJDK 64-Bit Server VM",
"vm_version": "25.66-b17",
"vm_vendor": "Oracle Corporation",
"start_time_in_millis": 1678878835905,
"mem": {
"heap_init_in_bytes": 268435456,
"heap_max_in_bytes": 1037959168,
"non_heap_init_in_bytes": 2555904,
"non_heap_max_in_bytes": 0,
"direct_max_in_bytes": 1037959168
},
"gc_collectors": [
"ParNew"
,
"ConcurrentMarkSweep"
],
"memory_pools": [
"Code Cache"
,
"Metaspace"
,
"Compressed Class Space"
,
"Par Eden Space"
,
"Par Survivor Space"
,
"CMS Old Gen"
]
},
"thread_pool": {
"force_merge": {
"type": "fixed",
"min": 1,
"max": 1,
"queue_size": -1
},
"percolate": {
"type": "fixed",
"min": 8,
"max": 8,
"queue_size": 1000
},
"fetch_shard_started": {
"type": "scaling",
"min": 1,
"max": 16,
"keep_alive": "5m",
"queue_size": -1
},
"listener": {
"type": "fixed",
"min": 4,
"max": 4,
"queue_size": -1
},
"index": {
"type": "fixed",
"min": 8,
"max": 8,
"queue_size": 200
},
"refresh": {
"type": "scaling",
"min": 1,
"max": 4,
"keep_alive": "5m",
"queue_size": -1
},
"suggest": {
"type": "fixed",
"min": 8,
"max": 8,
"queue_size": 1000
},
"generic": {
"type": "cached",
"keep_alive": "30s",
"queue_size": -1
},
"warmer": {
"type": "scaling",
"min": 1,
"max": 4,
"keep_alive": "5m",
"queue_size": -1
},
"search": {
"type": "fixed",
"min": 13,
"max": 13,
"queue_size": 1000
},
"flush": {
"type": "scaling",
"min": 1,
"max": 4,
"keep_alive": "5m",
"queue_size": -1
},
"fetch_shard_store": {
"type": "scaling",
"min": 1,
"max": 16,
"keep_alive": "5m",
"queue_size": -1
},
"management": {
"type": "scaling",
"min": 1,
"max": 5,
"keep_alive": "5m",
"queue_size": -1
},
"get": {
"type": "fixed",
"min": 8,
"max": 8,
"queue_size": 1000
},
"bulk": {
"type": "fixed",
"min": 8,
"max": 8,
"queue_size": 50
},
"snapshot": {
"type": "scaling",
"min": 1,
"max": 4,
"keep_alive": "5m",
"queue_size": -1
}
},
"transport": {
"bound_address": [
"0.0.0.0:9300"
],
"publish_address": "172.18.0.5:9300",
"profiles": { }
},
"http": {
"bound_address": [
"0.0.0.0:9200"
],
"publish_address": "172.18.0.5:9200",
"max_content_length_in_bytes": 104857600
},
"plugins": [
{
"name": "head",
"version": "master",
"description": "head - A web front end for an elastic search cluster",
"url": "/_plugin/head/",
"jvm": false,
"site": true
}
]
}

我将感谢任何帮助解决这个问题。
向你问好兰多。

qxsslcnc

qxsslcnc1#

我设法通过修改x-service应用程序ElasticSearch连接设置client.transport.sniff来绕过这个问题。它被设置为true,当它被更改为false时,我设法让x-service连接到ElasticSearch并成功启动。尽管如此,我不认为这是一个解决方案,因为理论上它应该在不需要这些更改的情况下工作,因为我已经暴露了9200,9300个端口的ElasticSearch。

相关问题