Connection refused on Ubuntu

Guys,

I had an old install and it was not working. I got a "Connection refused" when trying

$ curl -X GET http://localhost:9200

So, I purged my install and installed it again (now with 2.x). After that, I must got the same message, no matter if I stop and start the service. So, after using service elasticsearch start and then

sudo -u elasticsearch /usr/share/elasticsearch/bin/elasticsearch -d -p /var/run/elasticsearch.pid --default.config=/etc/elasticsearch/elasticsearch.yml --default.path.home=/usr/share/elasticsearch --default.path.logs=/var/log/elasticsearch --default.path.data=/var/lib/elasticsearch --default.path.work=/tmp/elasticsearch --default.path.conf=/etc/elasticsearch

it worked, what I'm missing here? Seems that the Ubuntu services can't start it.

I also configured elasticsearch.yml with network.host: localhost and http.port: 9200.

Thanks.

There were some changes in 2.X, see Networking | Elasticsearch Guide [8.11] | Elastic

But that should work. Can you start ES directly?

Hey, thanks for answering.

I noticed some of the changes, that's why I tried to change elasticsearch.yml, but didn't noticed that now localhost should be _local_, thanks!

So, first I tried to start it with the current configuration and tried to accesss with curl ... and it worked!:

$ sudo service elasticsearch start
$ sudo service elasticsearch status
● elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: enabled)
   Active: active (running) 
$ curl -X GET http://localhost:9200
{
  "name" : "Atalon",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.1.0",
    "build_hash" : "72cd1f1a3eee09505e036106146dc1949dc5dc87",
    "build_timestamp" : "2015-11-18T22:40:03Z",
    "build_snapshot" : false,
    "lucene_version" : "5.3.1"
  },
  "tagline" : "You Know, for Search"
}

Yesterday no matter what I did it won't start without the longer command line. But now I'm a different network (wireless now, cable yesterday), can have something related to it?

But, after changing localhost to _local_, I got the connection refused again. :frowning:
Checking with netstat, I got some interesting results:

tcp6       0      0 ::1:9200                :::*                    OUÇA       -               
tcp6       0      0 127.0.0.1:9200          :::*                    OUÇA       -               
tcp6       0      0 ::1:9300                :::*                    OUÇA       -    

So, I tried to use IPV6 and ...

$ curl -X GET http://[::1]:9200
{
  "name" : "Coldblood",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.1.0",
    "build_hash" : "72cd1f1a3eee09505e036106146dc1949dc5dc87",
    "build_timestamp" : "2015-11-18T22:40:03Z",
    "build_snapshot" : false,
    "lucene_version" : "5.3.1"
  },
  "tagline" : "You Know, for Search"
}

And after this, IPV4 worked again! Checking with netstat again, I got an interesing result on remote address (btw, "ouça" is "listen"):

tcp        0      0 127.0.0.1:58958         127.0.0.1:9200          TIME_WAIT   -               
tcp6       0      0 ::1:9200                :::*                    OUÇA       -               
tcp6       0      0 127.0.0.1:9200          :::*                    OUÇA       -               
tcp6       0      0 ::1:9300                :::*                    OUÇA       -               
tcp6       0      0 127.0.0.1:9300          :::*                    OUÇA       -  

I tried curl -X GET http://localhost:58958 too but got connection refused, but localhost and 127.0.0.1 works. Then I changed network.host to _local:ipv4_ and checked again. On netstat, just IPV6:

tcp6       0      0 127.0.0.1:9200          :::*                    OUÇA       -               
tcp6       0      0 127.0.0.1:9300          :::*                    OUÇA       -    

But after the first curl request, seems that the remote address is bound, and it worked again!

tcp        0      0 127.0.0.1:59230         127.0.0.1:9200          TIME_WAIT   -               
tcp6       0      0 127.0.0.1:9200          :::*                    OUÇA       -               
tcp6       0      0 127.0.0.1:9300          :::*                    OUÇA       -     

Not really sure what is happening. :slight_smile: