无法连接到我的 Elasticsearch 实例:NoNodeAvailableException
Can't connect to my Elasticsearch instance: NoNodeAvailableException
无法连接到我的 Elasticsearch 开始于:
docker-compose up
运行 命令:
curl -XGET http://localhost:9200/_nodes/http?pretty
输出:
{
"cluster_name" : "elasticsearch",
"nodes" : {
"qD18rHzhQaexExUw5sBgXg" : {
"name" : "Scanner",
"transport_address" : "172.19.0.3:9300",
"host" : "172.19.0.3",
"ip" : "172.19.0.3",
"version" : "6.2.3",
"build" : "fcbb46d",
"http_address" : "172.19.0.3:9200",
"http" : {
"bound_address" : [ "0.0.0.0:9200" ],
"publish_address" : "172.19.0.3:9200",
"max_content_length_in_bytes" : 104857600
}
}
}
}
连接传输客户端:
public Client client() throws Exception {
Settings settings = Settings.builder()
.put("spring.data.elasticsearch.cluster-nodes", "localhost:9300")
.build();
TransportClient client = TransportClient.builder()
.settings(settings)
.build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
return client;
}
获取错误:
Caused by: NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{localhost}{127.0.0.1:9300}]]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:326)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:223)
docker-compose.yml
services:
elasticsearch:
image: elasticsearch
ports:
- '9200:9200'
- '9300:9300'
kibana:
image: kibana
ports:
- '5601:5601'
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
Docker文件
FROM elasticsearch, kibana
EXPOSE 9200
EXPOSE 9300
(运行 本地安装的 Elasticsearch 没有 Docker 它可以工作!)
我做错了什么?知道如何解决吗?
传输端点绑定在 elasticsearch
容器内的本地主机上。这就是为什么它只能从容器本身访问的原因。
传输端点应绑定到 elasticsearch
容器中的 0.0.0.0
("transport_address" : "0.0.0.0:9300"
),并且可以通过 localhost:9300
在主机上通过本地主机访问它.
因此,您可以通过以下 docker-compose.yaml
:
实现
version: "3"
services:
elasticsearch:
image: elasticsearch
command: "-Etransport.host=0.0.0.0"
ports:
- '9200:9200'
- '9300:9300'
kibana:
image: kibana
ports:
- '5601:5601'
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
更新:
如果你只是使用上面的 docker-compose.yaml
,elasticsearch
容器在启动时失败并出现以下错误:
elasticsearch_1 | [2018-03-26T07:44:13,475][INFO ][o.e.n.Node ] [rzYPgrJ] starting ...
elasticsearch_1 | [2018-03-26T07:44:13,663][INFO ][o.e.t.TransportService ] [rzYPgrJ] publish_address {172.17.0.2:9300}, bound_addresses {0.0.0.0:9300}
elasticsearch_1 | [2018-03-26T07:44:13,688][INFO ][o.e.b.BootstrapChecks ] [rzYPgrJ] bound or publishing to a non-loopback address, enforcing bootstrap checks
elasticsearch_1 | ERROR: [1] bootstrap checks failed
elasticsearch_1 | [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
elasticsearch_1 | [2018-03-26T07:44:13,696][INFO ][o.e.n.Node ] [rzYPgrJ] stopping ...
elasticsearch_1 | [2018-03-26T07:44:13,747][INFO ][o.e.n.Node ] [rzYPgrJ] stopped
elasticsearch_1 | [2018-03-26T07:44:13,747][INFO ][o.e.n.Node ] [rzYPgrJ] closing ...
elasticsearch_1 | [2018-03-26T07:44:13,762][INFO ][o.e.n.Node ] [rzYPgrJ] closed
那是因为我们更改了 transport endpoint
在 0.0.0.0
上收听。
为了修复它,有必要在主机上增加 vm.max_map_count
sysctl 参数,至少达到 262144
:
sudo sysctl -w vm.max_map_count=262144
现在您可以通过docker-compose up
成功启动两个容器。
当降级到 elasticsearch:2.4.4 时它可以工作,我怀疑这与 SpringData 不兼容最新的 Elasticsearch 有关。
...
services:
elasticsearch:
image: elasticsearch:2.4.4
ports:
- '9200:9200'
- '9300:9300'
kibana:
image: kibana:4.6.1
...
图表:
https://github.com/spring-projects/spring-data-elasticsearch
无法连接到我的 Elasticsearch 开始于:
docker-compose up
运行 命令:
curl -XGET http://localhost:9200/_nodes/http?pretty
输出:
{
"cluster_name" : "elasticsearch",
"nodes" : {
"qD18rHzhQaexExUw5sBgXg" : {
"name" : "Scanner",
"transport_address" : "172.19.0.3:9300",
"host" : "172.19.0.3",
"ip" : "172.19.0.3",
"version" : "6.2.3",
"build" : "fcbb46d",
"http_address" : "172.19.0.3:9200",
"http" : {
"bound_address" : [ "0.0.0.0:9200" ],
"publish_address" : "172.19.0.3:9200",
"max_content_length_in_bytes" : 104857600
}
}
}
}
连接传输客户端:
public Client client() throws Exception {
Settings settings = Settings.builder()
.put("spring.data.elasticsearch.cluster-nodes", "localhost:9300")
.build();
TransportClient client = TransportClient.builder()
.settings(settings)
.build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
return client;
}
获取错误:
Caused by: NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{localhost}{127.0.0.1:9300}]]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:326)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:223)
docker-compose.yml
services:
elasticsearch:
image: elasticsearch
ports:
- '9200:9200'
- '9300:9300'
kibana:
image: kibana
ports:
- '5601:5601'
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
Docker文件
FROM elasticsearch, kibana
EXPOSE 9200
EXPOSE 9300
(运行 本地安装的 Elasticsearch 没有 Docker 它可以工作!)
我做错了什么?知道如何解决吗?
传输端点绑定在 elasticsearch
容器内的本地主机上。这就是为什么它只能从容器本身访问的原因。
传输端点应绑定到 elasticsearch
容器中的 0.0.0.0
("transport_address" : "0.0.0.0:9300"
),并且可以通过 localhost:9300
在主机上通过本地主机访问它.
因此,您可以通过以下 docker-compose.yaml
:
version: "3"
services:
elasticsearch:
image: elasticsearch
command: "-Etransport.host=0.0.0.0"
ports:
- '9200:9200'
- '9300:9300'
kibana:
image: kibana
ports:
- '5601:5601'
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
更新:
如果你只是使用上面的 docker-compose.yaml
,elasticsearch
容器在启动时失败并出现以下错误:
elasticsearch_1 | [2018-03-26T07:44:13,475][INFO ][o.e.n.Node ] [rzYPgrJ] starting ...
elasticsearch_1 | [2018-03-26T07:44:13,663][INFO ][o.e.t.TransportService ] [rzYPgrJ] publish_address {172.17.0.2:9300}, bound_addresses {0.0.0.0:9300}
elasticsearch_1 | [2018-03-26T07:44:13,688][INFO ][o.e.b.BootstrapChecks ] [rzYPgrJ] bound or publishing to a non-loopback address, enforcing bootstrap checks
elasticsearch_1 | ERROR: [1] bootstrap checks failed
elasticsearch_1 | [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
elasticsearch_1 | [2018-03-26T07:44:13,696][INFO ][o.e.n.Node ] [rzYPgrJ] stopping ...
elasticsearch_1 | [2018-03-26T07:44:13,747][INFO ][o.e.n.Node ] [rzYPgrJ] stopped
elasticsearch_1 | [2018-03-26T07:44:13,747][INFO ][o.e.n.Node ] [rzYPgrJ] closing ...
elasticsearch_1 | [2018-03-26T07:44:13,762][INFO ][o.e.n.Node ] [rzYPgrJ] closed
那是因为我们更改了 transport endpoint
在 0.0.0.0
上收听。
为了修复它,有必要在主机上增加 vm.max_map_count
sysctl 参数,至少达到 262144
:
sudo sysctl -w vm.max_map_count=262144
现在您可以通过docker-compose up
成功启动两个容器。
当降级到 elasticsearch:2.4.4 时它可以工作,我怀疑这与 SpringData 不兼容最新的 Elasticsearch 有关。
...
services:
elasticsearch:
image: elasticsearch:2.4.4
ports:
- '9200:9200'
- '9300:9300'
kibana:
image: kibana:4.6.1
...
图表:
https://github.com/spring-projects/spring-data-elasticsearch