当使用 Vagrant v.1.8.1 创建两个虚拟机时,第二台虚拟机也想使用端口 2222(即使已解决到端口 2200 的冲突):
这是我的 Vagrantfile:
Vagrant.configure("2") do |config| config.vm.define "master" do |master| master.vm.box = "centos" end
config.vm.define "slave1" do |slave1| slave1.vm.box = "centos" end end
并输出:
Bringing machine 'master' up with 'virtualbox' provider... Bringing machine 'slave1' up with 'virtualbox' provider... ==> master: Importing base box 'centos65'... ==> master: Matching MAC address for NAT networking... ==> master: Setting the name of the VM: tapd-cluster_master_1461971062767_92860 ==> master: Clearing any previously set network interfaces... ==> master: Preparing network interfaces based on configuration... master: Adapter 1: nat ==> master: Forwarding ports... master: 22 (guest) => 2222 (host) (adapter 1) ==> master: Booting VM... ==> master: Waiting for machine to boot. This may take a few minutes... master: SSH address: 127.0.0.1:2222 master: SSH username: vagrant master: SSH auth method: private key master: master: Vagrant insecure key detected. Vagrant will automatically replace master: this with a newly generated keypair for better security. master: master: Inserting generated public key within guest... master: Removing insecure key from the guest if it's present... master: Key inserted! Disconnecting and reconnecting using new SSH key... ==> master: Machine booted and ready! ==> master: Checking for guest additions in VM... ==> master: Mounting shared folders... master: /vagrant => C:/cygwin64/home/randys/vagrant/tapd-cluster ==> slave1: Importing base box 'centos65'... ==> slave1: Matching MAC address for NAT networking... ==> slave1: Setting the name of the VM: tapd-cluster_slave1_1461971109891_81433 ==> slave1: Fixed port collision for 22 => 2222. Now on port 2200. ==> slave1: Clearing any previously set network interfaces... ==> slave1: Preparing network interfaces based on configuration... slave1: Adapter 1: nat ==> slave1: Forwarding ports... slave1: 22 (guest) => 2200 (host) (adapter 1) ==> slave1: Booting VM... ==> slave1: Waiting for machine to boot. This may take a few minutes... slave1: SSH address: 127.0.0.1:2222 slave1: SSH username: vagrant slave1: SSH auth method: private key slave1: Warning: Authentication failure. Retrying... slave1: Warning: Authentication failure. Retrying...
注意 Vagrant 如何尝试连接端口 2222 上的 slave1。