我目前正在尝试设置 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.host
和 host.port
/etc/default/elasticsearch
中的设置|至 network.host: 0.0.0.0
和 http.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
配置)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/