溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Elasticsearch中所有配置的節(jié)點(diǎn)都不可用該怎么辦

發(fā)布時(shí)間:2021-09-14 10:26:44 來源:億速云 閱讀:187 作者:柒染 欄目:大數(shù)據(jù)

這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)Elasticsearch中所有配置的節(jié)點(diǎn)都不可用該怎么辦,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

為了Elasticsearch的評(píng)分機(jī)制使用,使用docker快速搭建了elasticsearch;使用spring boot連接ES的時(shí)候報(bào)錯(cuò):無法找到節(jié)點(diǎn)

環(huán)境:
【jdk】:1.8   

【ES】:6.5.4 單節(jié)點(diǎn) (ip:172.26.0.251)

【springboot】:2.1.2

代碼片段:
es的elasticsearch.yml配置:

cluster.name: "docker-cluster"
 network.host: 0.0.0.0
 node.name: cloud
 http.cors.enabled: true
 http.cors.allow-origin: "*"
 node.master: true
 node.data: true


工程的 application.yml

spring.data.elasticsearch.cluster-name = docker-cluster spring.data.elasticsearch.cluster-nodes = 172.26.0.251:9300 spring.data.elasticsearch.repositories.enabled = true spring.data.elasticsearch.client-transport-sniff = true #嗅探設(shè)置 pom.xml 文件中只引入相關(guān)包
        <dependency>             <groupId>org.elasticsearch.client</groupId>             <artifactId>transport</artifactId>         </dependency>         <dependency>             <groupId>org.nlpcn</groupId>             <artifactId>elasticsearch-sql</artifactId>         </dependency> es連接配置類
@Configuration @EnableConfigurationProperties(ElasticsearchProperties.class) @ConditionalOnClass(TransportClient.class) public class ElasticsearchAutoConfiguration {     private final Logger logger = LoggerFactory.getLogger(this.getClass());       private ElasticsearchProperties elasticsearchProperties;       public ElasticsearchAutoConfiguration(ElasticsearchProperties elasticsearchProperties) {         logger.debug("ElasticsearchAutoConfiguration elasticsearchProperties:{}", JSON                 .toJSONString(elasticsearchProperties));         this.elasticsearchProperties = elasticsearchProperties;     }       @Bean(destroyMethod = "close")     public TransportClient client() throws Exception {         TransportClient client = new PreBuiltTransportClient(settings());           String clusterNodes = elasticsearchProperties.getClusterNodes();         Assert.hasText(clusterNodes, "[Assertion failed] clusterNodes settings missing.");           for (String clusterNode : split(clusterNodes, ElasticsearchProperties.COMMA)) {             String hostName = substringBeforeLast(clusterNode, ElasticsearchProperties.COLON);             String port = substringAfterLast(clusterNode, ElasticsearchProperties.COLON);             Assert.hasText(hostName, "[Assertion failed] missing host name in 'clusterNodes'");             Assert.hasText(port, "[Assertion failed] missing port in 'clusterNodes'");             logger.info("adding transport node : " + clusterNode);             client.addTransportAddress(new TransportAddress(InetAddress.getByName                     (hostName), Integer.valueOf(port)));         }         client.connectedNodes();         return client;     }       @Bean     public ElasticClientKit elasticClientKit() throws Exception {         ElasticClientKit elasticClientKit = new ElasticClientKit();         elasticClientKit.setTransportClient(client());           return elasticClientKit;     }       @Bean     public ElasticAdminKit elasticAdminKit() throws Exception {         ElasticAdminKit elasticAdminKit = new ElasticAdminKit();         elasticAdminKit.setTransportClient(client());           return elasticAdminKit;     }       private Settings settings() {         return Settings.builder()                 .put("cluster.name", elasticsearchProperties.getClusterName())                 .put("client.transport.sniff", elasticsearchProperties.getClientTransportSniff())                 .put("client.transport.ignore_cluster_name", elasticsearchProperties                         .getClientIgnoreClusterName())                 .put("client.transport.ping_timeout", elasticsearchProperties                         .getClientPingTimeout())                 .put("client.transport.nodes_sampler_interval", elasticsearchProperties                         .getClientNodesSamplerInterval())                 //.put("xpack.security.user", "elastic:1qaz2wsx")                 .build();     } }


控制臺(tái)錯(cuò)誤信息:
2019-04-16 13:46:18.257 [svr-demo] ERROR 4492 --- [nio-9999-exec-2] c.j.p.w.e.GlobalExceptionHandler         : None of the configured nodes are available: [{#transport#-1}{_56HAY5MSUefZh20v5asSQ}{172.26.0.251}{172.26.0.251:9300}]
 
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{_56HAY5MSUefZh20v5asSQ}{172.26.0.251}{172.26.0.251:9300}]
    at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:349)
    at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:247)
    at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:60)
    at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:381)
    at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:407)
    at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:396)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:46)
    at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:53)
    at com.jkzl.phr.elasticsearch.ElasticClientKit.count(ElasticClientKit.java:442)
    at com.jkzl.phr.elasticsearch.ElasticClientKit.list(ElasticClientKit.java:446)
    at com.jkzl.phr.elasticsearch.ElasticClientKit.list(ElasticClientKit.java:233)
    at com.jkzl.phr.elasticsearch.ElasticClientKit.list(ElasticClientKit.java:227)
    at com.jkzl.phr.demo.score.service.ElkScoreService.getMapList(ElkScoreService.java:17)
    at com.jkzl.phr.demo.score.controller.ElkScoreDemoController.find(ElkScoreDemoController.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)
分析:
可能原因:通過錯(cuò)誤分析可能是集群名稱,或者端口錯(cuò)誤,或者無法連接到集群節(jié)點(diǎn)

1. 檢查工程中的集群名稱和交互端口是否和es服務(wù)的配置文件中一致(本例中一致,所以排除)

2. 查看es的啟動(dòng)日志,檢查es服務(wù)器的監(jiān)聽I(yíng)P和對(duì)外訪問的IP地址

[root@master-251 overlay2]# docker logs -f elasticsearch
 ...
 [2019-04-16T05:45:56,648][INFO ][o.e.t.TransportService   ] [ehrCloud] publish_address {172.17.0.3:9300}, bound_addresses {0.0.0.0:9300}
 [2019-04-16T05:45:56,796][INFO ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [ehrCloud] publish_address {172.17.0.3:9200}, bound_addresses {0.0.0.0:9200}
 [2019-04-16T05:45:56,797][INFO ][o.e.n.Node               ] [ehrCloud] started


 
因?yàn)閎oot工程中 使用client.transport.sniff為true,使客戶端去嗅探整個(gè)集群的狀態(tài),把集群中其它機(jī)器的ip地址加到客戶端中。這樣做的好處是,一般你不用手動(dòng)設(shè)置集群里所有集群的ip到連接客戶端,它會(huì)自動(dòng)幫你添加,并且自動(dòng)發(fā)現(xiàn)新加入集群的機(jī)器

看上面的日志可以發(fā)現(xiàn)ES服務(wù)器監(jiān)聽到的IP是172.17.0.3,這是docker內(nèi)部分配的IP;在自動(dòng)發(fā)現(xiàn)時(shí)會(huì)使用docker內(nèi)網(wǎng)IP進(jìn)行通信,導(dǎo)致無法連接到ES服務(wù)器

處理:
方式一:修改boot工程配置,關(guān)閉嗅探
設(shè)置工程中的client.transport.sniff為false,關(guān)閉嗅探;或者直接使用addTransportAddress方法把集群中其它機(jī)器的ip地址加到客戶端中

方式二:修改ES服務(wù)器配置,將publish_host改為服務(wù)器的ip而不是docker分配的內(nèi)部IP
修改elasticsearch.yml配置

cluster.name: "docker-cluster" network.host: 0.0.0.0 #修改監(jiān)聽的IP為本機(jī)的IP地址 network.publish_host: 172.26.0.251 network.bind_host: 0.0.0.0 node.name: cloud http.cors.enabled: true http.cors.allow-origin: "*" node.master: true node.data: true 重啟docker
[root@master-251 overlay2]# docker restart elasticsearch ... [2019-04-16T06:30:00,908][INFO ][o.e.n.Node               ] [ehrCloud] starting ... [2019-04-16T06:30:01,197][INFO ][o.e.t.TransportService   ] [ehrCloud] publish_address {172.26.0.251:9300}, bound_addresses {0.0.0.0:9300} [2019-04-16T06:30:01,489][INFO ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [ehrCloud] publish_address {172.26.0.251:9200}, bound_addresses {0.0.0.0:9200} [2019-04-16T06:30:01,490][INFO ][o.e.n.Node               ] [ehrCloud] started [2019-04-16T06:30:01,694][INFO ][o.w.a.d.Monitor          ] [ehrCloud] try load config from /usr/share/elasticsearch/config/analysis-ik/IKAnalyzer.cfg.xml [2019-04-16T06:30:01,696][INFO ][o.w.a.d.Monitor          ] [ehrCloud] try load config from /usr/share/elasticsearch/plugins/elasticsearch-analysis-ik/config/IKAnalyzer.cfg.xml [2019-04-16T06:30:01,992][INFO ][o.w.a.d.Monitor          ] [ehrCloud] [Dict Loading] /usr/share/elasticsearch/plugins/elasticsearch-analysis-ik/config/customer/new_word.dic [2019-04-16T06:30:02,821][WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [ehrCloud] Failed to clear cache for realms [[]]


可以發(fā)現(xiàn)publish_address已經(jīng)變?yōu)榉?wù)器IP(注意elasticsearch.yml中如果配置network.publish_host:0.0.0.0的話 監(jiān)聽的ip還是docker分配的內(nèi)部IP,不知道是什么原因)

上述就是小編為大家分享的Elasticsearch中所有配置的節(jié)點(diǎn)都不可用該怎么辦了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI