使用Vagrant在没有VirtualBox的情况下使用KVM / qemu设置VM

时间:2017-02-10 08:57:55

标签: vagrant qemu devops vagrantfile kvm

我开始使用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

    中的 提供商 部分
    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)

3 个答案:

答案 0 :(得分:5)

使用命令

启动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

兼容

答案 1 :(得分:0)

如果你运行Ruby 2.3,

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

答案 2 :(得分:0)

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

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

vagrant up