Elasticsearch:elasticsearch.service 的作业失败

标签 elasticsearch

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

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

sudo systemctl start elasticsearch

我收到以下错误

Job for elasticsearch.service failed because the control process exited with error code.

See "systemctl status elasticsearch.service" and "journalctl -xe" for details.



当我尝试运行命令时
systemctl status elasticsearch.service

我收到错误消息

● elasticsearch.service - Elasticsearch

Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vend

Active: failed (Result: exit-code) since Fri 2019-11-01 06:09:54 UTC; 12s ago

Docs: http://www.elastic.co

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

Main PID: 5960 (code=exited, status=1/FAILURE)



我已删除/清除 Elasticsearch 从我的机器上重新安装了几次,但似乎没有解决问题。

我试图修改默认 network.hosthost.port /etc/default/elasticsearch 中的设置|至 network.host: 0.0.0.0http.port: 9200解决这个问题,但还没有运气。

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

最佳答案

这是我解决的方法
首先打开/etc/elasticsearch/elasticsearch.yml在您的 nano 编辑器中使用以下命令:

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 允许来自本地主机的连接,并监听端口 9200 .
接下来,运行下面的代码来确定错误的原因:
journalctl -xe
错误 1 ​​

There is insufficient memory for the Java Runtime Environment to continue


解决方案
作为 JVM 应用程序, Elasticsearch 主服务器进程仅使用专用于 JVM 的内存。所需的内存可能取决于所使用的 JVM(32 位或 64 位)。 JVM 使用的内存通常包括:
  • 堆空间 (通过 -Xms-Xmx 配置)
  • 元空间 (受可用 native 内存量限制)
  • 内部 JVM (通常为数十 Mb)
  • 依赖于操作系统的内存特性,如 内存映射文件 .

  • Elasticsearch 主要依赖于 堆内存 ,并通过传递 -Xms 手动设置和 -Xmx (堆空间)选项到运行 的 JVM Elasticsearch 服务器。
    解决方案
    开通 /etc/elasticsearch/jvm.options在您的 nano 编辑器中使用以下命令:
    sudo nano /etc/elasticsearch/jvm.options
    
    首先,取消注释 Xmx 的值和 Xms接下来修改-Xms的值和 -Xmx不超过物理 RAM 的 50%。这些设置的值取决于服务器上可用的 RAM 量,Elasticsearch 需要内存用于 JVM 堆以外的用途,为此留出空间很重要。
    最低要求 : 如果你的物理内存是 <= 1 GB
    然后,您的设置应该是:
    # 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
    
    中等要求 : 如果你的物理内存是 >= 2 GB 但是 <= 4 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
    
    大需求 : 如果你的物理内存是 >= 4 GB 但是 <= 8 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
    
    备注 : 如果你的物理内存是 >= 8 GB 您可以决定要为 Elasticsearch 分配多少堆空间。您可以分配-Xms2048m-Xmx2048m-Xms4g-Xmx4g根据您的可用资源,甚至更高以获得更好的性能。
    错误 2

    Initial heap size not equal to the maximum heap size


    解决方案
    确保 -Xms 的值和 Xmx是平等的。也就是说,您正在使用 最低要求 因为你的物理内存是 <= 1 GB , 而不是这个:
    # 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

    the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured


    解决方案
    开通 /etc/elasticsearch/elasticsearch.yml在您的 nano 编辑器中使用以下命令:
    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
    
    就这样。
    我希望这会有所帮助

    关于Elasticsearch:elasticsearch.service 的作业失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58656747/

    相关文章:

    c# - C#NEST elasticsearch源过滤对于大多数字段返回null

    elasticsearch - Logstash错误-用于Elasticsearch的未知设置 '“hosts”'

    mysql - 在 Logstash 的 JDBC 输入插件中设置 MySQL conf

    linux - 如何在 CentOS 5 上将 elasticsearch 作为服务运行

    elasticsearch - 使用logstash将数据集导入到ElasticSearch的速度很慢

    django - 在AWS的Elastic Search中建立索引时出现连接错误

    elasticsearch - Elasticsearch:搜索词以特定符号连接,结尾或包含特定符号

    java - 使用Kibana和Java获取Elasticsearch中的特定字段

    elasticsearch - Elasticsearch错误的距离计算和过滤器

    ruby-on-rails - Elasticsearch/轮胎 : Facets Order