Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

Linux 安裝 libvirt 虛擬化管理工具完整教程(Ubuntu 12.04 驗證)

編輯:關於 Linux

libvirt 是虛擬化管理的核心 API 與工具集,支援 KVM、QEMU、Xen、LXC 等多種 Hypervisor。本文記錄在 Ubuntu 12.04 上從原始碼編譯安裝 libvirt 1.1.2 的完整流程,強調關鍵步驟:先裝 virtinst 佔位、正確啟動服務名稱,避開常見坑點。

環境與版本

  • OS:Ubuntu 12.04 LTS (Precise)
  • 目標版本:libvirt 1.1.2
  • 安裝方式:原始碼編譯(套件版本過舊)

關鍵前置步驟:安裝 virtinst 佔位

sudo apt-get install virtinst

原因: virtinst 依賴 libvirt,apt 會安裝舊版 libvirt 作為依賴。後續編譯安裝新版 libvirt 會覆蓋舊版檔案,避免檔案衝突與依賴關係損壞。此步驟極關鍵,網上許多教程遺漏。

依賴套件安裝

sudo apt-get install \
  libxml++2.6-dev libdevmapper-dev libpciaccess-dev \
  python-dev libnl-dev \
  pkg-config libyajl-dev libudev-dev \
  libapparmor-dev libselinux1-dev \
  libgnutls28-dev libsasl2-dev \
  libcurl4-gnutls-dev libssh2-1-dev \
  libpcap-dev libnuma-dev

下載、配置、編譯、安裝

  1. 下載源碼:
    wget https://libvirt.org/sources/libvirt-1.1.2.tar.gz
    tar xzf libvirt-1.1.2.tar.gz
    cd libvirt-1.1.2
  2. 配置:
    ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var \
      --with-qemu --with-lxc --with-network --with-storage-scsi \
      --with-storage-disk --with-storage-fs --with-storage-mpath \
      --with-storage-rbd --with-storage-gluster --with-storage-vstorage \
      --with-interface --with-nwfilter --with-nodedev --with-secdriver \
      --with-driver=qemu --with-driver=lxc --with-driver=network \
      --with-driver=storage --with-driver=nodedev --with-driver=secdriver

    輸出確認關鍵項:QEMU: yes、LXC: yes、Network: yes、Python: yes。

  3. 編譯與安裝:
    make -j$(nproc)
    sudo make install

關鍵服務管理:使用 libvirt-bin 而非 libvirtd

Ubuntu (Upstart/Systemd) 服務名稱為 libvirt-bin,非 libvirtd。

# 啟動
sudo service libvirt-bin start

# 停止
sudo service libvirt-bin stop

# 狀態
sudo service libvirt-bin status

# 開機自啟
sudo update-rc.d libvirt-bin defaults

驗證:

virsh -c qemu:///system list --all
# 或
virsh uri
# 輸出:qemu:///system

常見錯誤與修正

錯誤現象原因修正
libvirtd: unrecognized service服務名錯誤使用 service libvirt-bin
Unable to connect to libvirt daemon服務未啟動或權限不足啟動服務,將使用者加入 libvirt 群組:sudo usermod -aG libvirt $USER
編譯報錯 yajl 缺失缺少開發包sudo apt-get install libyajl-dev
Python binding 缺失configure 未檢測到 python-dev安裝 python-dev 重新 configure

升級與維護建議

  • 生產環境建議使用發行版官方倉庫版本(apt install libvirt-daemon-system libvirt-clients),穩定性更高。
  • 若需新特性,考慮編譯安裝到 /opt/libvirt,透過環境變數切換,避免污染系統目錄。
  • 定期備份 /etc/libvirt/ 配置目錄。

掌握上述流程,即可在 Ubuntu 上成功部署 libvirt 虛擬化管理平台,為上層雲平台(OpenStack、oVirt)或手動虛擬機管理奠定基礎。

Copyright © Windows教程網 All Rights Reserved