【问题标题】:Using Vagrant to set up a VM with KVM/qemu without VirtualBox使用 Vagrant 在没有 VirtualBox 的情况下使用 KVM/qemu 设置 VM
【发布时间】:2017-06-28 13:19:54
【问题描述】:

我正在开始使用 Vagrant,并希望将它与 KVM/qemu(和 Virtual Machine Manager GUI)一起使用,而不是安装 VirtualBox。所以我先安装了 Vagrant:

$ vagrant --version
Vagrant 1.9.1

$ vagrant box list
There are no installed boxes! Use `vagrant box add` to add some

作为per these posts,我需要vagrant-libvirt 才能使其与KVM 一起使用,所以我接下来安装了它:

$ vagrant plugin list
vagrant-libvirt (0.0.37)
vagrant-share (1.1.6, system)

接下来,我使用vagrant box add "centos/7" 添加一个CentOS(7) 框,并在出现提示时选择libvirt。之后,我运行vagrant init 并没有遇到任何错误:

$ vagrant init centos/7
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 似乎出错了,如下所示:

$ vagrant up
No usable default provider could be found for your system.

Vagrant relies on interactions with 3rd party systems, known as
"providers", to provide Vagrant with resources to run development
environments. Examples are VirtualBox, VMware, Hyper-V.

The easiest solution to this message is to install VirtualBox, which
is available for free on all major platforms.

If you believe you already have a provider available, make sure it
is properly installed and configured. You can see more details about
why a particular provider isn't working by forcing usage with
`vagrant up --provider=PROVIDER`, which should give you a more specific
error message for that particular provider.
  • 这是Vagrantfile

    中的provider部分
    config.vm.provider :libvirt do |domain|
        domain.driver = "qemu"
        domain.memory = 512
        domain.cpus = 1
    end
    
  • 我尝试将其修改为:

    config.vm.provider :libvirt do |domain|
        domain.driver = "kvm"
        domain.host = 'localhost'
        domain.uri = 'qemu:///system'
        domain.memory = 512
        domain.cpus = 1
    end
    
  • 我也试过vagrant up --provider=kvmvagrant up --provider=qemuvagrant up --provider=libvirt,但无济于事。

有没有我遗漏的步骤?还是需要安装其他包/依赖项?

编辑: 使用 vagrant 添加centos/7 后,运行vagrant box list 时显示。

$ vagrant box list
centos/7 (libvirt, 1611.01)

【问题讨论】:

  • 添加框后能否重新运行vagrant box list
  • @FrédéricHenri centos/7 出现在列表中。在问题中添加了输出
  • hum .. 你安装的 libvirt 和 qemu 工作正常吗?你能用virshvirt-manager创建qemu或kvm类型的虚拟机吗
  • @FrédéricHenri - 是的,虽然到目前为止我只将它与 GUI (VMM) 一起使用。 $ sudo virsh list 显示正确的输出 12 SS_Work running, like so

标签: vagrant qemu devops vagrantfile kvm


【解决方案1】:

使用命令启动 vagrant box

vagrant up --provider=kvm

虽然https://seven.centos.org/2017/08/updated-centos-vagrant-images-available-v1707-01/已经说过

vagrant-libvirt 插件只兼容 Vagrant 1.5 到 1.8

【讨论】:

【解决方案2】:

您可以使用命令行选项--provider=kvm,也可以设置VAGRANT_DEFAULT_PROVIDER 环境变量:

export VAGRANT_DEFAULT_PROVIDER=kvm  # <-- may be in ~/.profile, /etc/profile, or elsewhere

vagrant up

【讨论】:

    【解决方案3】:

    vagrant-libvirt(0.0.40) 如果您运行 Ruby 2.3,至少在 Linux Mint 18.3 (Ubuntu 16.04) 上与 Vagrant 2.0.2 兼容。我使用了 vagrantUp 网站上 Debian 下载的 vagrant,并使用它安装了插件,没有任何问题。

    【讨论】:

    • 我认为这不是真的。 vagrant-libvirt README 表示“Vagrant-libvirt 支持 Vagrant 1.5、1.6、1.7 和 1.8”。该自述文件还建议不要使用 yum 安装 vagrant。
    • 2019-07-21 更新:引用自述文件:“Vagrant-libvirt 支持 Vagrant 2.0、2.1 和 2.2。它也应该适用于 1.5 以后的早期版本,但它们没有经过积极测试。”
    猜你喜欢
    • 1970-01-01
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-24
    • 2021-05-13
    相关资源
    最近更新 更多