vagrant初始登錄失敗的一般性解決方案


如果是下載的box文件,vagrant box add和init之后啟動,可能出現長時間無法通過vagrant ssh登陸的問題

==> localvm2: Importing base box 'bigdatavm'...
==> localvm2: Matching MAC address for NAT networking...
==> localvm2: Setting the name of the VM: localvm2
==> localvm2: Fixed port collision for 22 => 2222. Now on port 2200.
==> localvm2: Clearing any previously set network interfaces...
==> localvm2: Preparing network interfaces based on configuration...
    localvm2: Adapter 1: nat
    localvm2: Adapter 2: hostonly
==> localvm2: Forwarding ports...
    localvm2: 22 (guest) => 2200 (host) (adapter 1)
==> localvm2: Running 'pre-boot' VM customizations...
==> localvm2: Booting VM...
==> localvm2: Waiting for machine to boot. This may take a few minutes...
    localvm2: SSH address: 127.0.0.1:2200
    localvm2: SSH username: vagrant
    localvm2: SSH auth method: private key
    localvm2: Warning: Remote connection disconnect. Retrying...
    localvm2: Warning: Remote connection disconnect. Retrying...
    localvm2: Warning: Authentication failure. Retrying...
    localvm2: Warning: Authentication failure. Retrying...
    localvm2: Warning: Authentication failure. Retrying...
    localvm2: Warning: Authentication failure. Retrying...
    localvm2: Warning: Authentication failure. Retrying...
    localvm2: Warning: Authentication failure. Retrying...
    localvm2: Warning: Authentication failure. Retrying...
    localvm2: Warning: Authentication failure. Retrying...

 

這時有兩種可能

一是虛擬機確實啟動失敗,由於vagrant默認不顯示虛機啟動界面,所以不太好判斷。因此需要在Vagrantfile配置中增加vb.gui = true選項,就可以查看虛機的啟動過程。常見問題是沒有開啟PC的vt-x支持,進BIOS修改配置即可。

二是如果使用拷貝過來的Vagrantfile進行up啟動

可能會由於ssh認證機制導致失敗。vagrant默認采用key登錄,但所用的KeyPair可能沒有正常配置。

使用vagrant ssh-config查看

D:\bigdata>vagrant ssh-config
Host localvm1
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile D:/bigdata/.vagrant/machines/localvm1/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL

The provider for this Vagrant-managed machine is reporting that it
is not yet ready for SSH. Depending on your provider this can carry
different meanings. Make sure your machine is created and running and
try again. Additionally, check the output of `vagrant status` to verify
that the machine is in the state that you expect. If you continue to
get this error message, please view the documentation for the provider
you're using.

D:\bigdata>

 

私鑰的地址為D:/bigdata/.vagrant/machines/localvm1/virtualbox/private_key,但實際上本機沒有這個文件。

修改方式1:拷貝本機生成的私鑰到上述路徑;用用戶名密碼(一般約定為vagrant/vagrant)通過shell登陸虛機,修改~/.ssh下的公鑰文件為自己本機生成的公鑰。

下次vagrant up就可以登陸成功了。

 

修改方式2:更改ssh配置為初始密碼登陸(增加password和insert_key配置)

    config.vm.define :localvm3 do |localvm3_config|
        localvm3_config.vm.hostname = "localvm3.vagrant.internal"
        localvm3_config.vm.network :private_network, ip: "192.168.66.33"
        localvm3_config.ssh.password = "vagrant"
        localvm3_config.ssh.insert_key = false
        localvm3_config.vm.provider "virtualbox" do |vb|
            vb.gui = true
            vb.name = "localvm3"
            vb.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
            vb.customize ["modifyvm", :id, "--memory", "2048"]
        end
    end

 

 

* 基於virtualbox


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM