異常1: can not run elasticsearch as root 異常1解決方式: 在es-linux環境中,不允許使用root用戶運行ElasticSearch,所以添加一個新的普通用戶就可以了(linux命令如下) 異常2: failed to obtain lock on ... ...
- 異常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);