如何debugging“Vagrant无法转发此VM上的指定端口”消息

我试图启动一个stream浪者的实例,并得到以下消息:

Vagrant cannot forward the specified ports on this VM, since they would collide with another VirtualBox virtual machine's forwarded ports! The forwarded port to 4567 is already in use on the host machine. To fix this, modify your current projects Vagrantfile to use another port. Example, where '1234' would be replaced by a unique host port: config.vm.forward_port 80, 1234 

我打开了VirtualBox,但目前我没有任何运行框,所以我很难过。 我怎样才能找出哪个进程正在4567听? 有没有办法列出我的机器上运行的所有Vagrant框?

谢谢,凯文

正如消息所述,端口与主机箱发生冲突。 我只是简单地将端口改为主机上的其他值。 所以,如果我得到错误

 config.vm.forward_port 80, 1234 

那么我会改变它

 config.vm.forward_port 80, 5656 

因为1234可能在我的主机上使用。

对于实际检查任何机器上的端口,我使用该操作系统的tcpview实用程序,并知道在哪里使用哪个端口。

您可以通过运行查看您的机器上正在运行的stream浪实例

 $ vagrant global-status id name provider state directory ---------------------------------------------------------------------- a20a0aa default virtualbox saved /Users/dude/Downloads/inst-MacOSX 64bc939 default virtualbox saved /Users/dude/svn/dev-vms/ubuntu14 a94fb0a default virtualbox running /Users/dude/svn/dev-vms/centos5 

如果你没有看到任何虚拟机运行,你的冲突不是一个stream浪的方块(stream浪者知道)。 接下来要做的是启动VirtualBox UI,并检查是否有任何实例正在运行。 如果你不想运行用户界面,你可以:

 ps -ef |grep VBox 

如果您正在运行VirtualBox实例,则应将其包含在该输出中。 您应该能够杀死在其输出中具有VirtualBox的进程。 一个问题是,这些过程中的一个似乎存在保持活力。 杀掉最高的VirtualBox进程。 如果您有一个VirtualBox图像正在运行,但是stream浪不知道,可能手动删除了一些Vagrant目录,这意味着Vagrant失去了对该实例的跟踪。

注意,你的Vagrantfile 并不是唯一一个在启动Vagrant框/实例时使用的。

当你得到这个:

 ~/dev/vagrant user$ vagrant reload Vagrant cannot forward the specified ports on this VM, since they would collide with some other application that is already listening on these ports. The forwarded port to 8001 is already in use on the host machine. To fix this, modify your current projects Vagrantfile to use another port. Example, where '1234' would be replaced by a unique host port: config.vm.network :forwarded_port, guest: 8001, host: 1234 Sometimes, Vagrant will attempt to auto-correct this for you. In this case, Vagrant was unable to. This is usually because the guest machine is in a state which doesn't allow modifying port forwarding. ~/dev/vagrant user$ 

你实际上不仅使用〜/ dev / vagrant中的Vagrantfile,而且还使用了通常位于这里的“box”分发.box文件中的一个:

 ~/.vagrant.d/boxes/trusty/0/virtualbox/Vagrantfile 

如果你看看它,你会看到它有很多的默认端口映射:

 $ cat ~/.vagrant.d/boxes//trusty/0/virtualbox/Vagrantfile $script = <<SCRIPT bzr branch lp:jujuredirector/quickstart /tmp/jujuredir bash /tmp/jujuredir/setup-juju.sh SCRIPT Vagrant.configure("2") do |config| # This Vagrantfile is auto-generated by 'vagrant package' to contain # the MAC address of the box. Custom configuration should be placed in # the actual 'Vagrantfile' in this box. config.vm.base_mac = "080027DFD2C4" config.vm.network :forwarded_port, guest: 22, host: 2122, host_ip: "127.0.0.1" config.vm.network :forwarded_port, guest: 80, host: 6080, host_ip: "127.0.0.1" config.vm.network :forwarded_port, guest: 8001, host: 8001, host_ip: "127.0.0.1" config.vm.network "private_network", ip: "172.16.250.15" config.vm.provision "shell", inline: $script end # Load include vagrant file if it exists after the auto-generated # so it can override any of the settings include_vagrantfile = File.expand_path("../include/_Vagrantfile", __FILE__) load include_vagrantfile if File.exist?(include_vagrantfile) 

因此,请继续编辑此文件以删除有问题的冲突转发端口:

  config.vm.network :forwarded_port, guest: 22, host: 2122, host_ip: "127.0.0.1" config.vm.network :forwarded_port, guest: 80, host: 6080, host_ip: "127.0.0.1" # config.vm.network :forwarded_port, guest: 8001, host: 8001, host_ip: "127.0.0.1" 

通过:

 ~/dev/vagrant user$ cp ~/.vagrant.d/boxes//trusty/0/virtualbox/Vagrantfile ~/.vagrant.d/boxes//trusty/0/virtualbox/Vagrantfile.old ~/dev/vagrant user$ vi ~/.vagrant.d/boxes//trusty/0/virtualbox/Vagrantfile 

并注意其他stream浪文件包括:

 include_vagrantfile = File.expand_path("../include/_Vagrantfile", __FILE__) 

现在它的工作原理是:

 $ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'trusty'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: vagrant_default_1401234565101_12345 ==> default: Clearing any previously set forwarded ports... ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: hostonly ==> default: Forwarding ports... default: 22 => 2122 (adapter 1) default: 80 => 6080 (adapter 1) default: 22 => 2222 (adapter 1) ==> default: Running 'pre-boot' VM customizations... ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Connection timeout. Retrying... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Configuring and enabling network interfaces... ==> default: Mounting shared folders... default: /vagrant => /Home/user/dev/vagrant/vagrant-docker ==> default: Running provisioner: shell... default: Running: inline script ... 

希望这可以帮助。

我遇到了这个问题,事实certificateRubyMine仍然坚持到一个端口。 通过运行这个命令,我发现哪个应用程序保留在端口(在我的情况下是31337):

 lsof -i | grep LISTEN 

产量

 node 1396 richard.nienaber 7u IPv4 0xffffff802808b320 0t0 TCP *:20559 (LISTEN) Dropbox 1404 richard.nienaber 19u IPv4 0xffffff8029736c20 0t0 TCP *:17500 (LISTEN) Dropbox 1404 richard.nienaber 25u IPv4 0xffffff8027870160 0t0 TCP localhost:26165 (LISTEN) rubymine 11668 richard.nienaber 39u IPv6 0xffffff8024d8e700 0t0 TCP *:26162 (LISTEN) rubymine 11668 richard.nienaber 65u IPv6 0xffffff8020c6e440 0t0 TCP *:31337 (LISTEN) rubymine 11668 richard.nienaber 109u IPv6 0xffffff8024d8df80 0t0 TCP localhost:6942 (LISTEN) rubymine 11668 richard.nienaber 216u IPv6 0xffffff8020c6ef80 0t0 TCP localhost:63342 (LISTEN) 

还要注意的是(至less在Vagrant 1.6.4中)有~/.vagrant.d/data/fp-leases的文件夹,文件的名字像8081等等。擦掉这个文件夹的内容刚才帮了我~/.vagrant.d/data/fp-leases

如果您使用Proxifier(或类似的应用程序),请先尝试closures它。 这是我在OSX 10.9上使用Proxifier时遇到的一个问题。