gpt4 book ai didi

ubuntu - 无法从主机操作系统访问 Vagrant VM 中的 Elasticsearch 2.0

转载 作者:行者123 更新时间:2023-11-29 02:46:21 25 4
gpt4 key购买 nike

我正在尝试在 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 X 10.9.5) 我可以很好地 curl 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

我在这里错过了什么?谁能告诉我为什么新版本没有端口转发?

最佳答案

在您的/etc/elasticsearch/elasticsearch.yml 配置文件中设置network.host: 0.0.0.0 以便可以在外部访问elasticsearch 本地主机。请记住执行 service elasticsearch restart

关于ubuntu - 无法从主机操作系统访问 Vagrant VM 中的 Elasticsearch 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33453917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com