Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch: Failed to connect to localhost port 9200 - Connection refused

By default it should bind to all local addresses. So, assuming you don't have a network layer issue with firewalls, the only ES setting I can think to check is network.bind_host and make sure it is either not set or is set to 0.0.0.0 or ::0 or to the correct IP address for your network.

Update: per comments in ES 2.3 you should set network.host instead.


Edit /etc/elasticsearch/elasticsearch.yml and add the following line:

network.host: 0.0.0.0

This will "unset" this parameter and will allow connections from other IPs.


Tried everything on this page, and only instructions from here helped.

in /etc/default/elasticsearch, make sure these are un-commented:

START_DAEMON=true
ES_USER=elasticsearch
ES_GROUP=elasticsearch
LOG_DIR=/var/log/elasticsearch
DATA_DIR=/var/lib/elasticsearch
WORK_DIR=/tmp/elasticsearch
CONF_DIR=/etc/elasticsearch
CONF_FILE=/etc/elasticsearch/elasticsearch.yml
RESTART_ON_UPGRADE=true

make sure /var/lib/elasticsearch is owned by elasticsearch user:

chown -R elasticsearch:elasticsearch /var/lib/elasticsearch/

In my case elasticsearch was started. But still had

curl: (7) Failed to connect to localhost port 9200: Connection refused

The following command was unsuccessful

sudo service elasticsearch restart

In order to make it work, I had to run instead

sudo systemctl restart elasticsearch

Then it went all fine.