使用Hyper-V提供程序的Vagrant运行Laravel Homestead

时间:2017-12-13 05:07:06

标签: vagrant windows-10 hyper-v vagrant-windows

在Laravel Homestead中使用Laravel的新安装我一直试图让Vagrant启动,但它会一直停机。我尝试使用Default虚拟交换机,以及DockerNATNewInternalVirtualSwitch这是我使用Hyper-V Manager添加的虚拟交换机。

我知道我可以将提供程序保留为VirtualBox并关闭Hyper-V,但由于我们在过去几天使用Vagrant和Docker执行此操作已经变得乏味,因为Windows 10 Pro上的Docker for Windows要求每次必须关闭并重新启动时,Hyper-V都会打开。

是否有人让Laravel Homestead使用Hyper-V提供商工作,您需要采取哪些步骤才能使网络工作成为问题?

Homestead.yaml

ip: 192.168.10.10
memory: 2048
cpus: 1
provider: hyperv
authorize: ~/.ssh/example/id_rsa.pub
keys:
    - ~/.ssh/example/id_rsa
folders:
    -
        map: 'D:\Projects\example\server'
        to: /home/vagrant/server
sites:
    -
        map: server.app
        to: /home/vagrant/server/public
databases:
    - example
name: example
hostname: example

Vagrant Up

Bringing machine 'example' up with 'hyperv' provider...
==> example: Verifying Hyper-V is enabled...
==> example: Importing a Hyper-V instance
    example: Please choose a switch to attach to your Hyper-V instance.
    example: If none of these are appropriate, please open the Hyper-V manager
    example: to create a new virtual switch.
    example:
    example: 1) DockerNAT
    example: 2) Default Switch
    example: 3) NewInternalVirtualSwitch
    example:
    example: What switch would you like to use? 3
    example: Cloning virtual hard drive...
    example: Creating and registering the VM...
    example: Setting VM Integration Services
    example: Successfully imported a VM with name: ubuntu-16.04-amd64_1
==> example: Starting the machine...
==> example: Waiting for the machine to report its IP address...
    example: Timeout: 120 seconds
    example: IP: fe80::215:5dff:fe38:107
==> example: Waiting for machine to boot. This may take a few minutes...
    example: SSH address: fe80::215:5dff:fe38:107:22
    example: SSH username: vagrant
    example: SSH auth method: private key <--- Stalls out for a couple minutes

错误

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.

更新

还使用外部虚拟交换机尝试了tip 4,它进一步尝试,但在尝试分配主机名时仍然出现错误:

==> example: Machine booted and ready!
==> example: Setting hostname...
No host IP was given to the Vagrant core NFS helper. This is
an internal error that should be reported as a bug.

2 个答案:

答案 0 :(得分:0)

编辑:在完成所有设置并测试了工作流程之后,我返回了VirtualBox + Homestead并禁用了HyperV。最重要的是,Windows和Linux彼此之间并不十分兼容,有时Hyper V是Windows固有的,后续的所有操作都不是,甚至简单的任务(如复制文件和设置权限)也需要大量工作。

我将把答案留在下面,也许是其他人,或者我将来会再回来。


我只是花了一天时间尝试使其工作,但我没有,但是我想出了一个至少对我来说更有效的解决方案,所以我在这里分享。

如果您的工作站运行带有Hyper V的Windows 10 Pro,并且您知道如何设置生产服务器,那么它可能对您有用。

想法是放弃Homestead并像在生产服务器上一样在Hyper V上设置本地服务器:

  1. 启用Hyper V
  2. 下载服务器操作系统映像(对我来说是Ubuntu 18.04)并使用它创建虚拟机。
  3. list of software included in homestead中选择所需的内容,然后将它们安装在虚拟机上(对我而言,是Nginx,PHP,PostgreSQL,Git,Python和Composer)。

这时,您几乎已经在Hyper V上自定义了Homestead。登录虚拟机,复制其ip(登录时应显示它,但如果没有,这是在Ubuntu {{ 1}}),将其输入到浏览器窗口中,它将打开默认的Nginx主页。

这很简单,但是问题在于此ip是动态的,并且会不断重置。最困难的部分是使其静态化。

  1. 在Hyper-V管理器中将ip设置为静态ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'。重新启动所有内容

  2. 在虚拟机(guide for Ubuntu 18.04)的OS中将ip设置为static。请注意,主机Hyper Hyper v vEthernet适配器的IP地址(在Win 10上为right click the virtual machine -> Settings -> Network Adapter -> Advanced Features来启动它)是虚拟机OS的网关地址。

从我的角度来看,这是有利有弊。

优点:

  • 在Windows + Hyper V上比在Windows + Oracle Virtual Box上更快,更干净地工作
  • 可自定义和可更新。更新Homestead的唯一方法似乎是删除它并下载新的。

缺点:

  • 如果您不熟悉生产服务器设置,则很难设置
  • 设置静态IP确实是很多痛苦的事情
  • 在Linux和Windows之间访问文件需要Samba依赖性
  • 管理通过Windows访问的Linux文件的权限很复杂
  • Linux guest虚拟机似乎无法通过Hyper V访问GPU

答案 1 :(得分:0)

可能会出现这个问题,因为默认情况下,Hyper-V 交换机被视为公共网络; Windows 防火墙阻止访问虚拟机。

一种简单但危险的解决方法是简单地关闭 Windows 防火墙。您可以这样做以测试这是否是您的问题,但当然不要关闭防火墙。

更好的解决方案是仅对网络交换机(或多个交换机)禁用防火墙。这不能在 GUI 中完成;为此,您需要一个提升的 PowerShell。

set-NetFirewallProfile -DisabledInterfaceAliases NewInternalVirtualSwitch,DockerNAT,Default

请注意,如果要为多个交换机禁用防火墙,则必须在一次调用 Set-NetFirewallProfile 时指定所有交换机。

更好的解决方案是将交换机更改为专用网络,但我不知道有什么方法可以做到这一点。

相关问题