通过Vagrant为Hyper-V VM自动配置网络接口

时间:2018-07-31 05:35:34

标签: ubuntu networking vagrant hyper-v

我正在尝试使用Vagrant在Hyper-V中运行Ubuntu VM,但是我遇到了一些网络问题。这有点超出我的专业领域,因此,我们将不胜感激。

我已经通过PowerShell控制台创建了Hyper-V内部交换机'VagrantSwitch',如下所示:

New-VMSwitch –SwitchName "VagrantSwitch" –SwitchType Internal
New-NetIPAddress –IPAddress 192.168.82.1 -PrefixLength 24 -InterfaceAlias "vEthernet (VagrantSwitch)"
New-NetNat –Name MyVagrantNetwork –InternalIPInterfaceAddressPrefix 192.168.82.0/24

VagrantFile的重要部分如下(注意:变量来自外部配置):

guest.vm.box = bento/ubuntu-16.04" # note: I've tried several different Ubuntu 16.04 boxes here.
guest.vm.hostname = node[:name]
guest.vm.provider "virtualbox" do |vb|
    # configure NAT/Host-only network. This allows for host->guest, guest->host and guest->guest communication
    guest.vm.network "private_network", ip: node[:ip], :netmask => node[:netmask], auto_config: false
    # this script configures /etc/network/interfaces
    guest.vm.provision :shell, :path => "provision/bootstrap.sh", :args => "'#{node[:ip]}' '#{node[:netmask]}'"
    vb.name = node[:name]
    vb.memory = node[:memory]
    vb.cpus = node[:cpus]
    vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ]
end
config.vm.provider "hyperv" do |hv|
    # previous attempts
    # guest.vm.network "private_network", ip: node[:ip]
    # guest.vm.network "private_network", type: "dhcp"
    guest.vm.network "private_network", bridge: "VagrantSwitch"
    # this script configures /etc/network/interfaces
    guest.vm.provision :shell, :path => "bootstrap.sh", :args => "'#{node[:ip]}' '#{node[:netmask]}'"
    hv.vmname = node[:name]
    hv.memory = node[:memory]
    hv.cpus = node[:cpus]
end

一切对于我的家用电脑上的VirtualBox都适用,但是我无法在我的Windows 10专业版工作计算机上使用VirtualBox,因为我启用了Windows docker所需的Hyper-V。 对于Hyper-V,我遇到的问题似乎是停滞不前。 Vagrant脚本的最后输出是:

manager1: SSH username: vagrant
manager1: SSH auth method: password

5分钟后出现以下错误之前:

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.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

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.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

启动网络接口和启动计算机似乎有些问题。

在出现错误之前,我实际上可以在Hyper-V Manager中看到VM。如果我连接到它,则报告以下内容

A start job is running for Raise network interfaces (Xmin Ys / 5min 1s)

Xmin Ys从5min 1s开始递减计数。在此超时和Vagrant脚本错误退出之后,我可以手动连接到VM,登录并配置/ etc / network / interfaces以使所有功能正常运行,但是,我不希望这是一个手动步骤。

正如我所提到的,这有点超出我的专业领域,因此,如果我在任何地方使用了错误的术语,或者如果我的理解不足都在我的问题中表示歉意...

在此先感谢您的回复。

0 个答案:

没有答案