elasticsearch,docker,Java,elasticsearch,Docker" /> elasticsearch,docker,Java,elasticsearch,Docker" />

Java 无法连接到docker中的elasticsearch容器

Java 无法连接到docker中的elasticsearch容器,java,elasticsearch,docker,Java,elasticsearch,Docker,我试图使用docker的官方elasticsearch映像,我遵循了这一点,但当我尝试连接到elasticsearch群集时,出现了异常NoNodeAvailableException[没有配置的节点可用 我的代码 TransportClient client = new PreBuiltTransportClient(Settings.builder().put("cluster.name", "docker-cluster") .build())

我试图使用docker的官方elasticsearch映像,我遵循了这一点,但当我尝试连接到elasticsearch群集时,出现了异常
NoNodeAvailableException[没有配置的节点可用

我的代码

TransportClient client = new PreBuiltTransportClient(Settings.builder().put("cluster.name", "docker-cluster")
                .build())
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
为了运行elasticsearch容器,我使用了以下命令

docker run -p 9200:9200 -p 9300:9300 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" docker.elastic.co/elasticsearch/elasticsearch:5.2.2
当我在
localhost:9200
上打开浏览器时,浏览器会显示此文本

{
  "name" : "J5oojcO",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "SfkgAJmaT_Sb3erfYUl7sQ",
  "version" : {
    "number" : "5.2.2",
    "build_hash" : "f9d9b74",
    "build_date" : "2017-02-24T17:26:45.835Z",
    "build_snapshot" : false,
    "lucene_version" : "6.4.1"
  },
  "tagline" : "You Know, for Search"
}
码头工人日志

[2017-03-28T23:57:47,804][INFO ][o.e.n.Node               ] [] initializing ...
[2017-03-28T23:57:48,214][INFO ][o.e.e.NodeEnvironment    ] [S5IAW08] using [1] data paths, mounts [[/ (overlay)]], net usable_space [54.8gb], net total_space [62.7gb], spins? [possibly], types [overlay]
[2017-03-28T23:57:48,216][INFO ][o.e.e.NodeEnvironment    ] [S5IAW08] heap size [1.9gb], compressed ordinary object pointers [true]
[2017-03-28T23:57:48,224][INFO ][o.e.n.Node               ] node name [S5IAW08] derived from node ID [S5IAW08lQvupW8s_e8btAQ]; set [node.name] to override
[2017-03-28T23:57:48,233][INFO ][o.e.n.Node               ] version[5.2.2], pid[1], build[f9d9b74/2017-02-24T17:26:45.835Z], OS[Linux/4.9.12-moby/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_92-internal/25.92-b14]
[2017-03-28T23:57:52,719][INFO ][o.e.p.PluginsService     ] [S5IAW08] loaded module [aggs-matrix-stats]
[2017-03-28T23:57:52,719][INFO ][o.e.p.PluginsService     ] [S5IAW08] loaded module [ingest-common]
[2017-03-28T23:57:52,720][INFO ][o.e.p.PluginsService     ] [S5IAW08] loaded module [lang-expression]
[2017-03-28T23:57:52,721][INFO ][o.e.p.PluginsService     ] [S5IAW08] loaded module [lang-groovy]
[2017-03-28T23:57:52,721][INFO ][o.e.p.PluginsService     ] [S5IAW08] loaded module [lang-mustache]
[2017-03-28T23:57:52,722][INFO ][o.e.p.PluginsService     ] [S5IAW08] loaded module [lang-painless]
[2017-03-28T23:57:52,722][INFO ][o.e.p.PluginsService     ] [S5IAW08] loaded module [percolator]
[2017-03-28T23:57:52,723][INFO ][o.e.p.PluginsService     ] [S5IAW08] loaded module [reindex]
[2017-03-28T23:57:52,723][INFO ][o.e.p.PluginsService     ] [S5IAW08] loaded module [transport-netty3]
[2017-03-28T23:57:52,724][INFO ][o.e.p.PluginsService     ] [S5IAW08] loaded module [transport-netty4]
[2017-03-28T23:57:52,727][INFO ][o.e.p.PluginsService     ] [S5IAW08] loaded plugin [x-pack]
[2017-03-28T23:57:54,117][WARN ][o.e.d.s.g.GroovyScriptEngineService] [groovy] scripts are deprecated, use [painless] scripts instead
[2017-03-28T23:58:00,388][INFO ][o.e.n.Node               ] initialized
[2017-03-28T23:58:00,389][INFO ][o.e.n.Node               ] [S5IAW08] starting ...
[2017-03-28T23:58:00,920][WARN ][i.n.u.i.MacAddressUtil   ] Failed to find a usable hardware address from the network interfaces; using random bytes: 53:a4:67:2d:77:c8:57:b6
[2017-03-28T23:58:01,073][INFO ][o.e.t.TransportService   ] [S5IAW08] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300}
[2017-03-28T23:58:04,224][INFO ][o.e.c.s.ClusterService   ] [S5IAW08] new_master {S5IAW08}{S5IAW08lQvupW8s_e8btAQ}{4xwcEYRxTmi7-bRwYXHbYA}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2017-03-28T23:58:04,293][INFO ][o.e.h.HttpServer         ] [S5IAW08] publish_address {172.17.0.2:9200}, bound_addresses {[::]:9200}
[2017-03-28T23:58:04,295][INFO ][o.e.n.Node               ] [S5IAW08] started
[2017-03-28T23:58:04,444][INFO ][o.e.g.GatewayService     ] [S5IAW08] recovered [0] indices into cluster_state
[2017-03-28T23:58:05,622][INFO ][o.e.l.LicenseService     ] [S5IAW08] license [c0268fbc-15ce-418c-aacc-5b9d7c3cbaf7] mode [trial] - valid
[2017-03-28T23:58:10,747][INFO ][o.e.c.m.MetaDataCreateIndexService] [S5IAW08] [.monitoring-data-2] creating index, cause [auto(bulk api)], templates [.monitoring-data-2], shards [1]/[1], mappings [node, _default_, logstash, cluster_info, kibana]
[2017-03-28T23:58:11,017][INFO ][o.e.c.m.MetaDataCreateIndexService] [S5IAW08] [.monitoring-es-2-2017.03.28] creating index, cause [auto(bulk api)], templates [.monitoring-es-2], shards [1]/[1], mappings [shards, _default_, node, index_stats, index_recovery, cluster_state, cluster_stats, indices_stats, node_stats]
[2017-03-28T23:58:11,598][INFO ][o.e.c.m.MetaDataMappingService] [S5IAW08] [.monitoring-es-2-2017.03.28/KmXIrx3-R-G_ngo8rfIcZA] update_mapping [cluster_stats]
[2017-03-28T23:58:11,852][INFO ][o.e.c.m.MetaDataMappingService] [S5IAW08] [.monitoring-es-2-2017.03.28/KmXIrx3-R-G_ngo8rfIcZA] update_mapping [node_stats]
[2017-03-28T23:58:22,105][INFO ][o.e.c.m.MetaDataMappingService] [S5IAW08] [.monitoring-es-2-2017.03.28/KmXIrx3-R-G_ngo8rfIcZA] update_mapping [cluster_stats]
[2017-03-28T23:58:22,192][INFO ][o.e.c.m.MetaDataMappingService] [S5IAW08] [.monitoring-es-2-2017.03.28/KmXIrx3-R-G_ngo8rfIcZA] update_mapping [indices_stats]
[2017-03-28T23:58:22,264][INFO ][o.e.c.m.MetaDataMappingService] [S5IAW08] [.monitoring-es-2-2017.03.28/KmXIrx3-R-G_ngo8rfIcZA] update_mapping [index_stats]
[2017-03-28T23:58:44,237][INFO ][o.e.m.j.JvmGcMonitorService] [S5IAW08] [gc][43] overhead, spent [668ms] collecting in the last [1.5s]
[2017-03-28T23:59:14,284][INFO ][o.e.m.j.JvmGcMonitorService] [S5IAW08] [gc][73] overhead, spent [306ms] collecting in the last [1s]
[2017-03-29T00:00:03,456][INFO ][o.e.c.m.MetaDataCreateIndexService] [S5IAW08] [.monitoring-es-2-2017.03.29] creating index, cause [auto(bulk api)], templates [.monitoring-es-2], shards [1]/[1], mappings [shards, _default_, node, index_stats, index_recovery, cluster_state, cluster_stats, indices_stats, node_stats]
[2017-03-29T00:00:03,685][INFO ][o.e.c.m.MetaDataMappingService] [S5IAW08] [.monitoring-es-2-2017.03.29/FulovogFThmVCpL0RS99Hg] update_mapping [cluster_stats]
[2017-03-29T00:00:03,774][INFO ][o.e.c.m.MetaDataMappingService] [S5IAW08] [.monitoring-es-2-2017.03.29/FulovogFThmVCpL0RS99Hg] update_mapping [node_stats]
[2017-03-29T00:00:03,856][INFO ][o.e.c.m.MetaDataMappingService] [S5IAW08] [.monitoring-es-2-2017.03.29/FulovogFThmVCpL0RS99Hg] update_mapping [indices_stats]
[2017-03-29T00:00:03,909][INFO ][o.e.c.m.MetaDataMappingService] [S5IAW08] [.monitoring-es-2-2017.03.29/FulovogFThmVCpL0RS99Hg] update_mapping [index_stats]
健康链接

1490745899 00:04:59 docker-cluster yellow 1 1 3 3 0 0 3 0 - 50.0%
提前谢谢

更新

官方指南说图像是用X-Pack构建的,所以我尝试禁用xpack安全性,并使用
127.0.0.1:9300


谢谢。

我不知道为什么文档会指示这样做,但是当您通过
127.0.0.1
作为传输主机时,绑定仅针对该地址,因此无法在容器外部访问


尝试将
transport.host
也定义为
0.0.0
,这样它也会绑定到容器IP。

我不知道为什么文档会指示这样做,但是当您将
127.0.0.1
传递为传输主机时,绑定只会绑定到该地址,因此无法在容器外部访问


尝试将
transport.host
也定义为
0.0.0
,这样它也会绑定到容器IP。

容器日志如何,是否有出现问题的迹象?另外,尝试healthcheck URL:
http://localhost:9200/_cat/health
我更新了我的问题@Toresan容器日志如何,是否有任何提示出现问题时,请尝试healthcheck URL:
http://localhost:9200/_cat/health
我更新了我的问题@ToRestant这很关键;谢谢。此外,我发现,当您执行此操作时,还必须确保在
传输客户端中
客户端.transport.sniff
设置设置为
false
ode>或原始错误将出现。据我所知,这在任何地方都没有记录。这很重要;谢谢。此外,我发现,当您执行此操作时,还必须确保在
TransportClient
中将
client.transport.sniff
设置设置为
false
,否则将出现原始错误。这据我所知,任何地方都没有记录。