2015-06-05 80 views
2

試圖在同一主機上運行兩個流浪實例。在一審流浪漢文件沒有什麼特別之處與SSH端口:從同一主機運行兩個vagrant實例時轉發ssh端口失敗?

# Create a forwarded port mapping which allows access to a specific port 
# within the machine from a port on the host machine. In the example below, 
# accessing "localhost:8080" will access port 80 on the guest machine. 
config.vm.network "forwarded_port", guest: 8080, host: 9080 
config.vm.network "forwarded_port", guest: 8081, host: 9081 
config.vm.network "forwarded_port", guest: 9990, host: 9090 
config.vm.network "forwarded_port", guest: 8983, host: 8983 
config.vm.network "forwarded_port", guest: 8985, host: 8985 
config.vm.network "forwarded_port", guest: 2181, host: 2181 
config.vm.network "forwarded_port", guest: 8002, host: 8002 
# If true, then any SSH connections made will enable agent forwarding. 
# Default value: false 
# config.ssh.forward_agent = true 

和預期這種情況下旋轉起來:

$ vagrant up 
Bringing machine 'default' up with 'virtualbox' provider... 
==> default: Checking if box 'hashicorp/precise32' is up to date... 
==> default: Resuming suspended VM... 
==> 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 refused. Retrying... 
==> default: Machine booted and ready! 

二審轉發端口客人22舉辦2221:

# Create a forwarded port mapping which allows access to a specific port 
# within the machine from a port on the host machine. In the example below, 
# accessing "localhost:8080" will access port 80 on the guest machine. 
config.vm.network "forwarded_port", guest: 8080, host: 10080 
config.vm.network "forwarded_port", guest: 80, host: 45678 
config.vm.network "forwarded_port", guest: 9999, host: 10999 
config.vm.network "forwarded_port", guest: 9000, host: 10900 
config.vm.network "forwarded_port", guest: 22, host: 2221 

但是,當它旋轉起來,我仍然得到端口22222衝突:

$ vagrant up 
Bringing machine 'default' up with 'virtualbox' provider... 
==> default: Checking if box 'hashicorp/precise32' is up to date... 
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 2222 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: 22, 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. 

所以我有這個工作,3個月前有兩個相同的流浪文件。似乎在沒有相應的文檔更改的情況下,已經對底層的「hashicorp/precise32」框進行了更新,並且不再允許對ssh端口進行修改?更新config.ssh.port似乎需要更改底層映像。

想法?

============================================== ==== 更新: 啓動的第二實例(向前22 => 2221),則重新加載產生以下輸出:

$ vagrant up 
Bringing machine 'default' up with 'virtualbox' provider... 
==> default: Checking if box 'hashicorp/precise32' is up to date... 
==> default: Resuming suspended VM... 
==> 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 refused. Retrying... 
==> default: Machine booted and ready! 

[email protected] /cygdrive/c/Gui-again 
$ vagrant reload 
==> default: Attempting graceful shutdown of VM... 
==> default: Checking if box 'hashicorp/precise32' is up to date... 
==> 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: Forwarding ports... 
    default: 8080 => 10080 (adapter 1) 
    default: 80 => 45678 (adapter 1) 
    default: 9999 => 10999 (adapter 1) 
    default: 9000 => 10900 (adapter 1) 
    default: 22 => 2221 (adapter 1) 
    default: 22 => 2222 (adapter 1) 
==> 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: The guest additions on this VM do not match the installed version of 
    default: VirtualBox! In most cases this is fine, but in rare cases it can 
    default: prevent things such as shared folders from working properly. If you see 
    default: shared folder errors, please make sure the guest additions within the 
    default: virtual machine match the version of VirtualBox you have installed on 
    default: your host and reload your VM. 
    default: 
    default: Guest Additions Version: 4.2.0 
    default: VirtualBox Version: 4.3 
==> default: Mounting shared folders... 
    default: /vagrant => C:/OSC/PBD-Gui-again 
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision` 
==> default: to force provisioning. Provisioners marked to run always will still run 

所以某處SSH端口正在被迫2222這不是流浪文件本身,還有什麼地方看?

回答

4

你可以嘗試添加一個「身份證SSH」到底

config.vm.network :forwarded_port, guest: 22, host: 2221, id: 'ssh' 

或者,也許這對你的作品,首先關閉SSH端口(視流浪版本)

config.vm.network :forwarded_port, guest: 22, host: 2221, id: "ssh", disabled: true 
config.vm.network :forwarded_port, guest: 22, host: 2221, auto_correct: true 

來源: https://github.com/mitchellh/vagrant/issues/3232

+0

這樣做。我必須將VM轉發到端口22,然後在更改之前重新加載它,但我可以忍受這一點。謝謝! – LizH

相關問題