MasterNotDiscoveredException - 使用 NodeClient 连接到具有动态 ip 的机器上的 elasticsearch 运行
MasterNotDiscoveredException - connecting to elasticsearch running on machine with dyanamic ip using NodeClient
我使用的环境是codeship,其中不允许sudo
机器上的命令,
(1) elasticsearch 1.2.2
节点是 运行 在 10.0.3.182
(这是动态 ip),默认为 cluster_name,数据和传输端口。
[2015-01-12 22:40:06,158][INFO ][node ] [Namora] initializing ...
[2015-01-12 22:40:06,162][INFO ][plugins ] [Namora] loaded [], sites []
[2015-01-12 22:40:08,332][INFO ][node ] [Namora] initialized
[2015-01-12 22:40:08,332][INFO ][node ] [Namora] starting ...
[2015-01-12 22:40:08,527][INFO ][transport ] [Namora] bound_address {inet[/0:0:0:0:0:0:0:0:9300]}, publish_address {inet[/10.0.3.182:9300]}
[2015-01-12 22:40:11,556][INFO ][cluster.service ] [Namora] new_master [Namora][ay0dhdU2QuSOgLz4dbuu6A][railsonfire_92c081a0-7cd5-0132-88b9-26d15d8e303d_c71873e6021a][inet[/10.0.3.182:9300]], reason: zen-disco-join (elected_as_master)
[2015-01-12 22:40:11,583][INFO ][discovery ] [Namora] elasticsearch/ay0dhdU2QuSOgLz4dbuu6A
[2015-01-12 22:40:11,622][INFO ][http ] [Namora] bound_address {inet[/0:0:0:0:0:0:0:0:9200]}, publish_address {inet[/10.0.3.182:9200]}
[2015-01-12 22:40:11,624][INFO ][gateway ] [Namora] recovered [0] indices into cluster_state
[2015-01-12 22:40:11,624][INFO ][node ] [Namora] started
集群信息为,
$ curl -XGET "10.0.3.182:9200/_cluster/health?pretty=true"
{
"cluster_name" : "elasticsearch",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0
}
(2) elasticsearch 1.3.2
在同一台机器上是运行(10.0.3.182
),数据端口9201
和9301
,配置如下,
################################### Cluster ###################################
# Cluster name identifies your cluster for auto-discovery. If you're running
# multiple clusters on the same network, make sure you're using unique names.
#
cluster.name: shaharma
# Set a custom port for the node to node communication (9300 by default):
#
transport.tcp.port: 9301
# Enable compression for all communication between nodes (disabled by default):
#
#transport.tcp.compress: true
# Set a custom port to listen for HTTP traffic:
#
http.port: 9201
es 日志是
[2015-01-12 23:27:36,466][INFO ][node ] [Sunstreak] version[1.3.2], pid[47523], build[dee175d/2014-08-13T14:29:30Z]
[2015-01-12 23:27:36,467][INFO ][node ] [Sunstreak] initializing ...
[2015-01-12 23:27:36,471][INFO ][plugins ] [Sunstreak] loaded [], sites []
[2015-01-12 23:27:38,667][INFO ][node ] [Sunstreak] initialized
[2015-01-12 23:27:38,668][INFO ][node ] [Sunstreak] starting ...
[2015-01-12 23:27:38,796][INFO ][transport ] [Sunstreak] bound_address {inet[/0:0:0:0:0:0:0:0:9301]}, publish_address {inet[/10.0.3.182:9301]}
[2015-01-12 23:27:38,813][INFO ][discovery ] [Sunstreak] shaharma/7hPpAvJJTSuzR58rIGHccA
[2015-01-12 23:27:41,823][INFO ][cluster.service ] [Sunstreak] new_master [Sunstreak][7hPpAvJJTSuzR58rIGHccA][railsonfire_92c081a0-7cd5-0132-88b9-26d15d8e303d_c71873e6021a][inet[/10.0.3.182:9301]], reason: zen-disco-join (elected_as_master)
[2015-01-12 23:27:41,859][INFO ][gateway ] [Sunstreak] recovered [0] indices into cluster_state
[2015-01-12 23:27:41,868][INFO ][http ] [Sunstreak] bound_address {inet[/0:0:0:0:0:0:0:0:9201]}, publish_address {inet[/10.0.3.182:9201]}
[2015-01-12 23:27:41,869][INFO ][node ] [Sunstreak] started
集群信息,
$ curl -XGET "10.0.3.182:9201/_cluster/health?pretty=true"
{
"cluster_name" : "shaharma",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0
}
(3) 现在我想连接到名为 shaharma
的 elasticsearch 1.3.2
集群,NodeClient 如下,
@Override
public Client getObject() throws Exception {
this.client = nodeBuilder()
.clusterName("shaharma")
.client(true)
.build()
.start()
.client();
return client;
}
但是,从应用程序中它已经找不到上面 运行 clusterName
shaharma
,但从 9202
和 9302
.[=38 开始=]
2015-01-12 23:29:07,932 INFO (main) [org.elasticsearch.node] - [Belasco] version[1.3.2], pid[48970], build[dee175d/2014-08-13T14:29:30Z]
2015-01-12 23:29:07,933 INFO (main) [org.elasticsearch.node] - [Belasco] initializing ...
2015-01-12 23:29:07,936 INFO (main) [org.elasticsearch.plugins] - [Belasco] loaded [], sites []
2015-01-12 23:29:09,262 INFO (main) [org.elasticsearch.node] - [Belasco] initialized
2015-01-12 23:29:09,262 INFO (main) [org.elasticsearch.node] - [Belasco] starting ...
2015-01-12 23:29:09,373 INFO (main) [org.elasticsearch.transport] - [Belasco] bound_address {inet[/0:0:0:0:0:0:0:0:9302]}, publish_address {inet[/10.0.3.182:9302]}
2015-01-12 23:29:09,389 INFO (main) [org.elasticsearch.discovery] - [Belasco] shaharma/BXvnMfBwQiSRqrsppuLEhA
2015-01-12 23:29:39,393 WARN (main) [org.elasticsearch.discovery] - [Belasco] waited for 30s and no initial state was set by the discovery
2015-01-12 23:29:39,436 INFO (main) [org.elasticsearch.http] - [Belasco] bound_address {inet[/0:0:0:0:0:0:0:0:9202]}, publish_address {inet[/10.0.3.182:9202]}
2015-01-12 23:29:39,437 INFO (main) [org.elasticsearch.node] - [Belasco] started
集群信息不可用,
curl -XGET "10.0.3.182:9202/_stats?pretty=true"
curl: (7) Failed to connect to localhost port 9202: Connection refused
由于应用程序无法连接到 elasticsearch,它给出了 MasterNotDiscovered org.elasticsearch.discovery.MasterNotDiscoveredException: waited for [1m]
在本地主机 ip 中完全相同的场景工作正常,因为在应用程序节点下方看到的日志检测到已经 运行 具有相同 clusterName
的节点。
2015-01-13 03:15:45,088 INFO (main) [org.elasticsearch.node] - [Electric Eve] version[1.3.2], pid[6262], build[dee175d/2014-08-13T14:29:30Z]
2015-01-13 03:15:45,103 INFO (main) [org.elasticsearch.node] - [Electric Eve] initializing ...
2015-01-13 03:15:45,128 INFO (main) [org.elasticsearch.plugins] - [Electric Eve] loaded [], sites []
2015-01-13 03:15:51,318 INFO (main) [org.elasticsearch.node] - [Electric Eve] initialized
2015-01-13 03:15:51,319 INFO (main) [org.elasticsearch.node] - [Electric Eve] starting ...
2015-01-13 03:15:51,566 INFO (main) [org.elasticsearch.transport] - [Electric Eve] bound_address {inet[/0:0:0:0:0:0:0:0:9302]}, publish_address {inet[/192.168.1.4:9302]}
2015-01-13 03:15:51,669 INFO (main) [org.elasticsearch.discovery] - [Electric Eve] shaharma/EhjQEz6tQ_m-x7_j_cAMUw
2015-01-13 03:15:54,889 INFO (elasticsearch[Electric Eve][clusterService#updateTask][T#1]) [org.elasticsearch.cluster.service] - [Electric Eve] detected_master [Professor X][q0poP21MSHKQcCPgtEWkKA][prayagupd][inet[/192.168.1.4:9301]], added {[Professor X][q0poP21MSHKQcCPgtEWkKA][prayagupd][inet[/192.168.1.4:9301]],}, reason: zen-disco-receive(from master [[Professor X][q0poP21MSHKQcCPgtEWkKA][prayagupd][inet[/192.168.1.4:9301]]])
2015-01-13 03:15:54,919 INFO (main) [org.elasticsearch.http] - [Electric Eve] bound_address {inet[/0:0:0:0:0:0:0:0:9202]}, publish_address {inet[/192.168.1.4:9202]}
2015-01-13 03:15:54,921 INFO (main) [org.elasticsearch.node] - [Electric Eve] started
所以,我的问题是如何使应用程序能够检测到具有动态 ip 的机器中已经 运行 的 elasticsearch 集群(使用 Elasticsearch NodeClient)。
参考资料
Elasticsearch server discovery configuration
进行以下更改可以解决此问题,不确定这是否是最好的解决方案而不是使用机器的实际 ip。
(1) 在 config/elasticsearch.yaml
、
中更改 network.host
network.host: 127.0.0.1
(2) 从 NodeClient
、
明确设置 network.host
public Client getObject() throws Exception {
this.client = nodeBuilder()
.settings(ImmutableSettings.settingsBuilder()
.put("cluster.name", "shaharma")
.put("network.host", "127.0.0.1"))
.client(true)
.build()
.start()
.client();
return client;
}
我使用的环境是codeship,其中不允许sudo
机器上的命令,
(1) elasticsearch 1.2.2
节点是 运行 在 10.0.3.182
(这是动态 ip),默认为 cluster_name,数据和传输端口。
[2015-01-12 22:40:06,158][INFO ][node ] [Namora] initializing ...
[2015-01-12 22:40:06,162][INFO ][plugins ] [Namora] loaded [], sites []
[2015-01-12 22:40:08,332][INFO ][node ] [Namora] initialized
[2015-01-12 22:40:08,332][INFO ][node ] [Namora] starting ...
[2015-01-12 22:40:08,527][INFO ][transport ] [Namora] bound_address {inet[/0:0:0:0:0:0:0:0:9300]}, publish_address {inet[/10.0.3.182:9300]}
[2015-01-12 22:40:11,556][INFO ][cluster.service ] [Namora] new_master [Namora][ay0dhdU2QuSOgLz4dbuu6A][railsonfire_92c081a0-7cd5-0132-88b9-26d15d8e303d_c71873e6021a][inet[/10.0.3.182:9300]], reason: zen-disco-join (elected_as_master)
[2015-01-12 22:40:11,583][INFO ][discovery ] [Namora] elasticsearch/ay0dhdU2QuSOgLz4dbuu6A
[2015-01-12 22:40:11,622][INFO ][http ] [Namora] bound_address {inet[/0:0:0:0:0:0:0:0:9200]}, publish_address {inet[/10.0.3.182:9200]}
[2015-01-12 22:40:11,624][INFO ][gateway ] [Namora] recovered [0] indices into cluster_state
[2015-01-12 22:40:11,624][INFO ][node ] [Namora] started
集群信息为,
$ curl -XGET "10.0.3.182:9200/_cluster/health?pretty=true"
{
"cluster_name" : "elasticsearch",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0
}
(2) elasticsearch 1.3.2
在同一台机器上是运行(10.0.3.182
),数据端口9201
和9301
,配置如下,
################################### Cluster ###################################
# Cluster name identifies your cluster for auto-discovery. If you're running
# multiple clusters on the same network, make sure you're using unique names.
#
cluster.name: shaharma
# Set a custom port for the node to node communication (9300 by default):
#
transport.tcp.port: 9301
# Enable compression for all communication between nodes (disabled by default):
#
#transport.tcp.compress: true
# Set a custom port to listen for HTTP traffic:
#
http.port: 9201
es 日志是
[2015-01-12 23:27:36,466][INFO ][node ] [Sunstreak] version[1.3.2], pid[47523], build[dee175d/2014-08-13T14:29:30Z]
[2015-01-12 23:27:36,467][INFO ][node ] [Sunstreak] initializing ...
[2015-01-12 23:27:36,471][INFO ][plugins ] [Sunstreak] loaded [], sites []
[2015-01-12 23:27:38,667][INFO ][node ] [Sunstreak] initialized
[2015-01-12 23:27:38,668][INFO ][node ] [Sunstreak] starting ...
[2015-01-12 23:27:38,796][INFO ][transport ] [Sunstreak] bound_address {inet[/0:0:0:0:0:0:0:0:9301]}, publish_address {inet[/10.0.3.182:9301]}
[2015-01-12 23:27:38,813][INFO ][discovery ] [Sunstreak] shaharma/7hPpAvJJTSuzR58rIGHccA
[2015-01-12 23:27:41,823][INFO ][cluster.service ] [Sunstreak] new_master [Sunstreak][7hPpAvJJTSuzR58rIGHccA][railsonfire_92c081a0-7cd5-0132-88b9-26d15d8e303d_c71873e6021a][inet[/10.0.3.182:9301]], reason: zen-disco-join (elected_as_master)
[2015-01-12 23:27:41,859][INFO ][gateway ] [Sunstreak] recovered [0] indices into cluster_state
[2015-01-12 23:27:41,868][INFO ][http ] [Sunstreak] bound_address {inet[/0:0:0:0:0:0:0:0:9201]}, publish_address {inet[/10.0.3.182:9201]}
[2015-01-12 23:27:41,869][INFO ][node ] [Sunstreak] started
集群信息,
$ curl -XGET "10.0.3.182:9201/_cluster/health?pretty=true"
{
"cluster_name" : "shaharma",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0
}
(3) 现在我想连接到名为 shaharma
的 elasticsearch 1.3.2
集群,NodeClient 如下,
@Override
public Client getObject() throws Exception {
this.client = nodeBuilder()
.clusterName("shaharma")
.client(true)
.build()
.start()
.client();
return client;
}
但是,从应用程序中它已经找不到上面 运行 clusterName
shaharma
,但从 9202
和 9302
.[=38 开始=]
2015-01-12 23:29:07,932 INFO (main) [org.elasticsearch.node] - [Belasco] version[1.3.2], pid[48970], build[dee175d/2014-08-13T14:29:30Z]
2015-01-12 23:29:07,933 INFO (main) [org.elasticsearch.node] - [Belasco] initializing ...
2015-01-12 23:29:07,936 INFO (main) [org.elasticsearch.plugins] - [Belasco] loaded [], sites []
2015-01-12 23:29:09,262 INFO (main) [org.elasticsearch.node] - [Belasco] initialized
2015-01-12 23:29:09,262 INFO (main) [org.elasticsearch.node] - [Belasco] starting ...
2015-01-12 23:29:09,373 INFO (main) [org.elasticsearch.transport] - [Belasco] bound_address {inet[/0:0:0:0:0:0:0:0:9302]}, publish_address {inet[/10.0.3.182:9302]}
2015-01-12 23:29:09,389 INFO (main) [org.elasticsearch.discovery] - [Belasco] shaharma/BXvnMfBwQiSRqrsppuLEhA
2015-01-12 23:29:39,393 WARN (main) [org.elasticsearch.discovery] - [Belasco] waited for 30s and no initial state was set by the discovery
2015-01-12 23:29:39,436 INFO (main) [org.elasticsearch.http] - [Belasco] bound_address {inet[/0:0:0:0:0:0:0:0:9202]}, publish_address {inet[/10.0.3.182:9202]}
2015-01-12 23:29:39,437 INFO (main) [org.elasticsearch.node] - [Belasco] started
集群信息不可用,
curl -XGET "10.0.3.182:9202/_stats?pretty=true"
curl: (7) Failed to connect to localhost port 9202: Connection refused
由于应用程序无法连接到 elasticsearch,它给出了 MasterNotDiscovered org.elasticsearch.discovery.MasterNotDiscoveredException: waited for [1m]
在本地主机 ip 中完全相同的场景工作正常,因为在应用程序节点下方看到的日志检测到已经 运行 具有相同 clusterName
的节点。
2015-01-13 03:15:45,088 INFO (main) [org.elasticsearch.node] - [Electric Eve] version[1.3.2], pid[6262], build[dee175d/2014-08-13T14:29:30Z]
2015-01-13 03:15:45,103 INFO (main) [org.elasticsearch.node] - [Electric Eve] initializing ...
2015-01-13 03:15:45,128 INFO (main) [org.elasticsearch.plugins] - [Electric Eve] loaded [], sites []
2015-01-13 03:15:51,318 INFO (main) [org.elasticsearch.node] - [Electric Eve] initialized
2015-01-13 03:15:51,319 INFO (main) [org.elasticsearch.node] - [Electric Eve] starting ...
2015-01-13 03:15:51,566 INFO (main) [org.elasticsearch.transport] - [Electric Eve] bound_address {inet[/0:0:0:0:0:0:0:0:9302]}, publish_address {inet[/192.168.1.4:9302]}
2015-01-13 03:15:51,669 INFO (main) [org.elasticsearch.discovery] - [Electric Eve] shaharma/EhjQEz6tQ_m-x7_j_cAMUw
2015-01-13 03:15:54,889 INFO (elasticsearch[Electric Eve][clusterService#updateTask][T#1]) [org.elasticsearch.cluster.service] - [Electric Eve] detected_master [Professor X][q0poP21MSHKQcCPgtEWkKA][prayagupd][inet[/192.168.1.4:9301]], added {[Professor X][q0poP21MSHKQcCPgtEWkKA][prayagupd][inet[/192.168.1.4:9301]],}, reason: zen-disco-receive(from master [[Professor X][q0poP21MSHKQcCPgtEWkKA][prayagupd][inet[/192.168.1.4:9301]]])
2015-01-13 03:15:54,919 INFO (main) [org.elasticsearch.http] - [Electric Eve] bound_address {inet[/0:0:0:0:0:0:0:0:9202]}, publish_address {inet[/192.168.1.4:9202]}
2015-01-13 03:15:54,921 INFO (main) [org.elasticsearch.node] - [Electric Eve] started
所以,我的问题是如何使应用程序能够检测到具有动态 ip 的机器中已经 运行 的 elasticsearch 集群(使用 Elasticsearch NodeClient)。
参考资料
Elasticsearch server discovery configuration
进行以下更改可以解决此问题,不确定这是否是最好的解决方案而不是使用机器的实际 ip。
(1) 在 config/elasticsearch.yaml
、
network.host
network.host: 127.0.0.1
(2) 从 NodeClient
、
network.host
public Client getObject() throws Exception {
this.client = nodeBuilder()
.settings(ImmutableSettings.settingsBuilder()
.put("cluster.name", "shaharma")
.put("network.host", "127.0.0.1"))
.client(true)
.build()
.start()
.client();
return client;
}