Elasticsearch 错误卷曲:(7) 无法连接到本地主机端口 9200:连接被拒绝但 localhost:9200 在浏览器上有效
Elasticsearch error curl: (7) Failed to connect to localhost port 9200: Connection refused but localhost:9200 works on browser
我正在尝试将 Elasticsearch 5.5.2 连接到 Django 2 项目tutorial:
当 运行 : 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/
为空。
请问 curl 有什么问题?
好的,我发现了!,你有一个 java 堆 space 错误。看看那个错误:
# There is insufficient memory for the Java Runtime Environment to continue
可以increase/decrease - 不知道是不是因为你的机器RAM太少导致es无法启动,或者你给es分配的ram太少 - space 专用于 java 虚拟机中的 elastic 正在编辑此文件 /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
然后用 curl 再试一次
我遇到了同样的问题,但与 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",
就我而言,问题出在 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"
}
我正在尝试将 Elasticsearch 5.5.2 连接到 Django 2 项目tutorial:
当 运行 : 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/
为空。
请问 curl 有什么问题?
好的,我发现了!,你有一个 java 堆 space 错误。看看那个错误:
# There is insufficient memory for the Java Runtime Environment to continue
可以increase/decrease - 不知道是不是因为你的机器RAM太少导致es无法启动,或者你给es分配的ram太少 - space 专用于 java 虚拟机中的 elastic 正在编辑此文件 /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
然后用 curl 再试一次
我遇到了同样的问题,但与 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",
就我而言,问题出在 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"
}