Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What if all configured nodes in Elasticsearch are not available?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about what to do if all the configured nodes in Elasticsearch are not available. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

In order to use the scoring mechanism of Elasticsearch, we use docker to quickly build an error when elasticsearch; uses spring boot to connect to ES: the node cannot be found.

Environment:

[jdk]: 1.8

[ES]: 6.5.4 single node (ip:172.26.0.251)

[springboot]: 2.1.2

Code snippet:

Elasticsearch.yml configuration for es:

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 of the project

Spring.data.elasticsearch.cluster-name = docker-cluster spring.data.elasticsearch.cluster-nodes = 172.26.0.251 spring.data.elasticsearch.repositories.enabled = true spring.data.elasticsearch.client-transport-sniff = true # sniffing Settings only introduces the related package org.elasticsearch.client transport org.nlpcn elasticsearch in the pom.xml file -sql es connection configuration class @ 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 () }}

Console error message:

2019-04-16 13 nio-9999-exec-2 46 c.j.p.w.e.GlobalExceptionHandler 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} {172.26.0.251}]

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 (NativeMethod)

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)

Analysis:

Possible cause: through error analysis, it may be the cluster name, or the port is wrong, or cannot connect to the cluster node

1. Check whether the cluster name and interactive port in the project are consistent with the configuration file of the es service (in this case, so exclude)

two。 Check the startup log of es, check the snooping IP of es server and the IP address of external access

[root@master-251 overlay2] # docker logs-f elasticsearch... [2019-04-16T05:45:56648] [INFO] [o.e.t.TransportService] [ehrCloud] publish_address {172.17.0.3 16T05:45:56648 9300}, bound_addresses {0.0.0 elasticsearch 9300} [2019-04-16T05:45:56796] [INFO] [ehrCloud] publish_address {172.17.0.3V 9200} Bound_addresses {0.0.0.0 INFO 9200} [2019-04-16T05:45:56797] [INFO] [o.e.n.Node] [ehrCloud] started

Because client.transport.sniff is true in the boot project, the client can sniff the status of the entire cluster and add the ip addresses of other machines in the cluster to the client. The advantage of this is that generally, you don't have to manually set the ip of all clusters in the cluster to the connecting client, it will automatically add it for you and automatically discover the new machines that join the cluster.

If you look at the log above, you can find that the IP monitored by the ES server is 172.17.0.3. This is because the IP; assigned within the docker will use the docker private network IP to communicate when it is automatically discovered, resulting in unable to connect to the ES server.

Deal with:

Method 1: modify the boot project configuration and turn off sniffing

Set the client.transport.sniff in the project to false and turn off sniffing, or directly use the addTransportAddress method to add the ip addresses of other machines in the cluster to the client

Method 2: modify the ES server configuration and change the publish_host to the ip of the server instead of the internal IP assigned by docker

Modify elasticsearch.yml configuration

Cluster.name: "docker-cluster" network.host: 0.0.0.0 # modify the listening IP to the local IP address 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 restart docker [root @ master-251 overlay2] # docker restart elasticsearch. [2019-04-16T06 30 ehrCloud 00908] [INFO] [o.e.n.Node] [ehrCloud] starting... [2019-04-16T06:30:01197] [INFO] [o.e.t.TransportService] [ehrCloud] publish_address {172.26.0.251 ehrCloud 9300} Bound_addresses {0.0.0.0 INFO 9300} [2019-04-16T06:30:01489] [INFO] [o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [ehrCloud] publish_address {172.26.0.251 INFO} Bound_addresses {0.0.0.0 o.e.n.Node 9200} [2019-04-16T06:30:01490] [INFO] [o.e.n.Node] [ehrCloud] started [2019-04-16T06:30:01694] [INFO] [o.w.a.d.Monitor] [ehrCloud] try load config from / usr/share/elasticsearch/config/analysis-ik/IKAnalyzer.cfg.xml [2019-04-16T06:30:01696] [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:01992] [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:02821 ] [WARN] [o.e.x.s.a.s.m.NativeRoleMappingStore] [ehrCloud] Failed to clear cache for realms [[]]

You can find that publish_address has become the server IP (note that if network.publish_host:0.0.0.0 is configured in elasticsearch.yml, the listening ip is still the internal IP assigned by docker. I don't know why)

This is what to do if all the configured nodes in the Elasticsearch shared by the editor are not available. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report