我的vagrant 每次启动到 default: SSH auth method: private key 这一步就不动了

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我的vagrant 每次启动到 default: SSH auth method: private key 这一步就不动了相关的知识,希望对你有一定的参考价值。

大概几分钟或者十几分钟后提示Timed out while waiting for the machine to boot. This meansthat Vagrant was unable to communicate with the guest machine withinthe configured ("config.vm.boot_timeout" value) time period. 然后就停了

添加box
如下添加一个debian的box
E:\ubuntu\vagrant-box-ngixn-php-fpm-mysql-redis-nodejs>vagrant box add debian p
ackage.box
==> box: Adding box 'debian' (v0) for provider:
box: Downloading: file://E:/ubuntu/vagrant-box-ngixn-php-fpm-mysql-redis-nod
ejs/package.box
box: Progress: 100% (Rate: 11.0M/s, Estimated time remaining: --:--:--)
==> box: Successfully added box 'debian' (v0) for 'virtualbox'!

vagrantfile
在任何vagrant工程下面都有一个vagrantfile,就像makefile一眼规,用来配置vagrant的欣慰所创建的虚拟机信息。
vagrant使用
添加镜像
vagrant box add abc boxpath[url|path] #abc未名称

开发到开发目录
vagrant init abc #初始化
D:\work\test>vagrant init debian
A Vagrantfile has been placed in this directory. You are now
ready to vagrant up your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
vagrantup.com for more information on using Vagrant.
vagrant up #启动
D:\work\test>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'debian'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: test_default_1413449093680_48484
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
default: /vagrant => D:/work/test
vagrant ssh #ssh登录
D:\work\test>vagrant ssh
ssh executable not found in any directories in the %PATH% variable. Is an
SSH client installed? Try installing Cygwin, MinGW or Git, all of which
contain an SSH client. Or use your favorite SSH client with the following
authentication information shown below:
Host: 127.0.0.1
Port: 2222
Username: vagrant
Private key: C:/Users/zhangwei_f/.vagrant.d/insecure_private_key
开启ssh后使用xshell登录
网络配置
Vagrant的网络有三种模式
1、较为常用是端口映射,就是将虚拟机中的端口映射到宿主机对应的端口直接使用 ,在Vagrantfile中配置:
config.vm.network :forwarded_port, guest: 80, host: 8080
guest: 80 表示虚拟机中的80端口, host: 8080 表示映射到宿主机的8080端口。

开启这个后,如果vagrant已经启动了,在命令行输入 vagrant reload 重启机器,就可以再宿主机伤使用 localhost:8080来访问虚拟机的localhost:80 。

2、如果需要自己自由的访问虚拟机,但是别人不需要访问虚拟机,可以使用private_network,并为虚拟机设置IP ,在Vagrantfile中配置:
config.vm.network :private_network, ip: "192.168.1.104"
192.168.1.104 表示虚拟机的IP,多台虚拟机的话需要互相访问的话,设置在相同网段即可

3、如果需要将虚拟机作为当前局域网中的一台计算机,由局域网进行DHCP,那么在Vagrantfile中配置:
config.vm.network :public_network

目录映射:
既然是开发环境,那么开发工作肯定还是需要在本地完成,而不是都要进到虚拟机中去完成,虚拟机就好好在后台运行服务就好了,不然就本末倒置了,所以这里就需要使用目录映射功能,将本地的目录映射到虚拟机的对应目录。
默认情况下,当前的工作目录,会被映射到虚拟机的 /vagrant 目录,当前目录下的文件可以直接在 /vagrant 下进行访问,当然也可以在通过 ln 创建软连接,如
ln -fs /vagrant/wwwroot /var/www

来进行目录映射,当然,从自动化配置的角度,能不进系统就不需要进系统,所以在Vagrant也可以进行目录映射的操作:
config.vm.synced_folder "wwwroot/", "/var/www"

前面的参数 “wwwroot/” 表示的是本地的路径,这里使用对于工作目录的相对路径,这里也可以使用绝对路径,比如: “d:/www/”
后面的参数 “/var/www” 表示虚拟机中对应映射的目录。
一些命令
vagrant up (启动虚拟机)
vagrant halt (关闭虚拟机——对应就是关机)
vagrant suspend (暂停虚拟机——只是暂停,虚拟机内存等信息将以状态文件的方式保存在本地,可以执行恢复操作后继续使用)
vagrant resume (恢复虚拟机 —— 与前面的暂停相对应)
vagrant destroy (删除虚拟机,删除后在当前虚拟机所做进行的除开Vagrantfile中的配置都不会保留)
vagrant reload (重启)
参考技术A 找不到原因,是因为看不到虚拟机的启动过程。在Vagrantfile中的最后一个end前面加入:
config.vm.provider "virtualbox" do |vb|
vb.gui = true
end
然后删掉目录下的.vagrant文件,命令行窗口重新运行 vagrant up 命令,这时就可以看到启动过程中到底哪里出了问题了。
我的启动卡在 default: SSH auth method: private key 的原因是 “VT-x/AMD-V 硬件加速在您的系统中不可用”,到Bios中找到对应选项修改成enabled 就可以了。
参考技术B 希望能够帮助你!

无法在Ubuntu上启动Vagrant VirtualBox

我只是想尝试启动一些Windows流浪的VirtualBox虚拟机。

vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 5985 (guest) => 55985 (host) (adapter 1)
    default: 5986 (guest) => 55986 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["startvm", "9100d42a-152f-41c7-81f6-c3cc667240a7", "--type", "headless"]

Stderr: VBoxManage: error: The virtual machine 'MSEdgeWin10_preview17_default_1519585578822_41955' has terminated unexpectedly during startup with exit code 1 (0x1)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component MachineWrap, interface IMachine

Vagrant版本:Vagrant 2.0.2 VirtualBox版本:5.2.6r120293 lsb_release -a:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 17.10
Release:    17.10
Codename:   artful

流浪者名单:

IE11-win81              (virtualbox, 0)
msedge-win10-16         (virtualbox, 0)
msedge-win10-17-preview (virtualbox, 0)

Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "msedge-win10-17-preview"

  config.vm.boot_timeout = 500

  config.vm.communicator = "winrm"
  config.winrm.username = "IEUser"
  config.winrm.password = "Passw0rd!"

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
  #   vb.memory = "1024"
  # end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
  # such as FTP and Heroku are also available. See the documentation at
  # https://docs.vagrantup.com/v2/push/atlas.html for more information.
  # config.push.define "atlas" do |push|
  #   push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
  # end

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end

UPDATE

我添加了一个配置来让VirtualBox加载GUI。现在我从GUI弹出窗口中收到此错误:

RTR3InitEx failed with rc=-1912 (rc=-1912)

The VirtualBox kernel modules do not match this version of VirtualBox. The installation of VirtualBox was apparently not successful. Executing

'/sbin/vboxconfig'

may correct this. Make sure that you do not mix the OSE version and the PUEL version of VirtualBox.

where: supR3HardenedMainInitRuntime what: 4 VERR_VM_DRIVER_VERSION_MISMATCH (-1912) - The installed support driver doesn't match the version of the user.

这是我使用的配置(添加到以前的配置):

config.vm.provider 'virtualbox' do |v|
          v.gui = true
end
答案

问题:安装了太多版本的VirtualBox。

我使用StackExchange的这些问题/答案来帮助我:

我怎么发现:

dpkg -l '*virtualbox*' | grep ^i

然后我用这个命令删除VB的包:

sudo apt autoremove --purge virtualbox

还有其他包含VB名称,我删除了所有这些包。

然后我更新了...以防万一:

sudo apt update

然后只需重新安装VB。

以下是确保不再存在导致冲突的错误配置的最后步骤。

删除.vagrant目录:

rm -r .vagrant

删除VirtualBox.xml配置文件并将其替换为干净版本:

rm /home/$USER/.config/VirtualBox/VirtualBox.xml
cp /home/$USER/.config/VirtualBox/VirtualBox.xml-prev /home/$USER/.config/VirtualBox/VirtualBox.xml

从Vagrant中删除一些缓存文件:

rm /home/$USER/.vagrant.d/data/machine-index/index.lock
rm /home/$USER/.vagrant.d/data/machine-index/index

清理VB VM。

首先,您需要获取UUID:

VBoxManage list vms

EG

"MSEdgeWin10_preview17_default_1519845470831_93278" {060622eb-b903-4287-8ac7-fcdf9233a6b9}
"MSEdgeWin10_preview17_default_1519850217620_30972" {e2ca66bc-b64e-4fba-89e5-688c2a2a5fc3}

然后你只需用UUID删除它们:

VBoxManage unregistervm 060622eb-b903-4287-8ac7-fcdf9233a6b9
VBoxManage unregistervm e2ca66bc-b64e-4fba-89e5-688c2a2a5fc3

然后我开始流浪汉:

vagrant up

如果您想要更大的视图,您可能还想在Vagrantfile中扩展vram。

EG

config.vm.provider 'virtualbox' do |v|
    v.gui = true
    v.customize [
      "modifyvm", :id,
      "--vram", "23"
    ]
end

23是MB,这似乎是VB的推荐。

以上是关于我的vagrant 每次启动到 default: SSH auth method: private key 这一步就不动了的主要内容,如果未能解决你的问题,请参考以下文章

无法在Ubuntu上启动Vagrant VirtualBox

端口使用Vagrant转发时连接重置

每次使用 vagrant up 时我都必须删除导出文件

Vagrant卡住连接超时重试

为什么`vagrant up`会失败“ifdown eth1”SSH测试?

vagrant ssh 登陆ubuntu 为啥每次都要输密码?并未在vagrantfile中配置password