2012-06-08 65 views
35

我试图启动一个实例流浪汉并获得以下信息:“流浪无法在此VM转发指定端口”:如何调试消息

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机箱?

感谢, 凯文

+1

确保您的防火墙/防病毒软件没有阻止它。那是我的问题。 –

回答

11

至于有消息称,该端口与主机盒碰撞。我只是简单地将端口更改为主机上的其他值。所以,如果我收到错误

config.vm.forward_port 80, 1234 

那么我将其更改为

config.vm.forward_port 80, 5656 

1234可能是我的主机上使用。

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

+0

你如何改变端口? –

+1

http://stackoverflow.com/questions/24127852/vagrant-cannot-forward-the-specified-ports-on-this-vm tl/dr:'config.vm.network“forwarded_port”的更完整/现代化描述,访客:22,主机:2201,ID:“ssh”,auto_correct:真' – MarkHu

+1

Vishal的答案适用于旧版本的流浪者'vm: *以下设置不应该存在:forward_port' – lft93ryt

9

我遇到了这个问题,事实证明RubyMine仍然坚持到一个端口。我发现它的应用通过运行此命令(在我的案件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) 
+6

当存在没有人在那个港口听,但流浪者仍然抱怨港口正在使用?这怎么可能? – Bunyk

52

你可以看到流浪的实例运行在计算机上运行的是什么

$ 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 

如果你没有看到任何虚拟机上运行,​​你的冲突不是一个无业游民箱(即流浪汉知道)。接下来要做的是启动VirtualBox UI,并检查它是否有任何实例在运行。如果你不希望运行的UI,您可以:

ps -ef |grep VBox 

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

+0

其中一个错误消息是红色鲱鱼的情况 - 谢谢 –

+7

如果您想用一行代码杀死'VBox'进程:'ps -ef | grep VBox | awk'{print $ 2}'| xargs kill' – duhaime

+0

这是一个更好的答案,谢谢! – James

17

注意,你的流浪文件是而不是唯一一个被用来提出一个流浪箱/实例。

当你得到这样的:

~/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$ 

实际上,您不仅使用Vagrantfile来自〜的/ dev /流浪者也从“盒子”分配一个。箱文件,该文件通常设在这里:

~/.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) 

因此,继续和编辑这个文件删除违规碰撞转发端口(S):

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 

,并留意其他Vagrantfiles纳入即:

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_14_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 
... 

希望这有助于。

+0

谢谢!这解决了我的问题 –

+1

哇,所以用Vagrant你不能“覆盖”转发的端口?这意味着我不能多次使用相同的方框;( –

1

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

5

还要注意的是(在流浪1.6.4至少)有文件夹~/.vagrant.d/data/fp-leases,具有名称文件,如80808081等删除该文件夹的内容帮我刚才。

+1

)为了更深入地了解,这是当前用于虚拟机的端口,这可能有助于的情况是,如果目录中的vagrant文​​件被删除运行,流浪者仍然认为端口正在使用,因为它没有执行拆卸虚拟机,删除这些文件将“释放”这些端口供其他流浪机使用。 –