vargant + kvm

掰断曲别针發表於2024-04-28

Vagrant是為每個人設計的,是建立虛擬化環境的最簡單、最快速的方法。
是一個虛擬機器管理工具,用來方便構建和維護虛擬軟體開發環境。 例如,它可以基於 VirtualBox、VMware、KVM、Hyper-V 和 AWS 甚至是 Docker 等。
以下是在 Arch linux 下,安裝vargant+kvm

安裝kvm

詳見 archlinux 安裝KVM,QEMU

安裝vagrant

安裝vagrant

sudo pacman -S vagrant

安裝libvirt外掛

sudo vagrant plugin install vagrant-libvirt
sudo vagrant plugin install vagrant-mutate  

安裝完成後就可以用了。

排錯

注意:安裝'vagrant-libvirt'時,可能會報錯,在網上找到了解決方案:
https://bbs.archlinux.org/viewtopic.php?id=292146

報錯:

Installing the 'vagrant-libvirt' plugin. This can take a few minutes...
Vagrant failed to properly resolve required dependencies. These
errors can commonly be caused by misconfigured plugin installations
or transient network issues. The reported error is:

conflicting dependencies date (= 3.2.2) and date (= 3.3.4)
  Activated date-3.3.4
  which does not match conflicting dependency (= 3.2.2)

  Conflicting dependency chains:
    date (= 3.3.4), 3.3.4 activated

  versus:
    date (= 3.2.2)

  Gems matching date (= 3.2.2):
    date-3.2.2

執行以下命令解決報錯:

VAGRANT_DISABLE_STRICT_DEPENDENCY_ENFORCEMENT=1 vagrant plugin install vagrant-libvirt 
VAGRANT_DISABLE_STRICT_DEPENDENCY_ENFORCEMENT=1 vagrant plugin install vagrant-mutate 
VAGRANT_DISABLE_STRICT_DEPENDENCY_ENFORCEMENT=1 vagrant plugin  update

vargrant 建立一個虛機

官方檢視可用box: https://app.vagrantup.com/boxes/search?utf8=✓&sort=downloads&provider=&q=ubuntu+22

 mkdir vagrant_workdir
 cd vagrant_workdir 
vagrant init generic/ubuntu2204 
 vagrant up --provider=libvirt 

排錯

報錯資訊

vagrant up --provider=libvirt

-------

Bringing machine 'default' up with 'libvirt' provider...
Error while connecting to Libvirt: Error making a connection to libvirt URI qemu:///system:
Call to virConnectOpen failed: Failed to connect socket to '/var/run/libvirt/virtqemud-sock': No such file or directory

此處 找到靈感:

sudo systemctl status  libvirtd
sudo systemctl enable libvirtd

相關文章