在Vagrantfile

时间:2016-02-26 09:07:12

标签: elasticsearch vagrant vagrantfile

我尝试启动elasticsearch并在Vagrantfile上配置其架构。 但是,当我在Vagrantfile上使用curl放置schema json文件时,会发生“连接被拒绝”错误,尽管elasticsearch已成功启动。

  
    

curl -X PUT http://192.168.33.20:9200/test --data-binary @ / synced_folder / schema.json

  

[错误讯息]

  
    

0curl:(7)连接失败到192.168.33.20:9200;连接被拒绝

  

※完成流浪后,此命令成功。具体...

  
    

sudo ssh 192.168.33.20

  

  
    

curl -X PUT http://192.168.33.20:9200/test --data-binary @ / synced_folder / schema.json

  

没有错误,架构配置成功。

  
    

{ “公认的”:真}

  

但是,我想在“vagrant up”进程中配置架构。 为什么在Vagrantfile上发生“连接被拒绝”错误?

[Vagrantfile]

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
 config.vm.box = "bento/centos-7.1"
 config.vm.box_url = "https://atlas.hashicorp.com/bento/boxes/centos-7.1"
 config.vm.network :private_network, ip: "192.168.33.20"
 config.vm.synced_folder "./", "/synced_folder"
 config.vm.provision "shell", path: "./script.sh"
end

[script.sh]

#!/bin/sh

#install java
yum -y install java

#install and start elasticsearch
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
cp /synced_folder/elasticsearch.repo /etc/yum.repos.d
yum -y install elasticsearch
sed -i '/# network.host: 192.168.0.1/a\network.host: 192.168.33.20' /etc/elasticsearch/elasticsearch.yml
cd /usr/share/elasticsearch
#Japanese morphological analysis plugin
bin/plugin install analysis-kuromoji
service elasticsearch start

#configure index 
curl -X PUT http://192.168.33.20:9200/test --data-binary @/synced_folder/schema.json

[/ synced_folder / schema.json]

{"mappings":{"comment_data":{"properties":{"comment":{"type":"string","store":"yes","index":"analyzed"},"date":{"type":"date","store":"yes"},"vps":{"type":"float","store":"yes"}}}}}

1 个答案:

答案 0 :(得分:3)

我可以解决这个问题。 我发现弹性搜索实际上是在服务开始后几秒钟开始的。 所以我向shell脚本添加一个等待进程。 谢谢!

while true;
do
    echo "waiting Elasticsearch..."
    curl -X -s GET http://192.168.33.20:9200
    if [ $? -eq "0" ]; then
        echo "Elasticsearch started!"
        break
    fi
    sleep 1s
done