我正在尝试将Elasticsearch 5.5.2连接到本教程之后的Django 2项目:
运行时:终端上的curl -X GET 'http://localhost:9200'
时,我得到了此错误:curl: (7) Failed to connect to localhost port 9200: Connection refused
时localhost:9200
在我的浏览器上运行良好。
这是我的elasticsearch.yml文件的概述:
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
# Elasticsearch performs poorly when the system is swapping the memory.
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 3
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
/var/log/elasticsearch/
是空的。
请卷曲有什么问题?
好的eureka!,您有一个Java堆空间错误。查看该错误:
# There is insufficient memory for the Java Runtime Environment to continue
您可以增加/减少 - 我不知道问题是否出现,因为您的机器的RAM太少,ES无法启动,或者您将RAM太少分配给ES-用于Java虚拟机中弹性的空间编辑此文件/etc/elasticsearch/jvm.options
要分配2 GB的RAM,您应该更改:
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms2g
-Xmx2g
然后您必须重新启动服务
sudo service elasticsearch restart
,然后用卷曲
在我的情况下,问题是在Java版本中,我先前安装了Open-jdk 11。在开始服务时创建问题。我更改了Open-jdk 8,它开始工作
curl localhost:9200
{
"name" : "My First Node",
"cluster_name" : "mycluster1",
"version" : {
"number" : "2.3.1",
"build_hash" : "bd980929010aef404e7cb0843e61d0665269fc39",
"build_timestamp" : "2016-04-04T12:25:05Z",
"build_snapshot" : false,
"lucene_version" : "5.5.0"
},
"tagline" : "You Know, for Search"
}
我遇到了相同的问题,但与lupanoide回答的原因不同。为他人添加我的发现。
我也在IP上拒绝了连接:9200,但Localhost:9200正在工作。当我尝试" Network.Host:0.0.0.0"时,服务将无法启动。我将值更改为" http. -host",如下所示,这允许该服务启动并通过IP调用。
/etc/elasticsearch/elasticsearch.yml
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
http.host: 192.168.1.199
#
# Set a custom port for HTTP:
#
http.port: 9200
#
之前:
[root@Loki-03 ~]# curl localhost:9200
"name" : "Loki-03"
[root@Loki-03 ~]# curl 192.168.1.199:9200
curl: (7) Failed to connect to 192.168.1.199 port 9200: Connection refused
之后:
[root@Loki-03 ~]# systemctl restart elasticsearch.service
[root@Loki-03 ~]# curl 192.168.1.199:9200
{
"name" : "Loki-03",
希望这会有所帮助。另外,我正在运行:
"version" : {
"number" : "7.4.0",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "22e1767283e61a198cb4db791ea66e3f11ab9910",
"build_date" : "2019-09-27T08:36:48.569419Z",
"build_snapshot" : false,
"lucene_version" : "8.2.0",