日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Springboot集成ES启动报错

發布時間:2025/3/8 javascript 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Springboot集成ES启动报错 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

報錯內容

  None of the configured nodes are available

elasticsearch.yml配置

cluster.name: ftest node.name: node-72 node.master: true node.data: true network.host: 112.122.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/xxx/backups"]

?

Java客戶端配置

import com.xxx.commons.log.BaseLogger; import com.xxx.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());}@Beanpublic 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>112.122.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” 這個關鍵字,然后發覺端口配置錯誤了。

總結一下es連接異常原因

?1、es服務端沒有啟動 ? ? 2、cluster.name?不匹配 ? ? 3、端口寫錯,java客戶端要配置?transport.tcp.port: 39300。 以上3條逐個排查,多半問題就解決了。

轉載于:https://www.cnblogs.com/hujunzheng/p/9948243.html

總結

以上是生活随笔為你收集整理的Springboot集成ES启动报错的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。