我在使用 VMware Fusion 7.1.3、Vagrant 1.7.4 和 vagrant-vmware-fusion 4.0.2 插件通过 WinRM 与 Windows Server 2016 TP4 VM 通信时遇到问题。
似乎 vagrant-vmware-fusion 插件从只是一个虚拟交换机的 VM 中捕获了错误的 IP 地址172.16.0.1
。
这是启动 Windows VM 的样子:
$ vagrant up
Bringing machine 'default' up with 'vmware_fusion' provider...
==> default: Verifying vmnet devices are healthy...
==> default: Preparing network adapters...
==> default: Starting the VMware VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: WinRM address: 172.16.0.1:5985
default: WinRM username: vagrant
default: WinRM transport: plaintext
^C==> default: Waiting for cleanup before exiting...
在 VM 内部,我有以下网卡:
PS C:\Users\vagrant> ipconfig
Windows IP Configuration
Ethernet adapter vEthernet (Virtual Switch):
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::851b:ed4b:1436:4710%11
IPv4 Address. . . . . . . . . . . : 172.16.0.1
Subnet Mask . . . . . . . . . . . : 255.240.0.0
Default Gateway . . . . . . . . . :
Ethernet adapter Ethernet 2:
Connection-specific DNS Suffix . : localdomain
Link-local IPv6 Address . . . . . : fe80::91d4:5359:785b:e075%8
IPv4 Address. . . . . . . . . . . : 192.168.254.134
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.254.2
Tunnel adapter isatap.{F8AB9E14-C9C4-4A78-A4F9-966B59BD5D9E}:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Tunnel adapter isatap.localdomain:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . : localdomain
这是一个安装了 Windows Docker 和 Hyper-V 的 Windows 2016 TP4 VM。 Windows docker 的安装创建了这个虚拟交换机。 不知何故,“主要”VMware 网卡被称为“以太网 2”,而不是列表中的第一个。
使用调试日志运行相同的vagrant up
表明首先捕获了正确的 IP 地址192.168.254.134
,但是在运行返回虚拟交换机 IP 地址 Vagrant 的vmrun getGuestIPAddress
之后将此错误的 IP 地址用于 WinRM。
$ "/Applications/VMware Fusion.app/Contents/Library/vmrun" "getGuestIPAddress" "/Users/stefan/code/docker-windows-box/.vagrant/machines/default/vmware_fusion/e04a32bc-9b7a-4cbf-9abb-dc5e7f299af7/packer-vmware-iso.vmx"
172.16.0.1
因此,由于vmrun
在某些情况下似乎检索到错误的值,所以只使用第一个 MAC 地址匹配的 IP 地址会更好吗?
在调试日志中间的某个地方,我找到了正确的 IP 地址: https :
嗨@StefanScherer - 我们引入了一个配置选项来尝试解决这样的情况……你能在你的 Vagrantfile 中试试这个吗?
config.vm.provider "vmware_fusion" do |v|
v.enable_vmrun_ip_lookup = false
end
@phinze非常感谢! 是的,它做到了!
$ vagrant up
Bringing machine 'default' up with 'vmware_fusion' provider...
==> default: Verifying vmnet devices are healthy...
==> default: Preparing network adapters...
==> default: Starting the VMware VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: WinRM address: 192.168.254.134:5985
default: WinRM username: vagrant
default: WinRM transport: plaintext
==> default: Machine booted and ready!
==> default: Forwarding ports...
default: -- 3389 => 3389
default: -- 22 => 2222
default: -- 5985 => 55985
default: -- 5986 => 55986
==> default: Configuring network adapters within the VM...
==> default: Configuring secondary network adapters through VMware
==> default: on Windows is not yet supported. You will need to manually
==> default: configure the network adapter.
==> default: Enabling and configuring shared folders...
default: -- /Users/stefan/code/docker-windows-box: /vagrant
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
虽然我不时查看插件发行说明,但我没有抓住这个。
只是为了记录,这是我的 Vagrantfile,用于 Windows Server 2016 TP4 在 MBP 上以视网膜模式全屏运行。
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.require_version ">= 1.6.0"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "windows_2016_tp4"
config.vm.communicator = "winrm"
["vmware_fusion", "vmware_workstation"].each do |provider|
config.vm.provider provider do |v, override|
v.gui = true
v.vmx["memsize"] = "4096"
v.vmx["numvcpus"] = "2"
v.vmx["vhv.enable"] = "TRUE"
v.vmx["hypervisor.cpuid.v0"] = "FALSE"
v.enable_vmrun_ip_lookup = false
end
end
config.vm.provider "vmware_fusion" do |v|
v.vmx["gui.fitguestusingnativedisplayresolution"] = "TRUE"
v.vmx["mks.enable3d"] = "TRUE"
v.vmx["mks.forceDiscreteGPU"] = "TRUE"
v.vmx["gui.fullscreenatpoweron"] = "TRUE"
v.vmx["gui.viewmodeatpoweron"] = "fullscreen"
v.vmx["gui.lastPoweredViewMode"] = "fullscreen"
v.vmx["sound.startconnected"] = "TRUE"
v.vmx["sound.present"] = "TRUE"
v.vmx["sound.autodetect"] = "TRUE"
end
config.vm.provision "shell", path: "scripts/provision.ps1", privileged: false
end
最有用的评论
嗨@StefanScherer - 我们引入了一个配置选项来尝试解决这样的情况……你能在你的 Vagrantfile 中试试这个吗?