解决Spring Boot(2.1.3.RELEASE)整合spring-data-elasticsearch3.1.5.RELEASE报NoNodeAvailableException[None of the configured nodes are available
Spring Boot(2.1.3.RELEASE)整合spring-data-elasticsearch3.1.5.RELEASE报NoNodeAvailableException[None of the configured nodes are available问题:
具体异常消息:
1 NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{NoI2lKCmTa2aqX7uIYaVGg}{172.27.73.28}{172.27.73.28:9301}] 2 ] 3 at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:349) 4 at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:247) 5 at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:60) 6 at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:381) 7 at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:407) 8 at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:396) 9 at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:46) 10 at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.doCount(ElasticsearchTemplate.java:501) 11 at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.count(ElasticsearchTemplate.java:466) 12 at org.springframework.data.elasticsearch.repository.query.ElasticsearchPartQuery.execute(ElasticsearchPartQuery.java:72) 13 at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:605) 14 at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595) 15 at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595) 16 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) 17 at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) 18 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) 19 at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) 20 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) 21 at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) 22 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) 23 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) 24 at com.sun.proxy.$Proxy70.findByNameLike(Unknown Source) 25 at com.practice.elasticsearch.SpringBoot02ElasticsearchApplicationTests.test1(SpringBoot02ElasticsearchApplicationTests.java:38) 26 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 27 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 28 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 29 at java.lang.reflect.Method.invoke(Method.java:498) 30 at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 31 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 32 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 33 at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 34 at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74) 35 at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84) 36 at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) 37 at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) 38 at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) 39 at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 40 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251) 41 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) 42 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 43 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 44 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 45 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 46 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 47 at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) 48 at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) 49 at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 50 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) 51 at org.junit.runner.JUnitCore.run(JUnitCore.java:137) 52 at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) 53 at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) 54 at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) 55 at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
我在docker上安装的elasticsearch是latest,也就是最高版。
下面的6.2.2是我后安的。
项目中引用的spring-data-elasticsearch是3.1.5.RELEASE版的。
在的github地址上:https://github.com/spring-projects/spring-data-elasticsearch,由如下说明:
说明,我们使用的elasticsearch是6.2.2版本。
关键是在docker hub elasticsearch上并没有6.2.2版,或者相邻的版本。
所以我们上elasticsearch官网上下载,直接在docker中下载镜像:
docker pull docker.elastic.co/elasticsearch/elasticsearch:6.2.2
运行
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.2.4
发现,运行了,马上就停止了。报以下错误:
[2019-03-16T11:34:18,203][INFO ][o.e.n.Node ] [qWS8p_Y] starting ... [2019-03-16T11:34:18,428][INFO ][o.e.t.TransportService ] [qWS8p_Y] publish_address {172.17.0.2:9300}, bound_addresses {0.0.0.0:9300} [2019-03-16T11:34:18,474][INFO ][o.e.b.BootstrapChecks ] [qWS8p_Y] bound or publishing to a non-loopback address, enforcing bootstrap checks ERROR: [1] bootstrap checks failed [1]: max virtual memory areas vm.max_map_count [65535] is too low, increase to at least [262144] [2019-03-16T11:34:18,545][INFO ][o.e.n.Node ] [qWS8p_Y] stopping ... [2019-03-16T11:34:18,637][INFO ][o.e.n.Node ] [qWS8p_Y] stopped [2019-03-16T11:34:18,637][INFO ][o.e.n.Node ] [qWS8p_Y] closing ... [2019-03-16T11:34:18,652][INFO ][o.e.n.Node ] [qWS8p_Y] closed
在elasticsearch6.2的docker安装页面上,地址:https://www.elastic.co/guide/en/elasticsearch/reference/6.2/docker.html,由如下说明:
The vm.max_map_count setting should be set permanently in /etc/sysctl.conf: $ grep vm.max_map_count /etc/sysctl.conf vm.max_map_count=262144 To apply the setting on a live system type: sysctl -w vm.max_map_count=262144
我们设定vm.max_map_count的值>262144即可。
使用:sysctl -a | grep "vm.max_map_count"查看修改的值。
再重启,OK。
注意的是,在配置文件中,配置
data: elasticsearch: cluster-name: docker-cluster
不是最新版的:elasticsearch