2012-06-08 63 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文​​件被刪除運行,流浪者仍然認爲端口正在使用,因爲它沒有執行拆卸虛擬機,刪除這些文件將「釋放」這些端口供其他流浪機使用。 –