2016-07-05 99 views
0

我有一個3 ES節點集羣。所有這些都是數據和主節點。在我的api(JAVA)中,我使用傳輸通信。我使用xxx.yy.zz.aaa IP地址來訪問/查詢ES索引。但我只是想知道,如果那個xxx.yy.zz.aaa機器關閉,那麼我必須重新配置API以指向集羣中可用的任何一臺機器。但有沒有辦法來沒有負載均衡器的ES集羣節點

  1. 如何自動檢測節點故障和點查詢到其他節點?
  2. 如何避免這種單點故障。

回答

0

您應該將所有3個IP地址添加到您的客戶端,以便在發生一個節點故障時連接到其他節點。您的連接器可能如下所示:

Settings.Builder settings = Settings.settingsBuilder(); 
     settings.put("cluster.name", "elasticsearchcluster"); 
     List<String> hosts = new LinkedList<String>(); 
     ArrayList<ElasticSearchHost> esHosts = elasticSearchConfig.esHostsConfig.esHosts; 
     for (ElasticSearchHost host : esHosts) { 
      hosts.add(host.host + ":" + host.port); 
     } 
     settings.put("discovery.zen.ping.multicast.enabled", "false"); 
     settings.put("discovery.zen.ping.unicast.hosts", StringUtils.join(hosts, ",")); 
     //settings.put("discovery.zen.ping.unicast.hosts","xxx.yy.zz.aaa:9300, xxx.yy.zz.bbb:9300, xxx.yy.zz.ccc:9300"); 
     client = TransportClient.builder().settings(settings).build(); 
     for (ElasticSearchHost host : esHosts) { 
      ((TransportClient) client).addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress(host.host, host.port))); 

     } 
     ClusterHealthResponse clusterHealth = client.admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();