我正在努力让Elasticsearch 2.0在Vagrant虚拟机中运行。我用于1.7的方法不再有效,所以我正在尝试更新我的方法。我可以在VM中安装ES 2.0,它似乎可以在VM中正常工作,但我无法从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 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
按预期工作,但是从主机操作系统我得到:
es200 > curl localhost:9200
curl: (52) Empty reply from server
我在这里缺少什么?任何人都可以告诉我为什么不是新版本的端口转发?
答案 0 :(得分:12)
在/etc/elasticsearch/elasticsearch.yml
配置文件集network.host: 0.0.0.0
中,以便elasticsearch
之外可以访问localhost
。记得做service elasticsearch restart
。
答案 1 :(得分:8)
在检查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