0

Hi I've been trying almost everything to access my elasticsearch database from my vagrant VM. In this forum there are plenty of threads but none of them seems to work, that's why I'm posting.

The thing is that if I type: curl -X GET http://127.0.0.1:9200 outside of vagrant I'll get the content of my elastisearch localhost.

Inside of vagrant I connect to my mongodb databases through:

mongo 10.0.2.2:27017 

Therefore, and following one of these answers:

Vagrant reverse port forwarding?

I expected that by changing this:

vagrant ssh -- -R 12345:localhost:80

into this:

vagrant ssh -- -R 12345:10.0.2.2:9200

I would be able to access my elasticsearch from vagrant if I typed:

curl -X GET http://10.0.2.2:9200

but I'm not getting anything...

This is the content of my vagrant file:

Vagrant.configure(2) do |config|
  # config.vm.box = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
  config.vm.box = "xenial-amd64"
  config.vm.box_url = "https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-vagrant.box"
  config.vm.hostname = "proxy"


  config.vm.network "private_network", ip: "192.168.90.103"



  config.vm.provision :shell, :path => "provisions/shell/bootstrap.sh"
end
Community
  • 1
  • 1
Defoe
  • 371
  • 1
  • 5
  • 17

1 Answers1

4

You need to make sure your vagrant-elasticsearch is listening on all network interfaces (not only localhost)

Edit the file /etc/elasticsearch/elasticsearch.yml and change a few things

network.bind_host: 0
network.host: 0.0.0.0

# I do that for cors
http.cors.enabled: true
http.cors.allow-origin: /https?:\/\/.*/

Make sure to restart elasticsearch after the changes. This will allow you to access your vagrant-elasticsearch from your host machine.

I think the easiest to work with is to set a static IP to your VM, you can edit your Vagrantfile and have (just an example of IP address)

Vagrant.configure("2") do |config|
  ...
  config.vm.network "private_network", ip: "192.168.90.103"
  ...
end

then you can easily access elasticsearch using http://192.168.90.103:9200

Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
  • I'm getting this error: /sbin/ifdown eth1 2> /dev/null THis is because of the config.vm.network "private_network", ip: "192.168.90.103" line. If I remove it I won't get any errors but it doesn't solve my problem – Defoe Apr 05 '17 at 15:17
  • hum ... can you post your Vagrantfile and provide vagrant version you use – Frederic Henri Apr 05 '17 at 15:21
  • ok and vagrant version ? are you on the latest 1.9.x version ? – Frederic Henri Apr 05 '17 at 15:38
  • vagrant 1.8.x had such [issues](https://github.com/mitchellh/vagrant/issues/7155) so upgrading will help you – Frederic Henri Apr 05 '17 at 15:41
  • I updated it, I don't get the error thanks to the newest version BUT running: curl -X GET http://192.168.90.103:9200 inside of vagrant doesn't retrieve anything... :( – Defoe Apr 05 '17 at 16:37
  • hum ... can you confirm with the new setup that `curl -X GET 127.0.0.1:9200` inside the VM works well ? does it work from the host ? – Frederic Henri Apr 05 '17 at 17:14
  • @ApoorvNag thats the first thing mentioned in the answer – Frederic Henri Nov 13 '18 at 13:51