我是这样解决的
首先,使用以下命令在您的 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
首先,取消注释Xmx和Xms的值
接下来,将 -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
初始堆大小不等于最大堆大小
解决方案
确保-Xms 和Xmx 的值相等。也就是说,您使用的是最低要求,因为您的物理 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
就是这样。
我希望这会有所帮助