我想在带有 Vagrant (2.4.3) 和 Qemu (9.2.0) 的 arm64(硅)MacBook Pro 上运行 amd64 AlmaLinux 9 虚拟机。
Vagrant.configure(2) do |config|
config.vm.box = "almalinux/9"
config.vm.provider "qemu" do |qe|
qe.arch = "x86_64"
qe.machine = "q35"
qe.cpu = "qemu64"
qe.net_device = "virtio-net-pci"
qe.extra_netdev_args = "net=192.168.51.0/24,dhcpstart=192.168.51.10"
end
end
但是,使用 almalinux/9 vagrant box 的配置,它在 SSH 步骤中一直挂起:
vagrant up --provider qemu
Bringing machine 'default' up with 'qemu' provider...
==> default: Checking if box 'almalinux/9' version '9.2.20230513' is up to date...
==> default: Importing a QEMU instance
default: Creating and registering the VM...
default: Successfully imported VM
==> default: Warning! The QEMU provider doesn't support any of the Vagrant
==> default: high-level network configurations (`config.vm.network`). They
==> default: will be silently ignored.
==> default: Starting the instance...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:50022
default: SSH username: vagrant
default: SSH auth method: private key
如果我使用 centos/7 vagrant box,它就可以工作:
vagrant up --provider qemu
Bringing machine 'default' up with 'qemu' provider...
==> default: Checking if box 'centos/7' version '2004.01' is up to date...
==> default: Importing a QEMU instance
default: Creating and registering the VM...
default: Successfully imported VM
==> default: Warning! The QEMU provider doesn't support any of the Vagrant
==> default: high-level network configurations (`config.vm.network`). They
==> default: will be silently ignored.
==> default: Starting the instance...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:50022
default: SSH username: vagrant
default: SSH auth method: private key
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
我尝试调试它,但无法弄清楚。看起来只要客户端共享其协议,SSH 服务器就会立即断开或拒绝连接。 “local is”行通常后面跟着一个“remote is”行。
DEBUG ssh: == Net-SSH connection debug-level log START ==
DEBUG ssh: D, [2025-01-05T20:16:26.594185 #17157] DEBUG -- net.ssh.transport.session[b68]: establishing connection to 127.0.0.1:50022
D, [2025-01-05T20:16:26.594651 #17157] DEBUG -- net.ssh.transport.session[b68]: connection established
I, [2025-01-05T20:16:26.594676 #17157] INFO -- net.ssh.transport.server_version[b7c]: negotiating protocol version
D, [2025-01-05T20:16:26.594681 #17157] DEBUG -- net.ssh.transport.server_version[b7c]: local is `SSH-2.0-Ruby/Net::SSH_7.3.0 arm64-darwin'
DEBUG ssh: == Net-SSH connection debug-level log END ==
我还尝试通过串行连接直接登录虚拟机控制台,以查看服务器(虚拟机)端发生了什么。对于 CentOS 7,https://github.com/ppggff/vagrant-qemu#debug 中描述的调试指令有效。我可以通过串行连接以 root 身份登录虚拟机控制台,例如
nc -U /Users/.../qemu_socket_serial
。使用 ps -ef | grep qemu_socket_serial
可以发现正在运行的虚拟机的完整路径。然而,只有在 vagrant 替换 SSH 密钥并且虚拟机成功启动后才有效。因此,对于 AlmaLinux 9,串行连接也会挂起。
我设法通过在 vagrant box 中显式安装 SSH 来使其工作。我在尝试 Alma9 的 docker 实例时发现 ssh 遇到了很多麻烦。我不太明白为什么会发生这种情况,但似乎是最新版本的 Alma9 中的安全限制问题,所以现在当它使用一些基本包创建机器时,您可能需要显式安装它们。
alma9.vm.provision "setup", type: "shell", preserve_order: true, inline: <<-EOF
echo "Install OpenSSH"
yum -y install openssh
EOF