簡體   English   中英

Vagrant 凍結(超時)在 SSH 驗證方法:私鑰

[英]Vagrant freezes (timeouts) at SSH auth method: private key

所以 - 我在谷歌上搜索了一下,發現了大約 100 萬個關於 vagrant 供應和 ssh 代理的問題。 我嘗試了很多解決方案,但沒有任何效果。 我嘗試為 .network 適配器 (VirtualBox) 添加選項,破壞機器,重新安裝 vagrant 等等,每次我需要運行 vagrant 時,這個東西都會阻止我工作。

現在我致力於全新的操作系統安裝(Ubuntu 20.04)。 我按照 oracle 網站上的說明安裝了 VirtualBox 6.1,並從 vagrantup.com/downloads 下載了正確的 vagrant 二進制文件。

再次 - vagrant 管理它立即失敗,好吧 - 讓我們面對現實 - vagrant 有問題,應該更換,但有些項目我不會得到任何預算來遷移到容器,所以我需要使該設置再次工作- 希望有人能為我提供解決方案。 這確實有效。

好的 - 這是最后的vagrant up output:

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 無法連接並運行配置。 它基本上下載了圖像並啟動了它。

所以我嘗試vagrant ssh --debug

我看到的最后幾行:

Checking key permissions: ~/.vagrant.d/insecure_private_key
 INFO ssh: Invoking SSH: /tmp/.mount_vagran2MLjJR/usr/bin/ssh ["vagrant@127.0.0.1", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "Compression=yes", "-o", "DSAAuthentication=yes", "-o", "IdentitiesOnly=yes", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-i", "~/.vagrant.d/insecure_private_key"]

就是這樣 - 命令將失敗,恕不另行通知。

所以我只能殺死虛擬機(關閉使用 vagrant 停止也不會工作:) 並嘗試獲取更多日志:

(只是為了確保我重新安裝了 vbguest 插件)

vagrant up --debug

好的 - 屏幕輸出看起來像一個循環。 而且我只能找到具有給定選項(密鑰路徑等)的“正在嘗試連接 SSH...”

幾分鍾后(我猜是配置的超時)我可以看到:

INFO interface: Machine: error-exit ["Vagrant::Errors::VMBootTimeout", "Timed out while waiting for the machine to boot. This means that\nVagrant was unable to communicate with the guest machine within\nthe configured (\"config.vm.boot_timeout\" value) time period.\n\nIf you look above, you should be able to see the error(s) that\nVagrant had when attempting to connect to the machine. These errors\nare usually good hints as to what may be wrong.\n\nIf you're using a custom box, make sure that networking is properly\nworking and you're able to connect to the machine. It is a common\nproblem that networking isn't setup properly in these boxes.\nVerify that authentication configurations are also setup properly,\nas well.\n\nIf the box appears to be booting properly, you may want to increase\nthe timeout (\"config.vm.boot_timeout\") value."]

這是一些配置:

unless Vagrant.has_plugin?("vagrant-vbguest")
  raise 'vagrant-vbguest is not installed, see README.md!'
end
unless Vagrant.has_plugin?("vagrant-disksize")
  raise 'vagrant-disksize is not installed, see README.md!'
end
Vagrant.configure("2") do |config|
  # https://docs.vagrantup.com
  config.vm.box = "ubuntu/bionic64"
  config.disksize.size = "25GB"

  # forward http traffic
  config.vm.network "forwarded_port", guest: 80, host: 8083
  # forward mysql
  config.vm.network "forwarded_port", guest: 3306, host: 3308
  # forward xdebug
  config.vm.network "forwarded_port", guest: 9000, host: 9000
  # forward elastic
  config.vm.network "forwarded_port", guest: 9200, host: 9200
  # forward solr
  config.vm.network "forwarded_port", guest: 8983, host: 8983

  config.vm.synced_folder ".", "/vagrant",
    type: "virtualbox",
    id: "vagrant-root",
    owner: "vagrant",
    group: "www-data",
    mount_options: ["dmode=775,fmode=664"]

  config.vm.provider "virtualbox" do |vb|
    vb.memory = "8192"
    vb.cpus = 4
    vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ]
    vb.customize [ "modifyvm", :id, "--cableconnected1", "on" ]
  end

  config.vm.provision "shell", path: "config/bootstrap.sh"
  config.vm.provision "shell", path: "config/solr.sh"
  config.vm.provision "shell", path: "config/startup.sh", run: "always"

end

我的問題是 - 我不知道如何解決這個問題。 如果我可以禁用 ssh 身份驗證或使用密碼,我會很高興,但我需要連接到虛擬機才能更改它……即使我可以使用 virtualbox 登錄,我也只能修復我的本地安裝。 但是還有其他人也在處理該代碼,解決方案應該可以解決這個問題。

再次總結一下:

我們處理:

  • 一標Ubuntu 20.04
  • 標准的 VirtualBox 安裝
  • 一個原始的 vagrant 二進制文件

全新安裝

不會工作

親切的問候,菲利普

好的,通過添加以下幾行(此處引用: https : //github.com/hashicorp/vagrant/issues/11777 ),我可以成功地將配置和 ssh 運行到機器中。

config.vm.provider :virtualbox do |v|
  v.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"]
  v.customize ["modifyvm", :id, "--uartmode1", "file", File::NULL]
end

所以你似乎需要什么(目前 - 我 100% 確定下一個 vagrant 的 ssh 問題只有幾個月的時間):

Vagrant.configure("2") do |config|
  config.vm.provider "virtualbox" do |vb|
    vb.customize [ "modifyvm", :id, "--uartmode1", "file", File::NULL ]
    vb.customize [ "modifyvm", :id, "--uart1", "0x3F8", "4" ]
    vb.customize [ "modifyvm", :id, "--cableconnected1", "on" ]
  end
end

我注意到選項vb.customize [ "modifyvm", :id, "--uartmode1", "file", File::NULL ]已經設置為不同的值 ( vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ] ) 並且不知道您是否可以分配多個值或原始選項導致問題。 所以我不能肯定地說更多,如果有人對此有更多見解,額外的解釋會很棒。

我的版本看起來像(只有相關的行):

Vagrant.configure("2") do |config|
  config.vm.provider "virtualbox" do |vb|
    vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ]
    vb.customize [ "modifyvm", :id, "--uartmode1", "file", File::NULL ]
    vb.customize [ "modifyvm", :id, "--uart1", "0x3F8", "4" ]
    vb.customize [ "modifyvm", :id, "--cableconnected1", "on" ]
  end
end

我在我的幾個虛擬機上遇到了同樣的問題:

Vagrant + VirtualBox和 (1) CentOS 7和 (2) Ubuntu 18.04圖片。

有趣的是, CentOS 7 VM 之前在主機上使用端口2229來賓上的端口22進行端口轉發時運行良好。

TLDR:在我的 VM 上重新映射端口轉發解決了我的 Ubuntu VM 的問題,所以我在這里分享這個技巧。

TLDR2: Docker for Windows引起了其他問題,我通過刪除所有與 Windows 相關的虛擬化痕跡(用大錘來完成螺絲刀任務)解決了這些問題。

長話短說:

CentOS VM 上, vagrant ssh-config顯示:

  HostName 127.0.0.1
  User vagrant
  Port 2229
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile "[[[REDACTED]]]/.vagrant/machines/default/virtualbox/private_key"
  IdentitiesOnly yes
  LogLevel FATAL

對我來說值得注意的是IdentityFile showed private_key ,這表明歷史上私鑰已成功設置。

然而,當我發現我的新 Ubuntu VM 存在這個問題時,我返回到 CentOS VM 並發現在vagrant up它現在也在SSH auth method: private key ,這表明我的系統或 VirtualBox 發生了一些變化在更新期間(我已經在運行現在可用的最新 Vagrant, v2.2.19 )。

我檢查了我的新 Ubuntu VM,其中vagrant ssh-config顯示:

Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile [[[REDACTED]]]/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL

我注意到IdentityFileinsecure_private_key

在不深入研究私鑰的情況下,我懷疑可能某些端口被綁定了,所以我重新映射了端口轉發,但通過將此行添加到我的Vagrantfile中,我發現成功有限(即它與 Ubuntu VM 一起工作):

config.vm.network:forwarded_port, guest: 22, host: 8765, id: 'ssh'

主機端口從默認的2222更改為8765 (只是一個隨機端口分配)。

當我運行vagrant destroyvagrant up它啟動了 Ubuntu VM,我能夠成功地vagrant ssh放入 VM。 我運行vagrant destroy只是因為我想重新啟動圖像,而不是因為我有任何跡象表明我需要這樣做。

然而,當我對 CentOS VM 運行同樣的方法時,它仍然超時,所以我正在研究其中的原因。


更新:

我得出的結論是, Docker Destkop for Windows導致我的系統發生一系列變化,這些變化基本上破壞了帶有VagrantVirtualBox

我有以下步驟作為我的最低可行解決方案

  1. 卸載Docker Desktop Client
  2. 禁用與虛擬化或容器相關的一系列 Windows 功能
  3. 檢查CPU-ZIntel Processor Identification Utility以驗證VT-x現在已啟用
  4. 在我有問題的 VM 上運行vagrant reload
  5. 取消選中已cable connected並重新檢查已cable connected
  6. vagrant ssh現在可以使用了。

我將需要一次恢復每個功能,看看在再次破壞之前我能 go 走多遠。

這是各種花絮和指針的屏幕截圖:

(1) 禁用容器 Windows (2) 禁用 Hyper-V (3) 禁用虛擬機平台 (4) 禁用 Windows Hypervisor 平台 (5) 禁用 WSL (6) 現在 VT-x 再次出現(之前沒有出現) ) (7) 現在 SLAT 再次出現(之前沒有出現) (8) CPU-Z 也看到 VT-x

在此處輸入圖像描述

我現在還注意到, Enable Nested VT-x在 VirtualBox 的 CPU 設置菜單上不再灰顯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM