【问题标题】:Elasticsearch: Job for elasticsearch.service failedElasticsearch:elasticsearch.service 的作业失败
【发布时间】:2020-02-27 14:30:18
【问题描述】:

我目前正在尝试为一个项目设置 Elasticsearch。我安装了Elasticsearch 7.4.1,也安装了Java,即openjdk 11.0.4

但是当我尝试使用命令启动 Elasticsearch

sudo systemctl start elasticsearch

我收到以下错误

elasticsearch.service 的作业失败,因为控制进程以错误代码退出。

详见“systemctl status elasticsearch.service”和“journalctl -xe”。

当我尝试运行命令时

systemctl status elasticsearch.service

我收到错误消息

● elasticsearch.service - 弹性搜索

已加载:已加载(/usr/lib/systemd/system/elasticsearch.service;已禁用;售卖

活动:自 2019 年 11 月 1 日星期五 06:09:54 UTC 以来失败(结果:退出代码); 12 秒前

Docs: http://www.elastic.co

进程:5960 ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DI

主 PID:5960(代码=已退出,状态=1/FAILURE)

我已经从我的机器中删除/清除了 Elasticsearch 并重新安装了几次,但它似乎无法解决问题。

我已尝试将/etc/default/elasticsearch 中的默认network.hosthost.port 设置修改为network.host: 0.0.0.0http.port: 9200 以解决此问题,但还没有成功。

我需要一些帮助。提前致谢。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    我是这样解决的

    首先,使用以下命令在您的 nano 编辑器中打开 /etc/elasticsearch/elasticsearch.yml

    sudo nano /etc/elasticsearch/elasticsearch.yml
    

    您的网络设置应该是:

    # Set the bind address to a specific IP (IPv4 or IPv6):
    #
    network.host: 127.0.0.1
    #
    # Set a custom port for HTTP:
    #
    http.port: 9200
    

    为了让 Elasticsearch 允许来自 localhost 的连接,并同时监听端口 9200

    接下来,运行下面的代码来确定错误的原因:

    journalctl -xe
    

    错误 1

    Java 运行时环境内存不足,无法继续

    解决方案

    作为 JVM 应用程序,Elasticsearch 主服务器进程仅使用专用于 JVM 的内存。所需内存可能取决于所使用的 JVM(32 位或 64 位)。 JVM使用的内存通常包括:

    • 堆空间(通过-Xms-Xmx 配置)
    • 元空间(受可用本机内存量限制)
    • 内部 JVM(通常为数十 Mb)
    • 依赖于操作系统的内存功能,例如内存映射文件

    Elasticsearch 主要依赖于堆内存,并且通过将-Xms-Xmx(堆空间)选项手动传递给运行Elasticsearch 的JVM 进行此设置服务器。

    解决方案

    使用以下命令在您的 nano 编辑器中打开 /etc/elasticsearch/jvm.options

    sudo nano /etc/elasticsearch/jvm.options
    

    首先,取消注释XmxXms的值

    接下来,将 -Xms-Xmx 的值修改为不超过物理 RAM 的 50%。这些设置的值取决于服务器上可用的 RAM 量,而 Elasticsearch 需要内存用于 JVM 堆以外的用途,为此留出空间很重要。

    最低要求:如果您的物理 RAM

    那么,你的设置应该是:

    # Xms represents the initial size of total heap space
    # Xmx represents the maximum size of total heap space
    
    -Xms128m
    -Xmx128m
    

    # Xms represents the initial size of total heap space
    # Xmx represents the maximum size of total heap space
    
    -Xms256m
    -Xmx256m
    

    中等要求:如果您的物理 RAM >= 2 GB

    那么,你的设置应该是:

    # Xms represents the initial size of total heap space
    # Xmx represents the maximum size of total heap space
    
    -Xms512m
    -Xmx512m
    

    # Xms represents the initial size of total heap space
    # Xmx represents the maximum size of total heap space
    
    -Xms750m
    -Xmx750m
    

    大要求:如果您的物理 RAM >= 4 GB

    那么,你的设置应该是:

    # Xms represents the initial size of total heap space
    # Xmx represents the maximum size of total heap space
    
    -Xms1024m
    -Xmx1024m
    

    # Xms represents the initial size of total heap space
    # Xmx represents the maximum size of total heap space
    
    -Xms2048m
    -Xmx2048m
    

    注意:如果您的物理 RAM >= 8 GB,您可以决定要为 Elasticsearch 分配多少堆空间。您可以根据您的可用资源分配-Xms2048m-Xmx2048m-Xms4g-Xmx4g 甚至更高以获得更好的性能。

    错误 2

    初始堆大小不等于最大堆大小

    解决方案

    确保-XmsXmx 的值相等。也就是说,您使用的是最低要求,因为您的物理 RAM 是 ,而不是这样:

    # Xms represents the initial size of total heap space
    # Xmx represents the maximum size of total heap space
    
    -Xms128m
    -Xmx256m
    

    应该是这样的:

    # Xms represents the initial size of total heap space
    # Xmx represents the maximum size of total heap space
    
    -Xms128m
    -Xmx128m
    

    或者这个:

    # Xms represents the initial size of total heap space
    # Xmx represents the maximum size of total heap space
    
    -Xms256m
    -Xmx256m
    

    错误 3

    默认发现设置不适合生产使用;必须至少配置 [discovery.seed_hosts、discovery.seed_providers、cluster.initial_master_nodes] 之一

    解决方案

    使用以下命令在您的 nano 编辑器中打开 /etc/elasticsearch/elasticsearch.yml

    sudo nano /etc/elasticsearch/elasticsearch.yml
    

    您的发现设置应该是:

    # Pass an initial list of hosts to perform discovery when this node is started:
    # The default list of hosts is ["127.0.0.1", "[::1]"]
    #
    discovery.seed_hosts: []
    

    修复所有错误后,运行以下命令启动并确认 Elasticsearch 的状态:

    sudo systemctl start elasticsearch
    sudo systemctl status elasticsearch
    

    就是这样。

    我希望这会有所帮助

    【讨论】:

    • 太棒了!它对我帮助很大!
    • 如果你和我一样使用5美元的数字海洋(RAM:1go)滴,建议设置-Xms512mo-Xmx512mo
    • 这将是您 RAM @JulienLeCoupanec 的 50% 左右,我认为这是不可取的。我建议你应该考虑 -Xmx128m。
    • @PromisePreston,你说得对,我不得不切换回 128mo。在旁边运行另一个脚本时造成了很多麻烦。
    • 回答自己的问题值得起立鼓掌
    【解决方案2】:

    小型虚拟机也有同样的问题。上面的配置已经设置好了。唯一有帮助的是增加启动超时。标准的 systemd 超时是不够的。

    作为预防措施,我将超时设置为 5 分钟,如下所示。

    sudo nano /usr/lib/systemd/system/elasticsearch.service
    

    在 elasticsearch.service 文件的 [Service] 部分下添加。

    TimeoutStartSec=300
    

    激活对服务的更改。

    sudo /bin/systemctl enable elasticsearch.service
    

    再次启动服务。

    service elasticsearch start
    

    【讨论】:

    【解决方案3】:

    如果使用包管理安装,请检查/etc/elasticsearch目录的所有者是否为elasticsearch。

    sudo chown -R elasticsearch:elasticsearch /etc/elasticsearch/
    

    【讨论】:

    • 谢谢,为我工作。干杯。
    【解决方案4】:

    首先验证这是否与命令相同:

    journalctl -xe
    

    如果您看到这样的错误 java.lang.NoClassDefFoundError: Could not initialize class 然后这样做:

    我从这里得到的解决方案https://github.com/elastic/elasticsearch/issues/57018

    sudo nano /etc/sysconfig/elasticsearch
    

    在文件的末尾或开头添加这个

    # Elasticsearch temp directory
    ES_TMPDIR=/var/log/elasticsearch
    

    【讨论】:

      【解决方案5】:

      尝试重新启动系统或直接退出

      我在全新安装 ES 时遇到了与 OP 相同的问题。在进入日志和谷歌搜索的兔子洞之前,我只是尝试退出我的操作系统(Ubuntu 20.04)并重新登录。打开一个新的终端,elasticsearch 能够成功启动。

      作为参考,我使用了:

      sudo service elasticsearch restart
      

      并检查:

      sudo service elasticsearch status
      

      【讨论】:

      • 虽然这可能有效(重新启动),但在后续较长的会话中,我又遇到了内存错误。因此,我没有总是重启,而是按照Promise Preston's answer 的建议使用了jvm.options 修复。
      【解决方案6】:

      在我的情况下,我的服务器缺少 java 当我重新配置我的新服务器时,我没有检查 java。

      安装java后,它开始工作了。

      它可能对某人有帮助

      请先检查java是否预装...因为它是elasticsearch的前置要求。

      # systemctl status elasticsearch.service
      # which java
      # locate java
      # java --version
      # sudo apt install openjdk-11-jre-headless
      # java --version
      # sudo systemctl stop elasticsearch
      # sudo systemctl start elasticsearch
      
      

      谢谢。

      【讨论】:

        【解决方案7】:

        我使用的是 ubuntu 20.04,就我而言,问题出在安装部分。我按照official documentation 中的自动安装步骤进行操作。 搜索了一段时间后,我尝试了相同文档中描述的手动方法,对我来说就像魔术一样工作。

        【讨论】:

          【解决方案8】:

          安装elasticsearch 7.15.2的步骤 关注这个digital ocean article

          如果您看到此错误

          elasticsearch.service 的作业失败,因为控制进程以错误代码退出。

          请参阅“systemctl status elasticsearch.service”和“journalctl -xe”了解 详情。

          打开sudo nano /etc/elasticsearch/elasticsearch.yml

          取消评论这些

          network.host: 127.0.0.1
          http.port: 9200
          

          打开sudo nano /etc/elasticsearch/jvm.options

          取消评论这些

          -Xms4g 
          -Xmx4g
          

          打开sudo nano /etc/elasticsearch/elasticsearch.yml

          更新这个

          discovery.seed_hosts: []
          

          最后运行这些

          sudo systemctl start elasticsearch
          sudo systemctl status elasticsearch
          

          检查它是否正常运行此命令

          curl -X GET 'http://localhost:9200'
          

          【讨论】:

            【解决方案9】:

            对于某些人来说,这可能对我来说就是这种情况,所以这可能会对某人有所帮助。我是写这些东西的菜鸟,所以请耐心等待。

            所以报错了

            线程“main”中的异常 org.elasticsearch.bootstrap.BootstrapException: org.elasticsearch.cli.UserException: 无法创建临时密钥库 a>

            可能的根本原因:java.nio.file.AccessDeniedException: /etc/elasticsearch/elasticsearch.keystore.tmp

            elasticsearch.service:失败,结果为“退出代码”。

            elasticsearch.service:主进程退出,code=exited,status=1/FAILURE

            对于 ubuntu 20.04, 解决方法是运行这两个命令:

            sudo chmod g+w /etc/elasticsearch

            以上命令更改文件权限(允许)以手动创建击键。以下命令手动创建。

            sudo -u elasticsearch -s /usr/share/elasticsearch/bin/elasticsearch-keystore create
            

            【讨论】:

              【解决方案10】:

              我也遇到了同样的问题

              我检查了 elasticsearch 服务状态

              sudo systemctl start elasticsearch
              

              接下来,运行下面的代码来确定错误的原因:

              journalctl -xe 
              

              我看到很多关于性能分析器的行

              Dec 20 21:07:37 my performance-analyzer-agent-cli[13112]: INFO: Single batch             : No bind variables have been provided with a single statement batch execution. This may be due to accidental API misuse
              Dec 20 21:07:37 my performance-analyzer-agent-cli[13112]: Dec 20, 2019 9:07:37 PM org.jooq.tools.JooqLogger info
              Dec 20 21:07:37 my performance-analyzer-agent-cli[13112]: INFO: Single batch             : No bind variables have been provided with a single statement batch execution. This may be due to accidental API misuse
              Dec 20 21:07:42 my performance-analyzer-agent-cli[13112]: Dec 20, 2019 9:07:42 PM org.jooq.tools.JooqLogger info
              Dec 20 21:07:42 my performance-analyzer-agent-cli[13112]: INFO: Single batch             : No bind variables have been provided with a single statement batch execution. This may be due to accidental API misuse
              Dec 20 21:07:42 my performance-analyzer-agent-cli[13112]: Dec 20, 2019 9:07:42 PM org.jooq.tools.JooqLogger info
              Dec 20 21:07:42 my performance-analyzer-agent-cli[13112]: INFO: Single batch             : No bind variables have been provided with a single statement batch execution. This may be due to accidental API misuse
              Dec 20 21:07:47 my performance-analyzer-agent-cli[13112]: Dec 20, 2019 9:07:47 PM org.jooq.tools.JooqLogger info
              Dec 20 21:07:47 my performance-analyzer-agent-cli[13112]: INFO: Single batch             : No bind variables have been provided with a single statement batch execution. This may be due to accidental API misuse
              Dec 20 21:07:47 my performance-analyzer-agent-cli[13112]: Dec 20, 2019 9:07:47 PM org.jooq.tools.JooqLogger info
              Dec 20 21:07:47 my performance-analyzer-agent-cli[13112]: INFO: Single batch             : No bind variables have been provided with a single statement batch execution. This may be due to accidental API misuse
              Dec 20 21:07:52 my performance-analyzer-agent-cli[13112]: Dec 20, 2019 9:07:52 PM org.jooq.tools.JooqLogger info
              Dec 20 21:07:52 my performance-analyzer-agent-cli[13112]: INFO: Single batch             : No bind variables have been provided with a single statement batch execution. This may be due to accidental API misuse
              Dec 20 21:07:52 my performance-analyzer-agent-cli[13112]: Dec 20, 2019 9:07:52 PM org.jooq.tools.JooqLogger info
              Dec 20 21:07:52 my performance-analyzer-agent-cli[13112]: INFO: Single batch             : No bind variables have been provided with a single statement batch execution. This may be due to accidental API misuse
              Dec 20 21:07:57 my performance-analyzer-agent-cli[13112]: Dec 20, 2019 9:07:57 PM org.jooq.tools.JooqLogger info
              Dec 20 21:07:57 my performance-analyzer-agent-cli[13112]: INFO: Single batch             : No bind variables have been provided with a single statement batch execution. This may be due to accidental API misuse
              Dec 20 21:07:57 my performance-analyzer-agent-cli[13112]: Dec 20, 2019 9:07:57 PM org.jooq.tools.JooqLogger info
              Dec 20 21:07:57 my performance-analyzer-agent-cli[13112]: INFO: Single batch             : No bind variables have been provided with a single statement batch execution. This may be due to accidental API misuse
              Dec 20 21:08:02 my performance-analyzer-agent-cli[13112]: Dec 20, 2019 9:08:02 PM org.jooq.tools.JooqLogger info
              Dec 20 21:08:02 my performance-analyzer-agent-cli[13112]: INFO: Single batch             : No bind variables have been provided with a single statement batch execution. This may be due to accidental API misuse
              Dec 20 21:08:02 my performance-analyzer-agent-cli[13112]: Dec 20, 2019 9:08:02 PM org.jooq.tools.JooqLogger info
              Dec 20 21:08:02 my performance-analyzer-agent-cli[13112]: INFO: Single batch             : No bind variables have been provided with a single statement batch execution. This may be due to accidental API misuse
              Dec 20 21:08:07 my performance-analyzer-agent-cli[13112]: Dec 20, 2019 9:08:07 PM org.jooq.tools.JooqLogger info
              Dec 20 21:08:07 my performance-analyzer-agent-cli[13112]: INFO: Single batch             : No bind variables have been provided with a single statement batch execution. This may be due to accidental API misuse
              Dec 20 21:08:07 my performance-analyzer-agent-cli[13112]: Dec 20, 2019 9:08:07 PM org.jooq.tools.JooqLogger info
              Dec 20 21:08:07 my performance-analyzer-agent-cli[13112]: INFO: Single batch             : No bind variables have been provided with a single statement batch execution. This may be due to accidental API misuse
              

              这使得问题分析问题 所以首先我试图阻止它,所以我找到了一个链接

              在 /usr/lib/systemd/system/opendistro-performance-analyzer.service 中

              在 [Service] 下添加 StandardOutput=null

              之后通过‘/bin/systemctl daemon-reload’重新加载systemd使其生效

              更多详情请点击以下链接 https://discuss.opendistrocommunity.dev/t/performance-analyzer-agent-cli-spamming-syslog-in-od-1-3-0/2040/4

              现在图片很清楚了,我发现了我忘记评论的 elasticsearch.yml 文件中有重复属性的问题。我注释掉了重复的属性并重新启动了elasticsearch服务。

              sudo systemctl start elasticsearch
              sudo systemctl status elasticsearch
              

              就是这样。

              我希望它会有所帮助。

              【讨论】:

                猜你喜欢
                • 2018-03-30
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多