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

7
使用 Laravel Homestead 的新安装,我一直在尝试启动 Vagrant,但它一直超时。我尝试使用默认的虚拟交换机 Default,以及我使用 Hyper-V Manager 添加的虚拟交换机 DockerNATNewInternalVirtualSwitch
我知道我可以将提供程序保留为 VirtualBox 并关闭 Hyper-V,但由于我们在不同应用程序中使用 Vagrant 和 Docker,因此在过去几天中,这样做变得很繁琐,因为 Windows 10 Pro 上的 Docker for Windows 需要开启 Hyper-V,所以每次你必须在两者之间关机和重启。
有没有人使用 Hyper-V 提供程序成功地运行 Laravel Homestead,并且你需要采取哪些步骤来使网络工作正常,这似乎是问题的原因?

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.

更新

我也尝试了使用外部虚拟开关提示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.
3个回答

1
编辑:设置完成并测试工作流程后,我回到了VirtualBox + Homestead并禁用了Hyper V。归根结底,Windows和Linux彼此之间不太兼容,虽然Hyper V是Windows本地的,但随之而来的所有内容都不会是,甚至像复制文件和设置权限这样的简单任务也需要大量的劳动力。

我将在下面留下我的答案,也许其他人或我将来会回来看它。


我刚花了一整天的时间努力让它工作,但我失败了。不过,我想到了一个对我来说更好的解决方案,所以我会在这里分享一下。
如果您的工作站运行Windows 10 Pro,并且您知道如何设置生产服务器,则可能适用于您。想法是放弃Homestead并像在Hyper V上设置生产服务器一样设置本地服务器:
  1. 启用Hyper V
  2. 下载您的服务器操作系统映像(对我来说是Ubuntu 18.04),并创建一个虚拟机。
  3. homestead中包含的软件列表中选择您需要的内容,并在虚拟机上安装这些内容(对我来说是Nginx、PHP、PostgreSQL、Git、Python和Composer)。
此时,您基本上已经在 Hyper V 上拥有自定义的 Homestead。登录虚拟机,复制其 IP(登录时应该会显示它,但如果没有,这里是一个在 Ubuntu 上将其带出来的命令ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'),输入到浏览器窗口中,应该会出现默认的 Nginx 首页。
这很容易,但问题在于这个 IP 是动态的,它将保持重置。最难的部分是使其静态。
4. 在 Hyper-V 管理器中设置 IP 为静态 右键单击虚拟机 -> 设置 -> 网络适配器 -> 高级功能。重新启动所有内容
5. 在虚拟机操作系统中将 IP 设置为静态(Ubuntu 18.04 指南)。请注意,主机 Hyper V vEthernet 适配器的 IP 地址(在 Win 10 上使用ipconfig 带出)是虚拟机操作系统的网关地址。

就我个人而言,以下是优缺点:

优点:

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

缺点:

  • 如果您不熟悉生产服务器设置,则很难设置
  • 设置静态 IP 非常痛苦且需要大量黑客技巧
  • 在 Linux 和 Windows 之间访问文件需要 Samba 依赖项
  • 管理通过 Windows 访问的 Linux 文件的权限很复杂
  • Linux 客户机似乎无法通过 Hyper V 访问 GPU

0

我在Windows 10 Home上尝试运行Docker和Homestead时遇到了类似的问题。虽然我不能确定哪个方法起了作用,但最终我采取了以下步骤:

  1. 在Windows功能中打开:
    • 虚拟机平台
    • Windows Hypervisor平台
    • 适用于Linux的Windows子系统
  2. 使用HyperVSwitch打开更多的Hyper-V(仅将其作为“Windows功能”打开是不够的!)https://unclassified.software/en/apps/hypervswitch
  3. 重启Windows
  4. 在VirtualBox管理器中禁用Homestead虚拟机的“Adapter 2”(设置 > 网络 > Adapter 2 > 取消选中“启用网络适配器”)
  5. 正常运行Homestead虚拟机。

一旦重新启动Homestead虚拟机,“Adapter 2”将再次启用,但它现在似乎与所有Hyper-V设置结合使用时都能正常工作。

由于进行了大量的尝试、错误和服务器重新启动,我不确定到底是什么起了作用,但我希望它能帮助一些人在运行Docker和Homestead时解决问题。至少我现在知道这是可能的 :)


0

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

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

更好的解决方案是仅针对网络交换机禁用防火墙。这无法在GUI中完成;您需要使用提升的PowerShell。

set-NetFirewallProfile -DisabledInterfaceAliases NewInternalVirtualSwitch,DockerNAT,Default

请注意,如果您想禁用多个交换机的防火墙,必须在单个调用Set-NetFirewallProfile中指定所有交换机。
更好的解决方案是将交换机更改为私有网络,但我不知道如何做到这一点。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接