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客户端?

这个失败最有可能的原因是您机器上的防火墙阻止了端口54328上的多播发现流量。在初始发现期间,客户端和主端都在这个端口上广播,它们没有收到对方的反馈。这就是为什么当你指定节点时。client=true客户端节点(不能是主节点)出现MasterNotDiscoveredException错误,没有数据的节点选择自己为主节点

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

在/config/elasticsearch.yml

取消注释并更改网络。主机设置为:

network.host: 127.0.0.1

您也可以在ifconfig中将此更改为您的机器IP号码。

我也有同样的问题。最后,我发现我的防火墙出了问题,我的防火墙(在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,它可以工作,但是我将我的本地主机硬编码到TransportClient将工作的地址。对于生产代码来说不是一件好事:-)

面临同样的问题,节点在重启时无法选择一个主节点

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

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

  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 <IP address>:<port no> 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.

应该这样做:

        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:

网络。主持人:127.0.0.1

相关内容

最新更新