Hello Vagrant
Vagrant部署
1 | $ cd ~/dev |
添加vagrant boxes
1 | $ vagrant box add hashicorp/precise32 # 支持virtualbox Hypervisor |
编辑Vagrantfile
默认使用的是virtualbox作为Hypervisor:
1 | Vagrant.configure("2") do |config| |
运行虚拟机
1 | $ vagrant up |
Vagrant使用KVM Hypervisor
安装vagrant-libvirt plugin:
1 | $ yum install libxslt-devel libxml2-devel libvirt-devel |
配置Vagrantfile:
1 | Vagrant.configure("2") do |config| |
启动虚拟机:
1 | $ vagrant up --provider=libvirt |
小结
Vagrant的box不是对所有hypervisor都通用,比如官方的hashicorp/precise32
就不支持KVM,如果环境只有KVM,那么可能需要自己制作对应的box,可以参考Vagrant-Libvirt Plugin,借助工具create_box.sh
从qcow2 image制作。
此外,需要注意的是,KVM和VirtualBox不能同时启动虚拟机,否则会报类似如下错误:
先启动virtualbox虚拟机再启动KVM虚拟机:
1 | There was an error talking to Libvirt. The error message is shown below: Call to virDomainCreateWithFlags failed: internal error Process exited while reading console log output: char device redirected to /dev/pts/2 kvm_create_vm: Device or resource busy failed to initialize KVM: Operation not permitted No accelerator found! |
先启动KVM虚拟机再启动virtualbox虚拟机:
1 | The guest machine entered an invalid state while waiting for it to boot. Valid states are 'starting, running'. The machine is in the 'poweroff' state. Please verify everything is configured properly and try again. If the provider you're using has a GUI that comes with it, it is often helpful to open that and watch the machine, since the GUI often has more helpful error messages than Vagrant can retrieve. For example, if you're using VirtualBox, run `vagrant up` while the VirtualBox GUI is open. |
参考: