libvirt安装过程

来源:互联网 发布:网络支付安全技术 编辑:程序博客网 时间:2024/06/07 01:26

from: http://blog.csdn.net/hjxhjh/archive/2010/05/15/5594527.aspx

Libvirt comes with direct support for the Python language. If your libvirt is installed as packages, ensure you have the appropriate package installed. This is named libvirt-python on RHEL/Fedora, python-libvirt on Ubuntu, and may be named differently on others. The libvirt-python package contains a module that permits applications written in the Python programming language to use the interface supplied by the libvirt library to use the virtualization capabilities of recent versions of Linux (and other OSes).

 

在Ubuntu9.10下,system->administration->software source下完成系统升级,然后安装一些package:
apt-get install bcc bin86 gawk bridge-utils iproute libcurl3 libcurl4-openssl-dev bzip2 module-init-tools
transfig tgif texinfo texlive-latex-base texlive-latex-recommended texlive-fonts-extra texlive-fonts-recommended
pciutils-dev mercurial build-essential make gcc libc6-dev zlib1g-dev python python-dev python-twisted libncurses5-dev
patch libvncserver-dev libsdl-dev libjpeg62-dev iasl libbz2-dev e2fslibs-dev git-core uuid-dev

接着安装:
apt-get install libvirt-bin
apt-get install libvirt-dev
apt-get install virt-viewer

此时命令行下virsh已经可以使用,包括create XX.xml,suspend domainId,resume domainId等已经可以使用(xx.xml配置文件的格式见a.xml)。
此时如果使用Python脚本编程,还需要安装Python的相关软件:sudo apt-get install python-libvirt以及sudo apt-get install python2.6-libvirt。这样就可以使用Python来控制域了。例如有一个libvtest.py的Python脚本。在命令行下Python libvtest.py就可以运行了。

如果真正使用libvirt C语言动态链接库进行编程还要安装libvirt的安装文件
下载libvirt-0.8.1-tar.gz,解压该文件:tar zxvf libvirt-0.8.1.tar.gz.解压完成后进入到文件夹
libvirt-0.8.1开始安装
1../configure
2.此时提示缺少libxml2,因此需要安装libxml2.sudo apt-get install libxml2 libxml2-dev
3.重新./configure,有提示找不到guntls.
4.安装guntls library。sudo apt-get install gnutls-doc gnutls-bin,sudo apt-get install libneon27-gnutls libcurl4-gnutls-dev.
5.再./configure,又提示缺少device-mapper-devel,
6.从网上下载device-mapper.1.02.28.tgz,然后解压缩tar zxvf device-mapper.1.02.28.tgz,进入解压后的文件夹中:cd device-mapper.1.02.28。安装device-mapper。
  (1)./configure
  (2) sudo make
  (3) sudo make install
然后退出该文件夹,重新安装libvirt。
7.进入libvirt-0.8.1中,./configure,已经没有错误
8.sudo make
9.sudo make install
此时已经安装好了libvirt,不过这时候如果需要使用virsh,需要使用virsh的绝对路径。(此时运行virsh的话会出错,根据提示信息我们认为是因为libvirt版本依赖造成的,为了能利用virsh Shell 脚本,我们可以用到原来的virsh的绝对路径找到这个可执行文件。如、usr/bin/virsh)

C语言库的使用
编辑好.cpp源码(例如myxm.cpp)后,在命令行下编译 g++ myxm.cpp -lvirt -o myxm
然后运行./myxm即可。