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命令是设计成这么慢的吗?有没有关于如何让流浪命令运行得更快的想法?慢的部分可以绕过吗?
发布于 2019-07-09 02:10:07
这不是一个广泛报道的问题,据我所知,没有办法绕过某些部分。如果速度真的困扰着你,我会考虑删除所有的Vagrant,包括~/.vagrant.d目录,重启你的电脑,并从官方Vagrant installers重新安装最新版本的Vagrant。看看这样会不会加快速度。运行vagrant global-status来查看是否运行几个机器会阻碍您的速度,这可能也很有用。
https://stackoverflow.com/questions/56840361
复制相似问题