Vagrant多机器 - 机器之间的连接

时间:2017-02-23 06:27:10

标签: php elasticsearch vagrant

我有简单的vagrant多机配置:

Vagrant.configure(2) do |config|
  config.vm.box = "bento/ubuntu-16.04"
  config.vm.provision :shell, path: "vagrant/ubuntu-16.04/provision.sh"
  config.vm.synced_folder "ed", "/var/www/html"
  config.vm.provider "virtualbox" do |v|
    v.memory = 1024
    v.cpus = 2
  end
  config.vm.define "node1", primary: true do |node|
    node.vm.hostname = 'node1'
    node.vm.network :private_network, ip: "192.168.56.101"
    node.vm.network :forwarded_port, guest: 22, host: 10122, id: "ssh"
    node.vm.provision :hosts, :sync_hosts => true
  end
  config.vm.define "node2" do |node|
    node.vm.hostname = "node2"
    node.vm.network :private_network, ip: "192.168.56.102"
    node.vm.network :forwarded_port, guest: 22, host: 10123, id: "ssh"
    node.vm.provision :hosts, :sync_hosts => true
  end
end

node1我有php和node2我有弹性搜索。
当我从curl localhost:9200运行vagrant@node2时,它有效,
但是当我尝试从curl 192.168.56.102:9200运行vagrant@node1时,它将无效,我收到错误:

curl: (7) Failed to connect to 192.168.56.102 port 9200: Connection refused

1 个答案:

答案 0 :(得分:2)

根据您的评论,elasticsearch监听localhost。因此,它只能从当地访问。看你的输出:

netstat -anp | grep LISTEN | grep 9200

tcp6 0 0 127.0.0.1:9200 :::* LISTEN - tcp6 0 0 ::1:9200 :::* LISTEN

您必须将elasticsearch端口绑定到您的IP地址才能从外部访问。

打开elasticsearch.yml并将IP地址添加到network.host选项。

network.host: "192.168.56.102"

之后重启elasticsearch服务。

sudo service elasticsearch restart