Elasticsearch error curl: (7) Failed to connect to localhost port 9200: Connection refused but localhost:9200 works on browser

kabrice picture kabrice · Feb 21, 2018 · Viewed 12.7k times · Source

I'm trying to connect Elasticsearch 5.5.2 to a Django 2 project following this tutorial :

When running : curl -X GET 'http://localhost:9200' on terminal, I got this error : curl: (7) Failed to connect to localhost port 9200: Connection refused while localhost:9200 works very well on my browser.

Here is an overview of my elasticsearch.yml file :

# 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/ is empty.

Please what's wrong with curl ?

Answer

Lupanoide picture Lupanoide · Feb 21, 2018

ok eureka!, You have a java heap space error. Look at that error:

# There is insufficient memory for the Java Runtime Environment to continue

You can increase/decrease - i don't know if the problem appears because your machine has too few RAM and es could not start, or you had allocated too few ram to es - the space dedicated to elastic in java virtual machine editing this file /etc/elasticsearch/jvm.options To allocate 2 GB of RAM, you should change:

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

 -Xms2g
 -Xmx2g

Then you have to restart the service

sudo service elasticsearch restart

And try again with curl