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()); } @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>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条逐个排查,多半问题就解决了。
本文来自博客园,作者:hjzqyx,转载请注明原文链接:https://www.cnblogs.com/hujunzheng/p/9948243.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端
2014-11-12 Codeforces Round #277(Div. 2) (A Calculating Function, B OR in Matrix, C Palindrome Transformation)