允许两个或多个 vagrant VM 在自己的网络上通信 [英] Allow two or more vagrant VMs to communicate on their own network

查看:23
本文介绍了允许两个或多个 vagrant VM 在自己的网络上通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建多个可以直接相互通信而不使用公共 IP 的服务器.他们仍然需要互联网访问,但网络外部的任何东西都不需要连接到他们.创建一个盒子通常是有效的,但是当我添加额外的服务器时,网络就会失败.

I want to create multiple servers that can communicate directly with each other without using public IPs. They'll still need internet access but nothing from outside the network will need to connect to them. Creating one box usually works, but when I add additional servers the networking fails.

MacOS:10.8.5
虚拟机:4.3.12
GuestOS:Ubuntuprecise64"
使用 Vagrant 配置的第 2 版

MacOS: 10.8.5
Virtualbox: 4.3.12
GuestOS: Ubuntu "precise64"
Using version 2 of the Vagrant config

大多数情况下,如果我使用专用网络,我会得到:

Most of the time if I use private network I get:

saltminion01: Warning: Connection timeout. Retrying...
saltminion01: Warning: Connection timeout. Retrying...
saltminion01: Warning: Connection timeout. Retrying...
saltminion01: Warning: Connection timeout. Retrying...
saltminion01: Warning: Connection timeout. Retrying...
saltminion01: Warning: Connection timeout. Retrying...
saltminion01: Warning: Connection timeout. Retrying...
saltminion01: Warning: Connection timeout. Retrying...
saltminion01: Warning: Connection timeout. Retrying...

有人有这样做的示例 Vagrantfile 吗?

Does anybody have a sample Vagrantfile that does this?

推荐答案

以下是创建两个 VM 的示例:

Here's an example which creates two VMs:

  • alpha 10.0.0.10
  • 测试版 10.0.0.11

从任一虚拟机内部,您可以通过 IP 地址访问另一个虚拟机,并可以连接到外部世界.

From inside either VM you can reach the other by IP address, and can connect to the outside world.

流浪文件:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrant multi-machine sample setup

Vagrant.configure("2") do |config|
  config.vm.define :alpha do |alpha|
    alpha.vm.box = "hashicorp/precise64"
    alpha.vm.network :private_network, ip: "10.0.0.10"
    alpha.vm.hostname = "alpha"
  end

  config.vm.define :beta do |beta|
    beta.vm.box = "hashicorp/precise64"
    beta.vm.network :private_network, ip: "10.0.0.11"
    beta.vm.hostname = "beta"
  end
end

这篇关于允许两个或多个 vagrant VM 在自己的网络上通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆