总结遇到的elasticsearch启动失败的几种情况及解决

1、使用root用户启动失败

在有一次搭建elasticsearch的时候,使用systemctl启动elasticsearch失败,然后在bin目录下面去使用启动脚本启动,发现报错不能用root用户启动,报“Caused by: java.lang.RuntimeException: can not run elasticsearch as root”:

[[email protected] bin]# ./elasticsearch
[2017-12-20T17:01:47,922][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-1] 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-6.1.1.jar:6.1.1]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.1.1.jar:6.1.1]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.1.1.jar:6.1.1]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.1.1.jar:6.1.1]
    at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.1.1.jar:6.1.1]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.1.1.jar:6.1.1]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) ~[elasticsearch-6.1.1.jar:6.1.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:104) ~[elasticsearch-6.1.1.jar:6.1.1]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:171) ~[elasticsearch-6.1.1.jar:6.1.1]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:322) ~[elasticsearch-6.1.1.jar:6.1.1]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.1.1.jar:6.1.1]
    ... 6 more
[[email protected] bin]# cd ..

解决:

创建一个独立的用户,比如elk来启动elasticsearch,不用root用户启动

2、elasticsearch安装目录权限不对

遇到启动elasticsearch失败,使用的是专门的用户elk来启动的,启动日志提示不能加载配置文件:

[[email protected] bin]$ ./elasticsearch
Exception in thread "main" 2018-06-03 17:36:23,881 main ERROR No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property ‘log4j2.debug‘ to show Log4j2 internal initialization logging.
2018-06-03 17:36:24,113 main ERROR Could not register mbeans java.security.AccessControlException: access denied ("javax.management.MBeanTrustPermission" "register")
        at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:585)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.checkMBeanTrustPermission(DefaultMBeanServerInterceptor.java:1848)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:322)
        at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
        at org.apache.logging.log4j.core.jmx.Server.register(Server.java:389)
        at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:167)
        at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:140)
        at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:556)
        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:617)
        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
        at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:242)
        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
        at org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)
        at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:618)
        at org.elasticsearch.common.logging.ESLoggerFactory.getLogger(ESLoggerFactory.java:54)
        at org.elasticsearch.common.logging.ESLoggerFactory.getLogger(ESLoggerFactory.java:62)
        at org.elasticsearch.common.logging.Loggers.getLogger(Loggers.java:101)
        at org.elasticsearch.ExceptionsHelper.<clinit>(ExceptionsHelper.java:42)
        at org.elasticsearch.ElasticsearchException.toString(ElasticsearchException.java:663)
        at java.lang.String.valueOf(String.java:2994)
        at java.io.PrintStream.println(PrintStream.java:821)
        at java.lang.Throwable$WrappedPrintStream.println(Throwable.java:748)
        at java.lang.Throwable.printStackTrace(Throwable.java:655)
        at java.lang.Throwable.printStackTrace(Throwable.java:643)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1061)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1052)
        at java.lang.Thread.dispatchUncaughtException(Thread.java:1959)

SettingsException[Failed to load settings from /usr/local/elasticsearch-5.6.0/config/elasticsearch.yml]; nested: AccessDeniedException[/usr/local/elasticsearch-5.6.0/config/elasticsearch.yml];
        at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:102)
        at org.elasticsearch.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:72)
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67)
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134)
        at org.elasticsearch.cli.Command.main(Command.java:90)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84)
Caused by: java.nio.file.AccessDeniedException: /usr/local/elasticsearch-5.6.0/config/elasticsearch.yml
        at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
        at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
        at java.nio.file.Files.newByteChannel(Files.java:361)
        at java.nio.file.Files.newByteChannel(Files.java:407)
        at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
        at java.nio.file.Files.newInputStream(Files.java:152)
        at org.elasticsearch.common.settings.Settings$Builder.loadFromPath(Settings.java:1032)
        at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:100)
        ... 6 more
[[email protected] bin]$ 

解决:

看到“Caused by: java.nio.file.AccessDeniedException: /usr/local/elasticsearch-5.6.0/config/elasticsearch.yml”的提示,就去检查目录的权限,果然是root:root权限,使用elk用户去启动,就报错了。
将目录的权限改成elk:elk就好了。

[[email protected] ~]# ll /usr/local/
drwxr-xr-x  7 root root       123 9月   7 2017 elasticsearch-5.6.0

[[email protected] local]#  chown  -R elk:elk elasticsearch-5.6.0
[[email protected] local]# ll
drwxr-xr-x  7 elk  elk        123 9月   7 2017 elasticsearch-5.6.0

3、日志和数据目录权限异常,启动失败

在一次启动elasticsearch的时候启动失败,日志有提示“main ERROR Unable to create file /home/elk/logs/my-application_index_indexing_slowlog.log java.io.IOException: 权限不够”和“Caused by: java.nio.file.AccessDeniedException: /home/elk/data/nodes”。关键日志信息如下(下面两段日志是节选的,日志信息太多了,有很多重复的):

[[email protected] bin]$ ./elasticsearch
2018-06-04 01:15:07,609 main ERROR Unable to create file /home/elk/logs/my-application.log java.io.IOException: 权限不够
        at java.io.UnixFileSystem.createFileExclusively(Native Method)
        at java.io.File.createNewFile(File.java:1012)

后面还有一段:

 Caused by: java.lang.IllegalStateException: Failed to create node environment
        at org.elasticsearch.node.Node.<init>(Node.java:268) ~[elasticsearch-5.6.0.jar:5.6.0]
        at org.elasticsearch.node.Node.<init>(Node.java:245) ~[elasticsearch-5.6.0.jar:5.6.0]
        at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:233) ~[elasticsearch-5.6.0.jar:5.6.0]
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:233) ~[elasticsearch-5.6.0.jar:5.6.0]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:342) ~[elasticsearch-5.6.0.jar:5.6.0]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:132) ~[elasticsearch-5.6.0.jar:5.6.0]
        ... 6 more
Caused by: java.nio.file.AccessDeniedException: /home/elk/data/nodes
        at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84) ~[?:?]

日志报的“/home/elk/data/”和“/home/elk/logs/”目录都是在elasticsearch.yml配置文件里面配置的两个目录,查看权限果然不对,权限是elk的目录权限是elk,但是下面的data目录和logs目录权限还是root,因此引起了启动失败:

[[email protected] home]# ll
drwx------  5 elk    elk         125 6月   3 17:35 elk       #elk目录权限正常
[[email protected] home]# cd elk/
[[email protected] elk]# ll
总用量 0
drwxr-xr-x 2 root root 6 6月   3 17:34 data      #下面的data和logs目录还是root
drwxr-xr-x 2 root root 6 6月   3 17:34 logs

将目录权限修改成elk之后,启动就OK了

[[email protected] elk]# chown elk:elk -R ./*
[[email protected] elk]# ll
总用量 0
drwxr-xr-x 2 elk elk 6 6月   3 17:34 data
drwxr-xr-x 2 elk elk 6 6月   3 17:34 logs
[[email protected] elk]# 

4、内存不够,启动失败

在一次使用虚拟机做实验的过程中启动elasticsearch遇到了这样的报错:

[[email protected] bin]$ ./elasticsearch
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error=‘Cannot allocate memory‘ (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /usr/local/elasticsearch-5.6.0/bin/hs_err_pid2819.log

解决:

原因:
查看了 /usr/local/elasticsearch-5.6.0/bin/hs_err_pid1027.log日志文件,出现这样的报错,有两种可能:
1、系统进程数达到上限了,部属的时候/etc/security/limits.conf文件修改没有生效。
2、确实物理内存不够

解决:
通过命令查看系统限制:ulimit -a查看open files不够大,如果不够大,就尝试通过设大该值:

[[email protected] ~]# ulimit -n
1024

果然是部属的时候修改的/etc/security/limits.conf文件没有生效。于是将机器reboot了一下,在查看就生效了:

[[email protected] ~]# ulimit -n
65536

但是在启动的时候还是报同样的错,查看了一下内存,这个虚拟机的内存只有1G,那应该就是物理内存不够了。目前还剩下这么多:

[[email protected] ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           974M        119M         79M        7.7M        775M        680M
Swap:          819M          0B        819M

手动清理了一下内存:

[[email protected] ~]# echo 3 > /proc/sys/vm/drop_caches
[[email protected] ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           974M        114M        789M        7.7M         69M        739M
Swap:          819M          0B        819M
[[email protected] ~]# 

但是在启动报错依旧。
于是增加物理内存到2G:

[[email protected] elk]# free -h
              total        used        free      shared  buff/cache   available
Mem:           1.8G        1.6G         77M          4K         72M         29M
Swap:          819M        691M        128M

然后切换到elk用户去启动服务,就OK了:

[[email protected] bin]$ ./elasticsearch     #为了看启动日志就前台启动的,ctrl+c 进程就会over掉

检查端口,起来了

[[email protected] elk]# netstat -tlunp|grep 9200
tcp6       0      0 10.0.0.16:9200          :::*                    LISTEN      9628/java
[[email protected] elk]# 

然后关掉进程重新后台启动:

[[email protected] bin]$ nohup ./elasticsearch >/dev/null 2>&1 &     #后台启动
[2] 9808
[[email protected] bin]$ ps -ef|grep elasticsearch   #检查进程
elk        9808   4115 10 01:29 pts/0    00:00:23 /usr/local/jdk1.8.0_151/bin/java -Xms2g -Xmx2g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -Djdk.io.permissionsUseCanonicalPath=true -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/usr/local/elasticsearch-5.6.0 -cp /usr/local/elasticsearch-5.6.0/lib/* org.elasticsearch.bootstrap.Elasticsearch
elk        9890   4115  0 01:32 pts/0    00:00:00 grep --color=auto elasticsearch
[[email protected] bin]$
[[email protected] elk]# netstat -tlunp|grep 9200    #用root用户检查端口
tcp6       0      0 10.0.0.16:9200          :::*                    LISTEN      9808/java
[[email protected] elk]# 

原文地址:http://blog.51cto.com/10950710/2124131

时间: 2024-10-15 03:22:21

总结遇到的elasticsearch启动失败的几种情况及解决的相关文章

vncserver 启动失败的一种情况

#vncserver Warning: localhost.localdomain:1 is taken because of /tmp/.X11-unix/X1Remove this file if there is no X server localhost.localdomain:1 Warning: localhost.localdomain:2 is taken because of /tmp/.X11-unix/X2Remove this file if there is no X

Win7 64bit 系统安装DirectX提示失败的一种情况的解决方法记录

提示内容为"不能信任一个安装所需的压缩文件.请检查加密服务是否启用并且 Cabinet 文件证书是否有效." 右键点击"计算机"->"管理"->"服务"找到"Health Key and Certificate Management"点击启用,然后再次启动DirectX安装程序就能正常安装了.

启动多线程的两种情况比较

启动多线程有两种方式:(都是在主线程main线程下) 1. 使用同一个线程对象来启多个线程 2. 使用多个线程对象来启多个线程 这两种方式有什么区别呢?先贴上代码举例说明: 这是使用线程对象MyRunnable的同一个实例r来启动了两个线程 MyRunnable r = new MyRunnable(); Thread ta = new Thread(r,"Thread-A"); Thread tb = new Thread(r,"Thread-B"); ta.st

bootstrap.memory_lock: true导致Elasticsearch启动失败问题

elasticsearch官网建议生产环境需要设置bootstrap.memory_lock: true 重新启动elasticsearch,报错信息如下: [[email protected] /home/baoshan/elk/elasticsearch-5.3.0]$bin/elasticsearch[2017-04-20T21:45:36,741][WARN ][o.e.b.JNANatives ] Unable to lock JVM Memory: error=12, reason=

启动elasticsearch报错的几种原因及解决方法

ERROR: [1] bootstrap checks failed [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] 解决: 在宿主机执行: sysctl -w vm.max_map_count=262144 原因: vm.max_map_count参数,是允许一个进程在VMAs拥有最大数量(VMA:虚拟内存地址, 一个连续的虚拟地址空间),当进程占用

elasticsearch启动时提示内存不足错误的解决方法

修改 jvm空间分 cd到elasticsearch目录 vim config/jvm.options 修改: -Xms2g -Xmx2g 为 -Xms256m -Xmx256m 本人主机内存为1G 原文地址:https://www.cnblogs.com/dbSyk/p/10090774.html

Junit4使用详解一:测试失败的两种情况

Junit4最佳实践 1.把测试文件夹和代码文件夹分离,这两者的代码互不干扰,代码目录和测试目录是并列的关系 2.Java代码 3.创建单元测试代码文件 4.运行测试代码  5.查看测试结果 现在的情况是我的测试代码是全部通过的,所以右边横条是绿色,现在再来看另一种情况: 我第一个“相加“的方法中,本来3+3=6,我的期望值写成了3,导致运行测试代码时,报了一个failure的错误,意思是指预期值跟我写的值不一致导致错误. 再看到这个地方 这是一个“相除”的方法,3/0,系统直接报错error,

割接(升级)失败的几种情况

2019-10-31 在覆盖更新的时候,地址重复.比如你开始写了一个TestController里面有几个测试接口,并更新到服务器上,后来,你把它命名为Test2Controller,本地运行没有问题,本地工具同步做得好,它把以前那个controller删除了,但是 服务器如果是覆盖更新的吧,就会有2个Testcontroller,就会冲突. SpringContextHelper.getBean(XXX.class),这种情况,如果class没有定位bean时,会报错,而不是返回null,还是

zookeeper启动失败排查

最近开始实践搭建Linux下的集群环境,在搭建zookeeper的时候,出现了启动失败的情况,介绍下几种情况和解决方法. 首先,强烈建议新手刚开始搭建的时候关掉防火墙,否则可能出现很多奇怪的错误令人心烦. 关闭防火墙并且禁止开机启动 systemctl stop firewalld.service systemctl disable firewalld.service 1.java.net.BindException: 地址已在使用 端口被占用了,这种情况下只需要把2181端口改成别的就可以了