Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Port issues with Vagrant and Elasticsearch

I've been trying to install Elasticsearch in a brand new Ubuntu box (ubuntu/trusty64) using Vagrant.

This is what I get when I run curl localhost:9200 in my guest machine

{
  "name" : "Base",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.3.4",
    "build_hash" : "e455fd0c13dceca8dbbdbb1665d068ae55dabe3f",
    "build_timestamp" : "2016-06-30T11:24:31Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.0"
  },
  "tagline" : "You Know, for Search"
}

It seems good. But when I run the same command on my host, this is what I get:

curl: (52) Empty reply from server

Here are my port forwarding data (vagrant port):

    22 (guest) => 2222 (host)
    80 (guest) => 8080 (host)
  9200 (guest) => 9200 (host)
  9300 (guest) => 9300 (host)

So, ports seems to be properly forwarded and Elasticsearch service in guest VM is running good.

Here's my firewall configuration in the guest VM (sudo ufw status)

To                         Action      From
--                         ------      ----
22                         ALLOW       Anywhere
9200/tcp                   ALLOW       Anywhere
9300/tcp                   ALLOW       Anywhere
22 (v6)                    ALLOW       Anywhere (v6)
9200/tcp (v6)              ALLOW       Anywhere (v6)
9300/tcp (v6)              ALLOW       Anywhere (v6)

I've also have an Apache server that runs with no problem when using localhost:8080 (forwarded to localhost:80)

Also, nothing weird in logs: cat /var/log/elasticsearch/elasticsearch.log:

[2016-07-12 18:49:37,838][INFO ][node                     ] [Raymond Sikorsky] version[2.3.4], pid[2138], build[e455fd0/2016-06-30T11:24:31Z]
[2016-07-12 18:49:37,839][INFO ][node                     ] [Raymond Sikorsky] initializing ...
[2016-07-12 18:49:38,439][INFO ][plugins                  ] [Raymond Sikorsky] modules [lang-groovy, reindex, lang-expression], plugins [], sites []
[2016-07-12 18:49:38,464][INFO ][env                      ] [Raymond Sikorsky] using [1] data paths, mounts [[/ (/dev/sda1)]], net usable_space [35.8gb], net total_space [39.3gb], spins? [possibly], types [ext4]
[2016-07-12 18:49:38,464][INFO ][env                      ] [Raymond Sikorsky] heap size [1007.3mb], compressed ordinary object pointers [true]
[2016-07-12 18:49:38,464][WARN ][env                      ] [Raymond Sikorsky] max file descriptors [65535] for elasticsearch process likely too low, consider increasing to at least [65536]
[2016-07-12 18:49:40,455][INFO ][node                     ] [Raymond Sikorsky] initialized
[2016-07-12 18:49:40,455][INFO ][node                     ] [Raymond Sikorsky] starting ...
[2016-07-12 18:49:40,521][INFO ][transport                ] [Raymond Sikorsky] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300}, {[::1]:9300}
[2016-07-12 18:49:40,527][INFO ][discovery                ] [Raymond Sikorsky] elasticsearch/HqATev5kScKOXLXdl44ZLA
[2016-07-12 18:49:43,585][INFO ][cluster.service          ] [Raymond Sikorsky] new_master {Raymond Sikorsky}{HqATev5kScKOXLXdl44ZLA}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-join(elected_as_master, [0] joins received)
[2016-07-12 18:49:43,622][INFO ][http                     ] [Raymond Sikorsky] publish_address {127.0.0.1:9200}, bound_addresses {127.0.0.1:9200}, {[::1]:9200}
[2016-07-12 18:49:43,622][INFO ][node                     ] [Raymond Sikorsky] started
[2016-07-12 18:49:43,625][INFO ][gateway                  ] [Raymond Sikorsky] recovered [0] indices into cluster_state

I know just the basics of servers. Am I missing something? Maybe the issue has nothing to do with ports?

like image 327
Ignacio Avatar asked Jul 12 '16 16:07

Ignacio


1 Answers

I run the following on ubuntu box and install latest version of elastic search to try (there has been some breaking changed in 2.x). Here are the steps I've done to make it work

change the network binding.

That is one of the breaking change

Elasticsearch 2.x will only bind to localhost by default. It will try to bind to both 127.0.0.1 (IPv4) and [::1] (IPv6), but will work happily in environments where only IPv4 or IPv6 is available. This change prevents Elasticsearch from trying to connect to other nodes on your network unless you specifically tell it to do so

like it is mentioned here

I wanted to add an additional note that often this is caused by the server within the VM because it binds to 127.0.0.1, which is loopback. You'll want to make sure that the server is bound to 0.0.0.0 so that all interfaces can access it.

This is the case here and we need to change the host property. open the /etc/elasticsearch/elasticsearch.yml and add

network.bind_host: 0
network.host: 0.0.0.0
like image 119
Frederic Henri Avatar answered Nov 07 '22 20:11

Frederic Henri