Elasticsearch error curl: (7) Failed to connect to localhost port 9200: Connection refused but localhost:9200 works on browser
Solution 1
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
Solution 2
In my case, the problem is with java version, i installed open-jdk 11 previously. Thats creating the issue while starting the service. I changed it open-jdk 8 and it started working
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"
}
kabrice
Updated on June 29, 2022Comments
-
kabrice almost 2 years
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
whilelocalhost: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 ?
-
kabrice about 6 years
/etc/elasticsearch/
doesn't exist ! I've installed elasticsearch withpip install elasticsearch==5.5.2
-
Lupanoide about 6 yearsok you have installed python library to manage query on elasticsearch. But you have installed also elasticsearch package - deb or tar.gz -on localhost because you have active an elasticsearch service - it responds on sudo service elasticsearch status and on localhost:9200/_nodes and you can visualize localhost:9200 on browser. ES python library is not ES DB! one is high level client library, and the other one is ES server.
-
Lupanoide about 6 yearsthe machine that doesn't have/etc/elasticsearch is the same that responds to you typing sudo service elasticsearch status?
-
kabrice about 6 yearsYep, I work with vagrant where I've created a ubuntu virtualen
-
Lupanoide about 6 yearsAh ok. I don't know how ubuntu virtualen works. Probably the paths are different on a virtualenv. And I can't help you for that, sorry
-
Lupanoide about 6 yearsI have another idea.. where is your elasticsearch.yml? jvm.options is in the same folder
-
kabrice about 6 yearsI just found out that Elasticsearch isn't installed. But it's very weird because
http://localhost:9200/
continue to work and display stuffs on my windows browser while I've shut down vagrant -
kabrice about 6 yearsRestarting my computer and doing your method made everything work. Thank you for your time