Elasticsearch:elasticsearch.service 的作业失败 [英] Elasticsearch: Job for elasticsearch.service failed

查看:182
本文介绍了Elasticsearch:elasticsearch.service 的作业失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试为一个项目设置 Elasticsearch.我已经安装了 Elasticsearch 7.4.1 并且我还安装了 Java,即 openjdk 11.0.4.

I am currently trying to setup Elasticsearch for a project. I have installed Elasticsearch 7.4.1 and I have also installed Java, that is openjdk 11.0.4.

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

But when I try to start Elasticsearch using the command

sudo systemctl start elasticsearch

我收到以下错误

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

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

详见systemctl status elasticsearch.service"和journalctl -xe".

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

当我尝试运行命令时

systemctl status elasticsearch.service

我收到错误信息

● elasticsearch.service - Elasticsearch

● elasticsearch.service - Elasticsearch

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

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

活动:失败(结果:退出代码)自 UTC 时间周五 2019-11-01 06:09:54 起;12 秒前

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

Docs: http://www.elastic.co

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

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

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

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

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

I have removed/purged Elasticsearch from my machine and re-installed several times, but it doesn't seem to fix the issue.

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

I have tried to modify the default network.host and host.port settings in /etc/default/elasticsearch to network.host: 0.0.0.0 and http.port: 9200 to fix the issue, but no luck yet.

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

I need some assistance. Thanks in advance.

推荐答案

我是这样解决的

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

Firstly, Open /etc/elasticsearch/elasticsearch.yml in your nano editor using the command below:

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.

In order for Elasticsearch to allow connections from localhost, and to also listen on port 9200.

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

Next, run the code below to determine the cause of the error:

journalctl -xe

错误 1

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

There is insufficient memory for the Java Runtime Environment to continue

解决方案

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

As a JVM application, the Elasticsearch main server process only utilizes memory devoted to the JVM. The required memory may depend on the JVM used (32- or 64-bit). The memory used by JVM usually consists of:

  • 堆空间(通过-Xms-Xmx配置)
  • 元空间(受可用本机内存量的限制)
  • 内部 JVM(通常为数十 Mb)
  • 依赖于操作系统的内存功能,例如内存映射文件.
  • heap space (configured via -Xms and -Xmx)
  • metaspace (limited by the amount of available native memory)
  • internal JVM (usually tens of Mb)
  • OS-dependent memory features like memory-mapped files.

Elasticsearch 主要依赖于堆内存,通过将-Xms-Xmx(堆空间)选项手动设置为运行 Elasticsearch 服务器的 JVM.

Elasticsearch mostly depends on the heap memory, and this setting manually by passing the -Xms and -Xmx(heap space) option to the JVM running the Elasticsearch server.

解决方案

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

Open /etc/elasticsearch/jvm.options in your nano editor using the command below:

sudo nano /etc/elasticsearch/jvm.options

首先,取消注释XmxXms

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

Next, modify the value of -Xms and -Xmx to no more than 50% of your physical RAM. The value for these settings depends on the amount of RAM available on your server and Elasticsearch requires memory for purposes other than the JVM heap and it is important to leave space for this.

最低要求:如果您的物理 RAM <= 1 GB

Minimum requirements: If your physical RAM is <= 1 GB

那么,您的设置应该是:

Then, your settings should be:

# 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<= 4 GB

Medium requirements: If your physical RAM is >= 2 GB but <= 4 GB

那么,您的设置应该是:

Then, your settings should be:

# 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<= 8 GB

Large requirements: If your physical RAM is >= 4 GB but <= 8 GB

那么,您的设置应该是:

Then, your settings should be:

# 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 OR -Xms4g-Xmx4g 甚至更高以获得更好的性能您的可用资源.

Note: If your physical RAM is >= 8 GB you can decide how much heap space you want to allocate to Elasticsearch. You can allocate -Xms2048m and -Xmx2048m OR -Xms4g and -Xmx4g or even higher for better performance based on your available resources.

错误 2

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

Initial heap size not equal to the maximum heap size

解决方案

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

Ensure the value of -Xms and Xmx are equal. That is, say, you are using the minimum requirements since your physical RAM is <= 1 GB, instead of this:

# 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] 之一

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

解决方案

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

Open /etc/elasticsearch/elasticsearch.yml in your nano editor using the command below:

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 的状态:

Once all the errors are fixed run the command below to start and confirm the status of Elasticsearch:

sudo systemctl start elasticsearch
sudo systemctl status elasticsearch

仅此而已.

我希望这会有所帮助

这篇关于Elasticsearch:elasticsearch.service 的作业失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆