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

mtp*_*ltz 5 hyper-v vagrant windows-10 vagrant-windows

使用Laravel和Laravel Homestead的新安装我一直试图让Vagrant启动,但是它会一直停机.我尝试使用Default虚拟交换机,以及所述DockerNATNewInternalVirtualSwitch是我添加使用虚拟交换机Hyper-V管理.

我知道我可以将提供程序保留为VirtualBox并关闭Hyper-V,但由于我们在不同的应用程序中使用Vagrant和Docker,因为Docker for Windows在Windows 10 Pro上需要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
Run Code Online (Sandbox Code Playgroud)

流浪汉

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
Run Code Online (Sandbox Code Playgroud)

错误

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.
Run Code Online (Sandbox Code Playgroud)

更新

还尝试使用外部虚拟交换机提示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.
Run Code Online (Sandbox Code Playgroud)

Art*_*sov 1

编辑:在设置完所有内容并测试工作流程后,我回到 VirtualBox + Homestead 并禁用了 Hyper V。底线是 Windows 和 Linux 彼此不太兼容,虽然 Hyper V 是 Windows 原生的,但接下来的一切不会,甚至复制文件和设置权限等简单任务也需要大量劳动力。

我将在下面留下我的答案,也许其他人或我将来会回来讨论这个问题。


我只是花了一天的时间试图让它工作,但我做不到,但我想出了一个至少对我来说更好的解决方案,所以我将在这里分享它。

如果您的工作站运行带有 Hyper V 的 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是动态的,它会不断重置。最困难的部分是使其静态。

  1. 将 Hyper-V 管理器中的 ip 设置为 static right click the virtual machine -> Settings -> Network Adapter -> Advanced Features。重新启动一切

  2. 在虚拟机的操作系统中将 ip 设置为静态(Ubuntu 18.04 指南)。请注意,主机 Hyper V vEthernet 适配器的 IP 地址(ipconfig在 Win 10 上启动)是虚拟机操作系统的网关地址。

所以从我的角度来看有利有弊。

优点:

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

缺点:

  • 如果您不熟悉生产服务器设置,则很难设置
  • 设置静态IP确实是一个痛苦的黑客行为
  • Linux和Windows之间访问文件需要Samba依赖
  • 管理通过 Windows 访问的 Linux 文件的权限很复杂
  • Linux 来宾似乎无法通过 Hyper V 访问 GPU