ES啟動報錯None of the configured nodes are available
阿新 • • 發佈:2018-12-21
elasticsearch.yml配置
cluster.name: fans node.name: node-72 node.master: true node.data: true network.host: 172.22.245.212 http.port: 39200 transport.tcp.port: 39300 discovery.zen.ping.unicast.hosts: ["127.0.0.1"] discovery.zen.ping.unicast.hosts.resolve_timeout: 30s #index.codec: best_compression http.cors.allow-origin: "/.*/" http.cors.enabled: true path.repo: ["/home/zyzx_test/esdata/backups"]
Java客戶端配置
import com.mochasoft.latte.commons.log.BaseLogger; import com.mochasoft.latte.data.elasticsearch.core.ElasticsearchTemplate; import java.net.InetAddress; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.Settings;import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.transport.client.PreBuiltTransportClient; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration; @Configuration public class ElasticsearchConfiguration extends BaseLogger { private static TransportClient transport = null; @Value("${elasticsearch.cluster.sniff:true}") private Boolean sniff; @Value("${elasticsearch.cluster.name:elasticsearch}") private String clusterName; @Value("${elasticsearch.cluster.hostname:localhost}") private String hostname; @Value("${elasticsearch.cluster.port:9300}") private int port; public ElasticsearchConfiguration() { } @Bean( name = {"elasticsearchTemplate"} ) public ElasticsearchTemplate elasticsearchTemplate() { return new ElasticsearchTemplate(this.client()); } @Bean public Client client() { if (transport == null) { Settings settings = Settings.builder().put("client.transport.sniff", this.sniff).put("cluster.name", this.clusterName).build(); this.logger.info("connection elasticserch info : hostname:{}, port: {}", this.hostname, this.port); transport = new PreBuiltTransportClient(settings, new Class[0]); String[] hostnames = this.hostname.split(","); try { for(int i = 0; i < hostnames.length; ++i) { this.logger.info("連結es=======>:{}", hostnames[i]); TransportAddress transportAddress = new InetSocketTransportAddress(InetAddress.getByName(hostnames[i]), this.port); transport.addTransportAddresses(new TransportAddress[]{transportAddress}); } return transport; } catch (Exception var5) { this.logger.error("", var5); return null; } } else { return null; } } }
ES客戶端屬性配置
<profile> <id>test-HA</id> <properties> <!--系統配置--> <server.bind.host>0.0.0.0</server.bind.host> <server.bind.port>30030</server.bind.port> <!--elasticsearch配置--> <elasticsearch.cluster.name>fans</elasticsearch.cluster.name> <elasticsearch.cluster.hostname>172.22.245.212</elasticsearch.cluster.hostname> <elasticsearch.cluster.port>39200</elasticsearch.cluster.port> </profile>
問題追蹤
在異常棧中定位到 org.elasticsearch.client.transport.TransportClientNodesService#ensureNodesAreAvailable
繼續找到 org.elasticsearch.client.transport.TransportClientNodesService#execute
this.nodes變數的新增邏輯是在 org.elasticsearch.client.transport.TransportClientNodesService$SimpleNodeSampler#doSample
this.nodes變數儲存了可用的ES連線節點資訊,從上圖可以看出,ReceiveTimeoutTransportException。很明顯,連線超時了。
直接訪問es ip+埠可以獲得如下資訊。
按理配置是沒有問題的。後來突然意識到 “transport” 這個關鍵字,然後發覺埠配置錯誤了。