Cannot access Elasticsearch 2.0 in Vagrant VM from host OS
Asked Answered
F

2

8

I'm trying to get Elasticsearch 2.0 up and running in a Vagrant VM. The method I was using for 1.7 no longer works, so I'm trying to update my method. I can get ES 2.0 installed in the VM, and it seems to work fine from within the VM, but I can't access it from outside the VM. It's like the VM isn't port-forwarding port 9200 for some reason, even though I'm telling it to. So I'm trying to figure out what I'm doing wrong.

Given this Vagrantfile:

Vagrant.configure(2) do |config|

  config.vm.box = "hashicorp/precise64"
  config.vm.hostname = "ES-2.0.0"
  config.vm.provision :shell, path: "bootstrap.sh"
  config.vm.network :forwarded_port, host: 9200, guest: 9200
  config.vm.synced_folder "/Users/sloan/code", "/srv/code"

  config.vm.provider "virtualbox" do |v|
    v.memory = 2048
    v.cpus = 1
    v.name = config.vm.hostname.to_s
  end

end

my old bootstrap.sh works fine:

#!/usr/bin/env bash

sudo apt-get update
sudo apt-get upgrade

# install openjdk-7 
sudo apt-get purge openjdk*
sudo apt-get -y install openjdk-7-jdk

# install curl
sudo apt-get -y install curl

# install Elasticsearch 1.7.3
wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.3.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
sudo mv elasticsearch-* elasticsearch
sudo mv elasticsearch /usr/local/share

# set up ES as service
curl -L http://github.com/elasticsearch/elasticsearch-servicewrapper/tarball/master | tar -xz
sudo mv *servicewrapper*/service /usr/local/share/elasticsearch/bin/
rm -Rf *servicewrapper*
sudo /usr/local/share/elasticsearch/bin/service/elasticsearch install
sudo ln -s 'readlink -f /usr/local/share/elasticsearch/bin/service/elasticsearch' /usr/local/bin/rcelasticsearch

# start ES service
sudo service elasticsearch start

# enable cors (to be able to use Sense)
sudo echo "http.cors.enabled: true" >> /usr/local/share/elasticsearch/config/elasticsearch.yml
# enable dynamic scripting
sudo echo "script.disable_dynamic: false" >> /usr/local/share/elasticsearch/config/elasticsearch.yml

sudo service elasticsearch restart

I mean that it works in the sense that, from the host OS (OS X 10.9.5) I can curl ES just fine:

es173 > curl localhost:9200
{
  "status" : 200,
  "name" : "Gibbon",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "1.7.3",
    "build_hash" : "05d4530971ef0ea46d0f4fa6ee64dbc8df659682",
    "build_timestamp" : "2015-10-15T09:14:17Z",
    "build_snapshot" : false,
    "lucene_version" : "4.10.4"
  },
  "tagline" : "You Know, for Search"
}

But when I use this new version of bootstrap.sh which I cooked up by trying to follow the Elasticsearch documents (always an arduous task):

#!/usr/bin/env bash

sudo apt-get update
sudo apt-get upgrade

# install curl
sudo apt-get -y install curl

# install openjdk-7 
sudo apt-get purge openjdk*
sudo apt-get -y install openjdk-7-jdk

wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb http://packages.elastic.co/elasticsearch/2.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list
sudo apt-get update && sudo apt-get install elasticsearch

sudo update-rc.d elasticsearch defaults 95 10
sudo /etc/init.d/elasticsearch start

# enable cors (to be able to use Sense)
sudo echo "http.cors.enabled: true" >> /etc/elasticsearch/elasticsearch.yml
# enable dynamic scripting
sudo echo "script.disable_dynamic: false" >> /etc/elasticsearch/elasticsearch.yml

sudo /etc/init.d/elasticsearch restart

does NOT work. From inside the VM, curl localhost:9200 works as expected, but from the host OS I get:

es200 > curl localhost:9200
curl: (52) Empty reply from server

What am I missing here? Can anybody tell me why isn't the new version port forwarding?

Fisc answered 31/10, 2015 at 16:35 Comment(6)
I don't know how the ES network specific configuration is in your setup, but that would be the first I'd look at. Because there is a big change in 2.0 mentioned in the documentation, meaning this: Currently an elasticsearch node may be bound to multiple addresses, but only publishes one. This wasn't like that before. One way of doing the same in 2.0 seems to be to set network.bind_host: 0.Improbability
Does that go in elasticsearch.yml? I tried it, doesn't seem to have helped.Fisc
How do I find out what the "ES network specific configuration" is in my setup? Other than adding two (now three) settings to /etc/elasticsearch/elasticsearch.yml, I haven't changed the default settings in any way.Fisc
try network.host: 0.0.0.0 as mentioned hereHoisch
Whoops, I had another problem (script.disable_dynamic: false), and once I fixed that, either of your answers work. So thanks to you both!Fisc
Still having trouble with cors, though. I'm using this code below, but I still can't hit ES from local javascript.Fisc
F
8

Upon examining the ES log file (cat /var/log/elasticsearch/elasticsearch.log) I found that script.disable_dynamic: false was breaking things:

[2015-10-31 19:58:54,428][INFO ][node                     ] [Yuri Topolov] version[2.0.0], pid[9826], build[de54438/2015-10-22T08:09:48Z]
[2015-10-31 19:58:54,428][INFO ][node                     ] [Yuri Topolov] initializing ...
[2015-10-31 19:58:54,537][INFO ][plugins                  ] [Yuri Topolov] loaded [], sites []
[2015-10-31 19:58:54,630][INFO ][env                      ] [Yuri Topolov] using [1] data paths, mounts [[/ (/dev/mapper/precise64-root)]], net usable_space [72.3gb], net total_space [78.8gb], spins? [possibly], types [ext4]
[2015-10-31 19:58:58,668][ERROR][bootstrap                ] Guice Exception: java.lang.IllegalArgumentException: script.disable_dynamic is not a supported setting, replace with fine-grained script settings.
Dynamic scripts can be enabled for all languages and all operations by replacing `script.disable_dynamic: false` with `script.inline: on` and `script.indexed: on` in elasticsearch.yml
    at org.elasticsearch.script.ScriptService.<init>(ScriptService.java:146)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at <<<guice>>>
    at org.elasticsearch.node.Node.<init>(Node.java:198)
    at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:145)
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170)
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:270)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)

I added that setting after I had my problem, but before I initially tried the suggestions in the comments, and so ES was failing. Fixing this setting didn't fix my original problem, but it was obscuring the solution.

Anyway, here is the bootstrap.sh file that is working for me:

#!/usr/bin/env bash

sudo apt-get update
sudo apt-get upgrade

# install curl
sudo apt-get -y install curl

# install openjdk-7 
sudo apt-get purge openjdk*
sudo apt-get -y install openjdk-7-jdk

# install ES
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb http://packages.elastic.co/elasticsearch/2.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list
sudo apt-get update && sudo apt-get install elasticsearch
sudo update-rc.d elasticsearch defaults 95 10

# either of the next two lines is needed to be able to access "localhost:9200" from the host os
sudo echo "network.bind_host: 0" >> /etc/elasticsearch/elasticsearch.yml
sudo echo "network.host: 0.0.0.0" >> /etc/elasticsearch/elasticsearch.yml

# enable cors (to be able to use Sense)
sudo echo "http.cors.enabled: true" >> /etc/elasticsearch/elasticsearch.yml
sudo echo "http.cors.allow-origin: /https?:\/\/localhost(:[0-9]+)?/" >> /etc/elasticsearch/elasticsearch.yml

# enable dynamic scripting
sudo echo "script.inline: on" >> /etc/elasticsearch/elasticsearch.yml
sudo echo "script.indexed: on" >> /etc/elasticsearch/elasticsearch.yml

sudo /etc/init.d/elasticsearch start
Fisc answered 31/10, 2015 at 20:29 Comment(1)
probably could enable all domains and see http.cors.allow-origin:/https?:\/\/.*/Hoisch
I
12

In your /etc/elasticsearch/elasticsearch.yml configuration file set network.host: 0.0.0.0 so that elasticsearch is accessible outside of localhost. Remember to do a service elasticsearch restart.

Inessive answered 14/1, 2016 at 15:57 Comment(1)
Restart Elasticsearch with systemd by sudo systemctl restart elasticsearch.service.Befool
F
8

Upon examining the ES log file (cat /var/log/elasticsearch/elasticsearch.log) I found that script.disable_dynamic: false was breaking things:

[2015-10-31 19:58:54,428][INFO ][node                     ] [Yuri Topolov] version[2.0.0], pid[9826], build[de54438/2015-10-22T08:09:48Z]
[2015-10-31 19:58:54,428][INFO ][node                     ] [Yuri Topolov] initializing ...
[2015-10-31 19:58:54,537][INFO ][plugins                  ] [Yuri Topolov] loaded [], sites []
[2015-10-31 19:58:54,630][INFO ][env                      ] [Yuri Topolov] using [1] data paths, mounts [[/ (/dev/mapper/precise64-root)]], net usable_space [72.3gb], net total_space [78.8gb], spins? [possibly], types [ext4]
[2015-10-31 19:58:58,668][ERROR][bootstrap                ] Guice Exception: java.lang.IllegalArgumentException: script.disable_dynamic is not a supported setting, replace with fine-grained script settings.
Dynamic scripts can be enabled for all languages and all operations by replacing `script.disable_dynamic: false` with `script.inline: on` and `script.indexed: on` in elasticsearch.yml
    at org.elasticsearch.script.ScriptService.<init>(ScriptService.java:146)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at <<<guice>>>
    at org.elasticsearch.node.Node.<init>(Node.java:198)
    at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:145)
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170)
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:270)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)

I added that setting after I had my problem, but before I initially tried the suggestions in the comments, and so ES was failing. Fixing this setting didn't fix my original problem, but it was obscuring the solution.

Anyway, here is the bootstrap.sh file that is working for me:

#!/usr/bin/env bash

sudo apt-get update
sudo apt-get upgrade

# install curl
sudo apt-get -y install curl

# install openjdk-7 
sudo apt-get purge openjdk*
sudo apt-get -y install openjdk-7-jdk

# install ES
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb http://packages.elastic.co/elasticsearch/2.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list
sudo apt-get update && sudo apt-get install elasticsearch
sudo update-rc.d elasticsearch defaults 95 10

# either of the next two lines is needed to be able to access "localhost:9200" from the host os
sudo echo "network.bind_host: 0" >> /etc/elasticsearch/elasticsearch.yml
sudo echo "network.host: 0.0.0.0" >> /etc/elasticsearch/elasticsearch.yml

# enable cors (to be able to use Sense)
sudo echo "http.cors.enabled: true" >> /etc/elasticsearch/elasticsearch.yml
sudo echo "http.cors.allow-origin: /https?:\/\/localhost(:[0-9]+)?/" >> /etc/elasticsearch/elasticsearch.yml

# enable dynamic scripting
sudo echo "script.inline: on" >> /etc/elasticsearch/elasticsearch.yml
sudo echo "script.indexed: on" >> /etc/elasticsearch/elasticsearch.yml

sudo /etc/init.d/elasticsearch start
Fisc answered 31/10, 2015 at 20:29 Comment(1)
probably could enable all domains and see http.cors.allow-origin:/https?:\/\/.*/Hoisch

© 2022 - 2024 — McMap. All rights reserved.