ElasticSearch异常归纳(能力工场小马哥)

2018-08-05 07:46:19来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

  • 异常1: can not run elasticsearch as root
[WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-2] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:125) ~[elasticsearch-5.1.2.jar:5.1.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-5.1.2.jar:5.1.2]
at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) ~[elasticsearch-5.1.2.jar:5.1.2]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.1.2.jar:5.1.2]
at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.1.2.jar:5.1.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:89) ~[elasticsearch-5.1.2.jar:5.1.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:82) ~[elasticsearch-5.1.2.jar:5.1.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:100) ~[elasticsearch-5.1.2.jar:5.1.2]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:176) ~[elasticsearch-5.1.2.jar:5.1.2]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:306) ~[elasticsearch-5.1.2.jar:5.1.2]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-5.1.2.jar:5.1.2]
... 6 more

 

  • 异常1解决方式: 

在es-linux环境中,不允许使用root用户运行ElasticSearch,所以添加一个新的普通用户就可以了(linux命令如下)

1 groupadd es      -- 创建一个用户组(我使用的es作为组名)
2 useradd -g es es   -- 创建一个用户(我使用es作为用户名,并加入到es组里面)
3 passwd es       -- 为刚刚创建的es用户添加密码
4 su es         -- 切换到es用户下
5 $ElasticSearch_Home/bin/elasticsearch  --启动ElasticSearch

 

  • 异常2: failed to obtain lock on ...
 1 Caused by: java.io.IOException: failed to obtain lock on /bigdata/env/elasticsearch512/data/nodes/0
 2     at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:238) ~[elasticsearch-5.1.2.jar:5.1.2]
 3     at org.elasticsearch.node.Node.<init>(Node.java:249) ~[elasticsearch-5.1.2.jar:5.1.2]
 4     at org.elasticsearch.node.Node.<init>(Node.java:229) ~[elasticsearch-5.1.2.jar:5.1.2]
 5     at org.elasticsearch.bootstrap.Bootstrap$6.<init>(Bootstrap.java:214) ~[elasticsearch-5.1.2.jar:5.1.2]
 6     at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:214) ~[elasticsearch-5.1.2.jar:5.1.2]
 7     at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:306) ~[elasticsearch-5.1.2.jar:5.1.2]
 8     at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-5.1.2.jar:5.1.2]
 9     ... 6 more
10 Caused by: java.nio.file.AccessDeniedException: /bigdata/env/elasticsearch512/data/nodes/0/node.lock
11     at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84) ~[?:?]
12     at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102) ~[?:?]
13     at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107) ~[?:?]
14     at sun.nio.fs.UnixFileSystemProvider.newFileChannel(UnixFileSystemProvider.java:177) ~[?:?]
15     at java.nio.channels.FileChannel.open(FileChannel.java:287) ~[?:1.8.0_181]
16     at java.nio.channels.FileChannel.open(FileChannel.java:335) ~[?:1.8.0_181]
17     at org.apache.lucene.store.NativeFSLockFactory.obtainFSLock(NativeFSLockFactory.java:113) ~[lucene-core-6.3.0.jar:6.3.0 a66a44513ee8191e25b477372094bfa846450316 - shalin - 2016-11-02 19:47:11]
18     at org.apache.lucene.store.FSLockFactory.obtainLock(FSLockFactory.java:41) ~[lucene-core-6.3.0.jar:6.3.0 a66a44513ee8191e25b477372094bfa846450316 - shalin - 2016-11-02 19:47:11]
19     at org.apache.lucene.store.BaseDirectory.obtainLock(BaseDirectory.java:45) ~[lucene-core-6.3.0.jar:6.3.0 a66a44513ee8191e25b477372094bfa846450316 - shalin - 2016-11-02 19:47:11]
20     at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:225) ~[elasticsearch-5.1.2.jar:5.1.2]
21     at org.elasticsearch.node.Node.<init>(Node.java:249) ~[elasticsearch-5.1.2.jar:5.1.2]
22     at org.elasticsearch.node.Node.<init>(Node.java:229) ~[elasticsearch-5.1.2.jar:5.1.2]
23     at org.elasticsearch.bootstrap.Bootstrap$6.<init>(Bootstrap.java:214) ~[elasticsearch-5.1.2.jar:5.1.2]
24     at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:214) ~[elasticsearch-5.1.2.jar:5.1.2]
25     at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:306) ~[elasticsearch-5.1.2.jar:5.1.2]
26     at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-5.1.2.jar:5.1.2]
27     ... 6 more
  • 异常2解决方式: 

由于上面使用root创建的es目录,导致ElasticSearch安装目录的所属用户和所属组都是root,现在使用es用户去启动elasticsearch命令,导致没有权限获取node.lock

最直接的解决方式: 将es所有目录更改所属用户到es下就可以了

1 chown -R es:es ./elasticsearch512
2     --(elasticsearch512是我对es安装目录的命名)
3     --(-R选项: 将elasticsearch512目录及内部所有子目录都更改所属用户)
4     --(es:es  代表:  用户:用户组)

 

  • 异常3: BindTransportException[Failed to bind to [9300-9400]]
 1 [WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-2] uncaught exception in thread [main]
 2 org.elasticsearch.bootstrap.StartupException: BindTransportException[Failed to bind to [9300-9400]]; nested: BindException[Cannot assign requested address];
 3     at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:125) ~[elasticsearch-5.1.2.jar:5.1.2]
 4     at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-5.1.2.jar:5.1.2]
 5     at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) ~[elasticsearch-5.1.2.jar:5.1.2]
 6     at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.1.2.jar:5.1.2]
 7     at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.1.2.jar:5.1.2]
 8     at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:89) ~[elasticsearch-5.1.2.jar:5.1.2]
 9     at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:82) ~[elasticsearch-5.1.2.jar:5.1.2]
10 Caused by: org.elasticsearch.transport.BindTransportException: Failed to bind to [9300-9400]
11     at org.elasticsearch.transport.TcpTransport.bindToPort(TcpTransport.java:636) ~[elasticsearch-5.1.2.jar:5.1.2]
12     at org.elasticsearch.transport.TcpTransport.bindServer(TcpTransport.java:601) ~[elasticsearch-5.1.2.jar:5.1.2]
13     at org.elasticsearch.transport.netty4.Netty4Transport.doStart(Netty4Transport.java:182) ~[?:?]
14     at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:69) ~[elasticsearch-5.1.2.jar:5.1.2]
15     at org.elasticsearch.transport.TransportService.doStart(TransportService.java:188) ~[elasticsearch-5.1.2.jar:5.1.2]
16     at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:69) ~[elasticsearch-5.1.2.jar:5.1.2]
17     at org.elasticsearch.node.Node.start(Node.java:577) ~[elasticsearch-5.1.2.jar:5.1.2]
18     at org.elasticsearch.bootstrap.Bootstrap.start(Bootstrap.java:234) ~[elasticsearch-5.1.2.jar:5.1.2]
19     at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:308) ~[elasticsearch-5.1.2.jar:5.1.2]
20     at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-5.1.2.jar:5.1.2]
21     ... 6 more
22 Caused by: java.net.BindException: Cannot assign requested address
23     at sun.nio.ch.Net.bind0(Native Method) ~[?:?]
24     at sun.nio.ch.Net.bind(Net.java:433) ~[?:?]
25     at sun.nio.ch.Net.bind(Net.java:425) ~[?:?]
26     at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) ~[?:?]
27     at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:127) ~[?:?]
28     at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:554) ~[?:?]
29     at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1258) ~[?:?]
30     at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:512) ~[?:?]
31     at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:497) ~[?:?]
32     at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:980) ~[?:?]
33     at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:250) ~[?:?]
34     at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:363) ~[?:?]
35     at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) ~[?:?]
36     at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:418) ~[?:?]
37     at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:454) ~[?:?]
38     at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873) ~[?:?]
39     at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
  • 异常3解决方式
1 network.host: 0.0.0.0     -- 绑定IP到本机        
  • 启动失败1:
1 ERROR: bootstrap checks failed
2 max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
  • 启动失败1解决方式:

  原因: elasticsearch 能够打开的最大句柄数为65536,这个数量不能满足最低65536的要求,更改一下可以linux的配置文件解决

1 vi /etc/security/limits.conf
2 
3 root soft nofile 65535
4 root hard nofile 65535
5 * soft nofile 65536  --将所有用户能够打开的最大句柄数都修改为65536
6 * hard nofile 65536
  • 启动失败2:

  原因: 直接翻译就是虚拟内存65530太低

1 max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
  • 启动失败2解决方式:
1 vi /etc/sysctl.conf
2 vm.max_map_count=655360
3 按Esc-->按Shift+:-->输入wq 保存退出
4 sysctl -p       -- 命令意思: 从指定的文件加载系统参数,如不指定即从/etc/sysctl.conf中加载

 

  • 从节点加入集群失败1:  failed to send join request to master
1 [INFO ][o.e.d.z.ZenDiscovery     ] [node-2] failed to send join request to master [{node-1}{7Wy1WO3fQZmBDwcDQRDh2Q}{kqmtZtjiSuC79opYfj1jzg}{172.31.87.193}{172.31.87.193:9300}], 
  reason [RemoteTransportException[[node-1][172.31.87.193:9300][internal:discovery/zen/join]];
nested: IllegalArgumentException[can't add node {node-2}{7Wy1WO3fQZmBDwcDQRDh2Q}{HW7YhCEBRbGti1ra7WXTYg}{172.31.87.192}{172.31.87.192:9300},
found existing node {node-1}{7Wy1WO3fQZmBDwcDQRDh2Q}{kqmtZtjiSuC79opYfj1jzg}{172.31.87.193}{172.31.87.193:9300} with the same id but is a different node instance]; ]
  • 从节点加入集群失败1解决方式:

出错原因: 该节点(node2)的安装文件都是妥妥的在主节点(node1)拷贝过来的,所以,数据文件(data文件夹下面的数据也拷贝过来了),按照抛错意思,可能是里面保存了node1的id等信息导致了冲突

1 rm -rf $ElasticSearch_home/data/*    --删除data目录下面的从Node1考来的所有数据
2 在node2节点上重启elasticsearch
3 在node1主节点上会发现如下状态信息: 4 [node-1] added {{node-2}{Qg2j8WLgQpy10mzs-r42Eg}{85mIKdCRRG-BAb42g8YhDg}{172.31.87.192}{172.31.87.192:9300},}, reason: zen-disco-node-join[{node-2}{Qg2j8WLgQpy10mzs-r42Eg}{85mIKdCRRG-BAb42g8YhDg}{172.31.87.192}{172.31.87.192:9300}] 5 [2018-08-04T23:40:25,006][INFO ][o.e.c.r.a.AllocationService] [node-1] Cluster health status changed from [YELLOW] to [GREEN] (reason: [shards started [[megacorp][4]] ...]).

 

 

 

JavaAPI开发异常1:  NoNodeAvailableException: None of the configured nodes are available

 1 Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{9zZ22lWuQpKTZlroNRCrNg}{47.105.116.201}{47.105.116.201:9300}]]
 2     at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:328)
 3     at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:226)
 4     at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59)
 5     at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:345)
 6     at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:403)
 7     at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80)
 8     at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54)
 9     at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:62)
10     at com.nengli51.es.data.Demo.main(Demo.java:23)

异常原因: 通过 TransportClient 连接集群时,需要配置 cluster.name 信息,出错原因可能是 使用Settings.EMPTY选项,或者使用了错误的Setting配置,导致连接集群失败

1 Settings settings = Settings.builder().put("cluster.name", "estest").build();
2 TransportClient client = new PreBuiltTransportClient(settings);   //这里是连接配置了cluster.name的集群的连接方式,如果你的ElasticSearch集群使用的默认集群名字(压根就没设置elasticsearch)那么直接使用下面的
* TransportClient client = new PreBuiltTransportClient(Settings.EMPTY);

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:JsonConfig处理日期时间

下一篇:Java代码质量改进之:使用ThreadLocal维护线程内部变量