无法从主机 OS 访问 Vagrant VM 中的 Elasticsearch 2.0
Cannot access Elasticsearch 2.0 in Vagrant VM from host OS
我正在尝试在 Vagrant VM 中启动 Elasticsearch 2.0 和 运行。我用于 1.7 的方法不再有效,所以我正在尝试更新我的方法。我可以在 VM 中安装 ES 2.0,它似乎在 VM 中运行良好,但我无法从 VM 外部访问它。这就像虚拟机出于某种原因不是端口转发端口 9200,即使我告诉它。所以我想弄清楚我做错了什么。
鉴于此 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
我的旧 bootstrap.sh
工作正常:
#!/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
我的意思是它的工作原理是,从主机 OS (OS X 10.9.5) 我可以很好地卷曲 ES:
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"
}
但是当我使用这个新版本的 bootstrap.sh
时,我试图遵循 Elasticsearch 文档(总是一项艰巨的任务):
#!/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
无效。从 VM 内部,curl localhost:9200
按预期工作,但从主机 OS 我得到:
es200 > curl localhost:9200
curl: (52) Empty reply from server
我在这里错过了什么?谁能告诉我为什么新版本没有端口转发?
检查 ES 日志文件 (cat /var/log/elasticsearch/elasticsearch.log
) 后,我发现 script.disable_dynamic: false
破坏了一些东西:
[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)
我在遇到问题后添加了该设置,但在我最初尝试评论中的建议之前,所以 ES 失败了。修复此设置并没有解决我原来的问题,但它掩盖了解决方案。
无论如何,这是为我工作的 bootstrap.sh
文件:
#!/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
在您的 /etc/elasticsearch/elasticsearch.yml
配置文件中设置 network.host: 0.0.0.0
以便 elasticsearch
可以在 localhost
之外访问。记得做一个service elasticsearch restart
.
我正在尝试在 Vagrant VM 中启动 Elasticsearch 2.0 和 运行。我用于 1.7 的方法不再有效,所以我正在尝试更新我的方法。我可以在 VM 中安装 ES 2.0,它似乎在 VM 中运行良好,但我无法从 VM 外部访问它。这就像虚拟机出于某种原因不是端口转发端口 9200,即使我告诉它。所以我想弄清楚我做错了什么。
鉴于此 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
我的旧 bootstrap.sh
工作正常:
#!/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
我的意思是它的工作原理是,从主机 OS (OS X 10.9.5) 我可以很好地卷曲 ES:
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"
}
但是当我使用这个新版本的 bootstrap.sh
时,我试图遵循 Elasticsearch 文档(总是一项艰巨的任务):
#!/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
无效。从 VM 内部,curl localhost:9200
按预期工作,但从主机 OS 我得到:
es200 > curl localhost:9200
curl: (52) Empty reply from server
我在这里错过了什么?谁能告诉我为什么新版本没有端口转发?
检查 ES 日志文件 (cat /var/log/elasticsearch/elasticsearch.log
) 后,我发现 script.disable_dynamic: false
破坏了一些东西:
[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)
我在遇到问题后添加了该设置,但在我最初尝试评论中的建议之前,所以 ES 失败了。修复此设置并没有解决我原来的问题,但它掩盖了解决方案。
无论如何,这是为我工作的 bootstrap.sh
文件:
#!/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
在您的 /etc/elasticsearch/elasticsearch.yml
配置文件中设置 network.host: 0.0.0.0
以便 elasticsearch
可以在 localhost
之外访问。记得做一个service elasticsearch restart
.