Vagrant - 如何在使用私有接口时配置 vagrant ssh? [英] Vagrant - how to configure vagrant ssh when using private interfaces?

查看:35
本文介绍了Vagrant - 如何在使用私有接口时配置 vagrant ssh?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 3 个虚拟机的多虚拟机 vagrantfile 设置.其中两个 vm 的 NAT 网络接口已禁用,并且仅在内部接口上使用静态 ip.

I have a multivm vagrantfile setup with 3 vms. Two of the vm's have their NAT network interface disabled, and solely use a static ip on an internal interface.

副作用是我无法再运行 vagrant ssh foo 来连接到虚拟机.

The side effect is that I am no longer able to run vagrant ssh foo to connect to the vm's.

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

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  #config.vm.box = "PuppetlabsCent64"
  #config.vm.box_url = "http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box"
  config.vm.box = "Debian-7-2"
  config.vm.box_url= "https://dl.dropboxusercontent.com/u/197673519/debian-7.2.0.box"
  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network :private_network, ip: "192.168.45.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network :public_network

  config.vm.synced_folder ".", "/vagrant_data"

  config.vm.provider :virtualbox do |vb|
   vb.customize ["modifyvm", :id, "--memory", "512"]
  end

     config.vm.define "r", primary: true  do |router|
       router.vm.box = "Debian-7-2"
       router.vm.network :private_network, ip: "192.168.45.11"

     end

     config.vm.define "r1" do |roomate1|
       roomate1.vm.box = "Debian-7-2"
       roomate1.vm.network :private_network, ip: "192.168.45.12"
     end

     config.vm.define "r2" do |roomate2|
       roomate2.vm.box = "Debian-7-2"
       roomate2.vm.network :private_network, ip: "192.168.45.13"
     end

   config.vm.provider :virtualbox do |vb|
     vb.customize "post-boot",["controlvm", :id, "setlinkstate1", "off"]
   end

end

这个线程在流浪用户组,给了我检查默认流浪配置的想法.

This thread in the vagrant user group, gave me the idea to check the default vagrant config.

我已经尝试了以下每一项都没有运气

I've tried each of the following with no luck

 config.vm.define "r", primary: true  do |router|
   router.vm.box = "Debian-7-2"
   router.vm.network :private_network, ip: "192.168.45.11"
   #config.ssh.host "192.168.45.11"
   #router.vm.network :forwarded_port, host: "192.168.45.11"
   #router.vm.box_url = "192.168.45.11"
   #router.vm.boot_timeout = 200
   #router.vagrant.host = "192.168.45.11"
   #router.ssh.host = "192.168.45.11"
 end

#non working 
sowen@pv-sowen-nb:~/Code/flatmate-firewall$ vagrant ssh-config r
Host r
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /Users/sowen/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL

运行 vagrant up 在启动过程中中途挂起,导致我必须等待 300 秒才能启动每个虚拟机.

Running vagrant up hangs part way through the boot process, causing me to have to wait 300 seconds for each vm to boot.

错误信息

Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period. This can
mean a number of things.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

有没有办法配置 vagrant ssh 以使用正确的 ip &端口,以便它不会超时?

Is there a way to configure vagrant ssh to use the correct ip & port so that it doesn't time out?

来源:https://github.com/spuder/flatmate-firewall/blob/master/Vagrantfile

推荐答案

我可以在你的 Vagrantfile 中看到你的问题,但我向你展示了我的两台机器的例子.

I can see your problem in your Vagrantfile, but I show you my example with two machine.

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  # All Vagrant configuration is done here. The most common configuration
  # options are documented and commented below. For a complete reference,
  # please see the online documentation at vagrantup.com.

  config.vm.define 'app' do |app_config|
    app_config.vm.box = 'ubuntu_app'
    app_config.vm.host_name = 'app'
    app_config.vm.network "private_network", ip: "192.168.33.33"
  end

  config.vm.define 'web' do |web_config|
    web_config.vm.box = 'ubuntu_app'
    web_config.vm.host_name = 'web'
    web_config.vm.network "private_network", ip: "192.168.33.34"
  end
end

然后我使用标准的 ssh 连接连接到网络"机器

And then I connect to the "web" machine with the standard ssh conection

roberto@rcisla-pc:~/Desktop/vagrant$ ssh vagrant@web -p 22
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)

 * Documentation:  https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Sun Jan 12 13:18:18 2014 from 192.168.33.1
vagrant@web:~$

等同于应用机器"

roberto@rcisla-pc:~/Desktop/vagrant$ ssh vagrant@app -p 22
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)

 * Documentation:  https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Sun Jan 12 13:18:18 2014 from 192.168.33.1
vagrant@app:~$

我希望这会有所帮助.

这篇关于Vagrant - 如何在使用私有接口时配置 vagrant ssh?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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