我正在使用 Virtualbox 6.1.12 运行 Vagrant 2.2.9。我的主机操作系统是 Ubuntu 20.04
我需要运行具有不同版本 Ubuntu 的虚拟机:16.04 (xenial)、18.04 (bionic) 和 20.04 (focal)。Xenial 和 Bionic 虚拟机创建正常,我可以通过 SSH 进入它们,但无法通过 SSH 进入 Focal 虚拟机。
简单的.Vagrantfile
:
-*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/focal64"
end
当我尝试启动focal
虚拟机时,vagrant up
该过程卡住了default: SSH auth method: private key
并最终超时:
vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/focal64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/focal64' version '20200720.0.0' is up to date...
==> default: Setting the name of the VM: testfocal_default_1595414135038_3222
==> default: Fixed port collision for 22 => 2222. Now on port 2205.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 (guest) => 2205 (host) (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:2205
default: SSH username: vagrant
default: SSH auth method: private key
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.
If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.
If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.
If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
vagrant ssh
此后也会超时
但是使用 xenial 和 bionic 执行相同的过程可以正常工作,我可以启动虚拟机并通过 SSH 顺利进入它们。
但观察输出就会vagrant ssh-config
发现两者之间存在很大差异:
对于正在运行的 Xenial / Bionic VM,使用的私钥文件是在项目级别创建的:
vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2200
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /home/adria/dev/testbionic/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
但对于 Focal VM 来说,使用的私钥文件是主文件夹中的私钥文件:
vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2203
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /home/adria/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
我以完全相同的方式创建所有虚拟机,所以我不知道为什么在焦点情况下它会选择不同的私钥。如果是因为主机和客户机操作系统相同,我会感到惊讶,但这是我唯一能想到的。
有什么想法或指点吗?