Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java MasterNotDiscoveryException-使用NodeClient连接到在具有动态ip的机器上运行的elasticsearch_Java_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Java,elasticsearch" /> elasticsearch,Java,elasticsearch" />

Java MasterNotDiscoveryException-使用NodeClient连接到在具有动态ip的机器上运行的elasticsearch

Java MasterNotDiscoveryException-使用NodeClient连接到在具有动态ip的机器上运行的elasticsearch,java,elasticsearch,Java,elasticsearch,我使用的环境是,机器上不允许使用sudo命令 (1)elasticsearch 1.2.2节点在10.0.3.182(动态ip)上运行,具有默认群集名称、数据和传输端口 [2015-01-12 22:40:06,158][INFO ][node ] [Namora] initializing ... [2015-01-12 22:40:06,162][INFO ][plugins ] [Namora] loaded [],

我使用的环境是,机器上不允许使用
sudo
命令

(1)
elasticsearch 1.2.2
节点在
10.0.3.182
(动态ip)上运行,具有默认群集名称、数据和传输端口

[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
}
curl -XGET "10.0.3.182:9202/_stats?pretty=true" 
curl: (7) Failed to connect to localhost port 9202: Connection refused
(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)现在我想连接到elasticsearch
1.3.2
名为
shaharma
的集群,如下所示

@Override
public Client getObject() throws Exception {
    this.client = nodeBuilder()
            .clusterName("shaharma")
            .client(true)
            .build()
            .start()
            .client();

    return client;
}
但是,从应用程序中找不到上面已经运行的
clusterName
shaharma
,而是从
9202
9302
开始

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: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
}
curl -XGET "10.0.3.182:9202/_stats?pretty=true" 
curl: (7) Failed to connect to localhost port 9202: Connection refused
由于应用程序无法连接到elasticsearch,它会给出MasterNotDiscovery
org.elasticsearch.discovery.MasterNotDiscoveryException:等待[1m]

localhostip中完全相同的场景运行正常,因为应用程序节点下方的日志检测到已在运行的节点具有相同的
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 NodeClient)的机器中检测已经运行的elasticsearch集群。 工具书类
进行以下更改可以解决此问题,但不确定这是否是最好的解决方案,而不是使用机器的实际ip

(1)
config/elasticsearch.yaml
中更改
network.host

network.host: 127.0.0.1
(2)
节点客户端
显式设置
网络主机

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;
}