简体   繁体   English

从无业游民访问elasticsearch

[英]Access elasticsearch from vagrant

Hi I've been trying almost everything to access my elasticsearch database from my vagrant VM. 嗨,我一直在尝试几乎所有事情,以便从无所事事的VM访问我的Elasticsearch数据库。 In this forum there are plenty of threads but none of them seems to work, that's why I'm posting. 在此论坛中,有很多线程,但似乎都没有起作用,这就是我要发布的原因。

The thing is that if I type: curl -X GET http://127.0.0.1:9200 outside of vagrant I'll get the content of my elastisearch localhost. 问题是,如果我输入:在无业游民之外的地方curl -X GET http://127.0.0.1:9200我将获得elastisearch本地主机的内容。

Inside of vagrant I connect to my mongodb databases through: 在流浪汉内部,我通过以下方式连接到mongodb数据库:

mongo 10.0.2.2:27017 

Therefore, and following one of these answers: 因此,并遵循以下答案之一:

Vagrant reverse port forwarding? 无用的反向端口转发?

I expected that by changing this: 我希望通过更改此内容:

vagrant ssh -- -R 12345:localhost:80

into this: 到这个:

vagrant ssh -- -R 12345:10.0.2.2:9200

I would be able to access my elasticsearch from vagrant if I typed: 如果输入以下内容,我将可以从无业游民访问我的elasticsearch:

curl -X GET http://10.0.2.2:9200

but I'm not getting anything... 但是我什么都没得到...

This is the content of my vagrant file: 这是我的流浪者文件的内容:

Vagrant.configure(2) do |config|
  # config.vm.box = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
  config.vm.box = "xenial-amd64"
  config.vm.box_url = "https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-vagrant.box"
  config.vm.hostname = "proxy"


  config.vm.network "private_network", ip: "192.168.90.103"



  config.vm.provision :shell, :path => "provisions/shell/bootstrap.sh"
end

You need to make sure your vagrant-elasticsearch is listening on all network interfaces (not only localhost) 您需要确保您的vagrant-elasticsearch在所有网络接口上侦听(不仅是本地主机)

Edit the file /etc/elasticsearch/elasticsearch.yml and change a few things 编辑文件/etc/elasticsearch/elasticsearch.yml并进行一些更改

network.bind_host: 0
network.host: 0.0.0.0

# I do that for cors
http.cors.enabled: true
http.cors.allow-origin: /https?:\/\/.*/

Make sure to restart elasticsearch after the changes. 确保更改后重新启动elasticsearch。 This will allow you to access your vagrant-elasticsearch from your host machine. 这将允许您从主机访问您的vagrant-elasticsearch。

I think the easiest to work with is to set a static IP to your VM, you can edit your Vagrantfile and have (just an example of IP address) 我认为最容易使用的方法是为VM设置静态IP,您可以编辑Vagrantfile并拥有(仅是IP地址的示例)

Vagrant.configure("2") do |config|
  ...
  config.vm.network "private_network", ip: "192.168.90.103"
  ...
end

then you can easily access elasticsearch using http://192.168.90.103:9200 那么您可以使用http://192.168.90.103:9200轻松访问elasticsearch

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM