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

问题描述 投票:10回答:3

我开始使用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"和选择的libvirt添加一个CentOS(7)框。之后,我跑了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)
vagrant qemu devops vagrantfile kvm
3个回答
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
投票

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

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

vagrant up

0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.