vagrant ssh-config
命令需要超过12秒:
host% time vagrant ssh-config
Host default
HostName 10.0.0.2
User vagrant
Port 22
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /home/user/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
1.614u 0.487s 0:12.27 17.0% 0+0k 0+24io 0pf+0w
host%
这大概是导致vagrant ssh
也需要12秒的原因(相比之下,ssh -p2222 vagrant@localhost
不使用vagrant ssh-config
,仅需1秒钟(。
我的Vagrantfile
是:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-18.10"
config.vm.box_version = "201906.18.0"
config.vm.box_check_update = false
config.vm.hostname = "demo"
config.vm.network :private_network, ip: "10.0.0.2"
# enables, for example, 'ssh vagrant@10.0.0.2'
# None of these actually work. Boo.
#config.ssh.host = "10.0.0.2"
#config.ssh.port = 22
#config.ssh.username = 'root'
#config.ssh.password = 'vagrant'
#config.ssh.insert_key = 'true'
config.vm.provider "virtualbox" do |vb|
vb.name = config.vm.hostname
vb.memory = "2048"
vb.cpus = "2"
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
# config.vm.synced_folder "../data", "/vagrant_data"
config.vm.provision "shell", inline: <<-SHELL
echo "Hello, World!"
SHELL
end
如果我运行 vagrant ssh-config --debug
,它在等待11秒之前打印以下内容:
INFO runner: Preparing hooks for middleware sequence...
INFO runner: 1 hooks defined.
INFO runner: Running action: environment_load #<Vagrant::Action::Builder:0x0000000001e95f60>
DEBUG checkpoint_client: starting plugin check
INFO cli: CLI: [] "ssh-config" []
DEBUG cli: Invoking command class: VagrantPlugins::CommandSSHConfig::Command []
DEBUG checkpoint_client: waiting for checkpoint to complete...
然后打印到这一点:
INFO base: VBoxManage path: VBoxManage
INFO subprocess: Starting process: ["/usr/bin/VBoxManage", "--version"]
INFO subprocess: Command not in installer, restoring original environment...
DEBUG subprocess: Selecting on IO
并悬挂0.5秒,然后再次打印一些其他内容和上面的线,然后再悬挂0.5秒,然后完成。
我希望vagrant ssh-config
只是在查询Vagrant的数据结构,我希望它能有效地实施,以便最多可以完成几毫秒。相反,它在做一些显然参与的事情。
我注意到其他命令(例如vagrant destroy --debug
(具有相似的行为。即,在waiting for checkpoint
之后,他们停了很长时间,在Selecting on IO
之后较短的停顿。
诸如vagrant ssh-config
和vagrant destroy
之类的流式命令是否设计为慢?关于如何使流浪命令运行更快的想法吗?可以绕过慢零件吗?
这不是一个广泛报道的问题,据我所知,没有办法绕过某些部分。如果速度真的很困扰您,我会考虑删除包括~/.vagrant.d
目录,重新启动计算机的所有流浪者,并重新安装从官方流浪者安装程序中的最新版本的Vagrant。看看这是否加快了速度。运行vagrant global-status
以查看运行几个框是否阻碍您的速度也可能很有用。