Elasticsearch服务器发现配置

我安装了ElasticSearch服务器,我正在运行:

$ ./elasticsearch -f {0.18.2}[11698]: initializing ... loaded [], sites [] {0.18.2}[11698]: initialized {0.18.2}[11698]: starting ... bound_address {inet[/0:0:0:0:0:0:0:0:9300]}, publish_address {inet[/192.168.1.106:9300]} new_master [Stingray][ocw4qPdmSfWuD9pUxHoN1Q][inet[/192.168.1.106:9300]], reason: zen-disco-join (elected_as_master) elasticsearch/ocw4qPdmSfWuD9pUxHoN1Q recovered [0] indices into cluster_state bound_address {inet[/0:0:0:0:0:0:0:0:9200]}, publish_address {inet[/192.168.1.106:9200]} {0.18.2}[11698]: started 

如何配置Java客户端连接到此服务器? 我刚才:

 node.client=true 

但是,在尝试连接之后我收到了:

 org.elasticsearch.discovery.MasterNotDiscoveredException: at org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$3.onTimeout(TransportMasterNodeOperationAction.java:162) 

如果我将java客户端配置为:

 node.data=false 

我得到以下日志:

 INFO main node:internalInfo:93 - [Stark, Tony] {0.18.2}[13008]: starting ... INFO main transport:internalInfo:93 - [Stark, Tony] bound_address {inet[/0:0:0:0:0:0:0:0:9301]}, publish_address {inet[/192.168.1.106:9301]} INFO elasticsearch[Stark, Tony]clusterService#updateTask-pool-13-thread-1 service:internalInfo:93 - [Stark, Tony] new_master [Stark, Tony][WkNn96hgTkWXRnsR0EOZjA][inet[/192.168.1.106:9301]]{data=false}, reason: zen-disco-join (elected_as_master) 

据我所知,这意味着这个新节点(应该是客户端节点)使自己成为一个新的主节点。 而且我没有记录它已被发现并连接到任何其他节点。

服务器和客户端都在同一台机器上启动。 可以从浏览器访问192.168.1.106:9200。

而且我找不到任何有关发现配置的好文档。 我可以在哪里阅读有关ElasticSearch配置的更多信息? 以及如何配置Java客户端?

面临同样的问题,即节点无法在节点重新启动时选择主节点。

问题在于节点之间的通信。

请在弹性搜索日志中确保节点重启是否显示

  publish_address {127.0.0.1:9200} or publish_address {0.0.0.1:9200} 

这意味着当前节点未将其IP地址发布到其他节点,因此节点将无法识别此节点,即使节点IP可能存在于discovery.zen.ping.unicast.hosts中

解决方案在elasticsearch.yml中进行以下更改。 加

  network.host: _non_loopback:ipv4_ and restart the node. Ensure that the bound address now shows the : and not the localhost. 

这意味着现在您的节点是可发现的。 使其在群集中可被发现的第二步是在所有主节点的单播主机列表中添加节点的IP地址,这样无论何时我们有新的主节点,该节点都可被新主节点发现。

  Add the node IP to the discovery.zen.ping.unicast.hosts list of hosts of all the masters to make it disoverable. A masterpings all the nodes present in the unicast list. 

导致此故障的最可能原因是您的计算机上的防火墙阻止了端口54328上的多播发现流量。客户端和主服务器在初始发现期间都在此端口上进行广播,并且它们不会相互回复。 这就是为什么当你指定node.client = true时,客户端节点(不能是主节点)因MasterNotDiscoveredException而失败,没有数据的节点选择自己作为主节点。

我遇到了同样的问题,通过在配置文件中使用IP号码解决了它。

在/config/elasticsearch.yml中

取消注释并将network.host设置更改为:

 network.host: 127.0.0.1 

您也可以在ifconfig中将其更改为您的计算机IP号。

我遇到过同样的问题。 最后,事实certificate我遇到了防火墙问题,我的防火墙(在Ubuntu上)阻止了ElasticSearch的端口。 我在Ubuntu上使用默认防火墙, ufw

所以,为了打开端口,我在终端上运行了这些命令:

 sudo ufw allow proto tcp to any port 9200:9400 sudo ufw allow proto tcp to any port 54328 

我的集群在9200本地运行,所有客户都在9300+上打开。 所以,我刚为他们打开了9200-9400的范围。 54328用于多播广播。

只是为了完成:我也使用了TransportClient,它可以工作,但是我将我的localhost硬编码到了TransportClient将要处理的地址。 对于生产代码来说不是一件好事:-)

像这样的东西应该工作:

  Settings s = ImmutableSettings.settingsBuilder() .put(this.settings) .build(); TransportClient client = new TransportClient(s); client.addTransportAddress(new InetSocketTransportAddress( "localhost", 9300) ); 

我犯了什么罪,我最初尝试将客户端连接到9200,而不是9300.上面的设置指南可以在http://www.elasticsearch.org/guide/reference/java-api/client.html找到。

将网络主机配置为localhost:

network.host:127.0.0.1