【问题标题】:Can't initialize VM using vagrant无法使用 vagrant 初始化 VM
【发布时间】:2016-07-17 11:07:08
【问题描述】:

我无法在 cmd (Windows 10) 上初始化 vagrant 键入 vagrant up,这是日志

`

C:\xampp\apache\ecomex\ecomex>vagrant up
Bringing machine 'ecomex' up with 'virtualbox' provider...
==> ecomex: Loading Berkshelf datafile...
==> ecomex: Sharing cookbooks with VM
==> ecomex: Checking if box 'grtjn/centos-7.0' is up to date...
==> ecomex: Clearing any previously set forwarded ports...
==> ecomex: Updating Vagrant's Berkshelf...
==> ecomex: Resolving cookbook dependencies...
==> ecomex: Fetching 'ecomex' from source at cookbooks/ecomex
==> ecomex: Using apt (3.0.0)
==> ecomex: Using ark (1.0.1)
==> ecomex: Using build-essential (3.2.0)
==> ecomex: Using chef_handler (1.3.0)
==> ecomex: Using ecomex (0.0.1) from source at cookbooks/ecomex
==> ecomex: Using nodejs (2.2.0)
==> ecomex: Using redisio (2.3.0)
==> ecomex: Using seven_zip (2.0.0)
==> ecomex: Using ulimit (0.3.3)
==> ecomex: Using windows (1.39.2)
==> ecomex: Using yum (3.10.0)
==> ecomex: Using yum-epel (0.6.6)
==> ecomex: Vendoring apt (3.0.0) to C:/Users/EruAizen/.berkshelf/vagrant-berkshelf/shelves/berkshelf20160329-4476-mlo9s9-ecomex/apt
==> ecomex: Vendoring ark (1.0.1) to C:/Users/EruAizen/.berkshelf/vagrant-berkshelf/shelves/berkshelf20160329-4476-mlo9s9-ecomex/ark
==> ecomex: Vendoring build-essential (3.2.0) to C:/Users/EruAizen/.berkshelf/vagrant-berkshelf/shelves/berkshelf20160329-4476-mlo9s9-ecomex/build-essential
==> ecomex: Vendoring chef_handler (1.3.0) to C:/Users/EruAizen/.berkshelf/vagrant-berkshelf/shelves/berkshelf20160329-4476-mlo9s9-ecomex/chef_handler
==> ecomex: Vendoring ecomex (0.0.1) to C:/Users/EruAizen/.berkshelf/vagrant-berkshelf/shelves/berkshelf20160329-4476-mlo9s9-ecomex/ecomex
==> ecomex: Vendoring nodejs (2.2.0) to C:/Users/EruAizen/.berkshelf/vagrant-berkshelf/shelves/berkshelf20160329-4476-mlo9s9-ecomex/nodejs
==> ecomex: Vendoring redisio (2.3.0) to C:/Users/EruAizen/.berkshelf/vagrant-berkshelf/shelves/berkshelf20160329-4476-mlo9s9-ecomex/redisio
==> ecomex: Vendoring seven_zip (2.0.0) to C:/Users/EruAizen/.berkshelf/vagrant-berkshelf/shelves/berkshelf20160329-4476-mlo9s9-ecomex/seven_zip
==> ecomex: Vendoring ulimit (0.3.3) to C:/Users/EruAizen/.berkshelf/vagrant-berkshelf/shelves/berkshelf20160329-4476-mlo9s9-ecomex/ulimit
==> ecomex: Vendoring windows (1.39.2) to C:/Users/EruAizen/.berkshelf/vagrant-berkshelf/shelves/berkshelf20160329-4476-mlo9s9-ecomex/windows
==> ecomex: Vendoring yum (3.10.0) to C:/Users/EruAizen/.berkshelf/vagrant-berkshelf/shelves/berkshelf20160329-4476-mlo9s9-ecomex/yum
==> ecomex: Vendoring yum-epel (0.6.6) to C:/Users/EruAizen/.berkshelf/vagrant-berkshelf/shelves/berkshelf20160329-4476-mlo9s9-ecomex/yum-epel
==> ecomex: Clearing any previously set network interfaces...
==> ecomex: Preparing network interfaces based on configuration...
    ecomex: Adapter 1: nat
==> ecomex: Forwarding ports...
    ecomex: 3000 (guest) => 9898 (host) (adapter 1)
==> ecomex: Booting VM...
==> ecomex: Waiting for machine to boot. This may take a few minutes...
    ecomex: SSH address: 127.0.0.1:22
    ecomex: SSH username: vagrant
    ecomex: SSH auth method: private key

`

几分钟后,它会抛出下一条错误消息

等待机器启动时超时。这意味着 Vagrant 无法与内部的来宾机器通信 配置的(“config.vm.boot_timeout”值)时间段。

如果你看上面,你应该能够看到错误 Vagrant 在尝试连接到机器时出现过。这些错误 通常可以很好地提示可能出现的问题。

如果您使用的是自定义框,请确保网络正确 工作,您可以连接到机器。这是一个常见的 在这些框中未正确设置网络的问题。 验证身份验证配置是否也设置正确, 也是。

如果该框似乎可以正常启动,您可能需要增加 超时(“config.vm.boot_timeout”)值。

我的流浪档案

# -*- mode: ruby -*-
# vi: set ft=ruby
VM = 'ecomex'

Vagrant.configure(2) do |config|
  #selecting Cent OS 7.0
  config.vm.box = 'grtjn/centos-7.0'
  config.vbguest.auto_update = false
  # proxy network: Node: 3000 & Apache: 9898
  config.vm.network :forwarded_port, guest: 3000, host:9898, auto_correct: true
  config.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", disabled: "true"

  #VirtualBox setup
  config.vm.define VM
  config.vm.provider :virtualbox do |vb|
    vb.name = VM
  end

  #Fixing issue: stdin is not tty
  ssh_fix = 'bash -c "BASH_ENV=/etc/profile exec bash"'
  config.ssh.shell = ssh_fix unless ARGV[0] == 'ssh'

  #Adding omnibus & bershelf prugins
  config.omnibus.chef_version = :latest
  config.berkshelf.enabled = true
  config.berkshelf.berksfile_path = './Berksfile'

  #Chef provisioning
  config.vm.provision :chef_solo do |chef|
    chef.add_recipe VM
    chef.custom_config_path = 'Vagrantfile.chef'
    chef.json = {
      :nodejs => {
        :install_method => 'package',
        :npm => '2.13.4'
      }
    }
  end

  #start node app
  config.vm.provision :shell do |s|
    s.privileged = false
    s.inline = 'cd /vagrant && pm2 start pm2.json'
  end
end

我访问了这个线程 Vagrant stuck connection timeout retrying 并在我的 vagrant 文件中添加了该行以查看发生了什么

config.vm.provider :virtualbox do |vb|
  vb.gui = true
end

在那之后,screen shows request login 这就是我卡住的地方,因为在输入 'vagrant' 作为登录名和密码之后什么都没有发生。

注意事项:

  • 我使用的是 Windows 10
  • Windows 防火墙已关闭
  • 在 NAT 上设置 VM 网络

对不起我的拼写,我的英语不够好。

感谢您的帮助!

【问题讨论】:

    标签: ssh vagrant


    【解决方案1】:

    您的帖子中有一些有趣的事情:

    1. 根据您 vagrant uped 所在的目录路径 (C:\xampp\apache\ecomex\ecomex),您似乎正在运行 xampp。从 apache/xampp 服务器配置中运行 vagrant 至少可以说是一个有趣的想法。这也让我觉得 xampp 可能会受到干扰(端口 22 或 2222 有什么问题吗?)。

    2. 你能引导和 ssh 进入一个自定义程度较低的 vagrant box 吗?您提供的那个有一堆活动部件,其中许多可能是罪魁祸首。

    3. 您是否从提升的命令提示符运行? (以管理员身份运行)。

    4. 尝试注释掉(在开头添加 #)以下行,因为它们与 ssh 混淆:

      ssh_fix = 'bash -c "BASH_ENV=/etc/profile exec bash"'
      config.ssh.shell = ssh_fix unless ARGV[0] == 'ssh'
      

      让他们成为

      #ssh_fix = 'bash -c "BASH_ENV=/etc/profile exec bash"'
      #config.ssh.shell = ssh_fix unless ARGV[0] == 'ssh'
      
    5. 发布vagrant up --debug的结果(也可以通过vagrant up --debug > vagrantlog.log输出到文件)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-21
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 2023-01-25
      • 1970-01-01
      • 2016-04-01
      • 1970-01-01
      相关资源
      最近更新 更多