首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Elasticsearch错误curl:(7)无法连接到localhost端口9200:连接被拒绝,但localhost:9200可以在浏览器上工作

Elasticsearch错误curl:(7)无法连接到localhost端口9200:连接被拒绝,但localhost:9200可以在浏览器上工作
EN

Stack Overflow用户
提问于 2018-02-21 18:49:19
回答 3查看 15.3K关注 0票数 3

我正在尝试按照这个tutorial将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文件的概述:

代码语言:javascript
运行
复制
# 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有什么问题?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-02-21 23:59:59

ok eureka!,你有一个java堆空间错误。看看这个错误:

代码语言:javascript
运行
复制
# There is insufficient memory for the Java Runtime Environment to continue

你可以增加/减少-我不知道问题出现是因为你的机器内存太少,es无法启动,或者你分配给es的内存太少- java虚拟机编辑这个文件/etc/elasticsearch/jvm.options分配2 GB内存的弹性专用空间,你应该改变:

代码语言:javascript
运行
复制
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

 -Xms2g
 -Xmx2g

然后,您必须重新启动服务

代码语言:javascript
运行
复制
sudo service elasticsearch restart

然后使用curl重试

票数 6
EN

Stack Overflow用户

发布于 2019-10-30 14:12:38

这是在启动服务时产生的问题。我把它改成开放的jdk 8,它开始工作了

代码语言:javascript
运行
复制
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"
}
票数 1
EN

Stack Overflow用户

发布于 2019-10-04 16:02:33

我也有同样的问题,但与卢帕诺德回答的原因不同。将我的发现添加给其他人。

我在ip:9200上的连接也被拒绝,但localhost:9200正在工作。当我尝试"network.host : 0.0.0.0“时,服务不会启动。我将值更改为"http.host“,如下所示,这允许服务启动并通过ip调用。

/etc/elasticsearch/elasticsearch.yml

代码语言:javascript
运行
复制
# ---------------------------------- 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
#

之前:

代码语言:javascript
运行
复制
[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

之后:

代码语言:javascript
运行
复制
[root@Loki-03 ~]# systemctl restart elasticsearch.service 
[root@Loki-03 ~]# curl 192.168.1.199:9200
    {
      "name" : "Loki-03",

希望这能有所帮助。另外,我正在运行:

代码语言:javascript
运行
复制
  "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",
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48903999

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档