编译和安装

1、(1)准备好libvirt-1.3.5安装包,用MobaXterm工具将准备好的libvirt上传到/usr/local/目录下

(2)将libvirt-1.3.5.tar解压到/usr/local/目录下

cd /usr/local/

tar -zxf libvirt-1.3.5.tar.gz

2、配置libvirt

(1)配置libvirt时,需运行libvirt目录下的configure脚本文件。

进入libvirt解压目录下

cd libvirt-1.3.5

[root@localhost libvirt-1.3.5]#./configure

3、编译libvirt

(1)配置。/configure成功后,在libvirt安装目录下执行“make”命令编译。

cd libvirt-1.3.5

[root@localhost libvirt-1.3.5]#make

4、安装libvirt,libvirt 安装会默认安装libvirtd和virsh等可执行程序。

(1)编译完成后执行“make install”安装libvirt

[root@localhost libvirt-1.3.5]# make install

(2)查看libvirtd位置命令:

[root@localhost libvirt-1.3.5]# which libvirtd

(3)查看libvirtd版本号:libvirtd -version

(4) 查看virsh位置命令:

[root@localhost libvirt-1.3.5]# which virsh

(5)查看virsh版本号:

[root@localhost libvirt-1.3.5]# virsh -version

(6)查看libvirtd和virsh的头文件和库文件:

[root@localhost libvirt-1.3.5]# ls /usr/local/include/libvirt

[root@localhost libvirt-1.3.5]# ls /usr/local/lib/libvirt*

5、查看已经安装的libvirt

查看libvirt是否启动,实质是查看libvirt的libvirtd这个守护进程是否启动。

(1) [root@localhost libvirt-1.3.5]# ps -le |grep libvirtd

(2)启动libvirt

[root@localhost libvirt-1.3.5]# service libvirtd start

[root@localhost libvirt-1.3.5]# service libvirtd status

  • libvirt的配置文件

1、libvirt文件配置

(1)libvirt的配置文件一般在/etc/libvirt/目录下

[root@localhost ~]# cd /etc/libvirt

[root@localhost libvirt]# ls

2、libvirt中域的XML配置文件格式

<domain type='kvm'>

<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

<name>libvirt</name>

<uuid>32b95fab-6d78-4e28-beca-2d3988ff8c8e</uuid>

<memory unit='KiB'>1048576</memory>

<currentMemory unit='KiB'>1048576</currentMemory>

<vcpu placement='static'>1</vcpu>

<os>

<type arch='x86_64' machine='pc-1.2'>hvm</type>

<boot dev='hd'/>

<boot dev='cdrom'/>

</os>

<features>

<acpi/>

<apic/>

<pae/>

</features>

<clock offset='utc'/>

<on_poweroff>destroy</on_poweroff>

<on_reboot>restart</on_reboot>

<on_crash>restart</on_crash>

<devices>

<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

<emulator>/usr/local/bin/qemu-system-x86_64</emulator>

<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

<disk type='file' device='disk'>

<driver name='qemu' type='qcow2'/>

<source file='/tmp/ubuntu.img'/>

<target dev='hda' bus='ide'/>

<address type='drive' controller='0' buss='0' target='0' unit='0'/>

</disk>

<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

<disk type='file' device='cdrom'>

<driver name='qemu' type='raw'/>

<source file='/tmp/ubuntu-18.04.5-desktop-amd64.iso'/>

<target dev='hdc' bus='ide'/>

<readonly/>

</disk>

<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

<controller type='usb' index='0'>

<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>

</controller>

<controller type='ide' index='0'>

<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>

</controller>

<interface type='bridge'>

<mac address='52:54:00:78:f9:98'/>

<source bridge='virbr0'/>

<model type='virtio'/>

<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>

</interface>

<input type='mouse' bus='ps2'/>

<graphics type='vnc' port='-1' autoprot='yes'/>

<memballoon model='virtio'>

<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>

</memballoon>

</devices>

</domain>

3、libvirt API使用示例

(1)[root@localhost qemu]#virsh create /etc/libvirt/qemu/demo.xml

[root@localhost qemu]#virsh -c qemu:///session

(2)使用API查询某个域的信息,C语言示例如下:

#include<stdio.h>

#include<stdlib.h>

#include<libvirt/libvirt.h>

virConnectPtr conn=NULL;

virConnectPtr getConn()

{

conn=virConnectOpenReadOnly(NULL);

if(conn==NULL)

{

printf("error,cann't connect!");

exit(1);

}

return conn;

}

int getInfo(int id)

{

virDomainPtr dom=NULL;

virDomainInfo info;

conn=getConn();

dom=virDomainLookupByID(conn,id);

if(dom==NULL)

{

printf("error,cann't find domain!'");

virConnectClose(conn);

exit(1);

}

if (virDomainGetInfo(dom,&info)<0)

{

printf("error,cann't get info!");

virDomainFree(dom);

exit(1);

}

printf("the Domain state is:%c\n",info.state);

printf("the Domain allowed max memory is:%ld KB\n",info.maxMem);

printf("the Domain used memory is:%ld KB\n",info.memory);

printf("the Domain vCPU number is:%d\n",info.nrVirtCpu);

if(dom!=NULL)

{

virDomainFree(dom);

}

if(conn!=NULL)

{

virConnectClose(conn);

}

return 0;

}

int main()

{

getInfo(1);

return 0;

}

(3)编译运行libvirt-conn.c并使用virsh查看当前节点情况

[root@localhost ~]#virsh

virsh#define /etc/libvirt/qemu/demo.xml

virsh#start libvirt

virsh#list

[root@localhost qemu]#ln -s /usr/local/var/run/libvirt /var/run/libvirt

virsh#domname1

virsh#dominfo 1

virsh#list

[root@localhost ~]#vncviewer 172.0.0.1:0

问题解决:

一、问题:

1、问题一:configure: error: You must install the libyajl library & headers to compile libvirt

解决方案:yum install yajl-devel

2、问题:You must install the pciaccess module to build with udev

解决方案:yum install libpciaccess-devel

3、问题:configure: error: You must install device-mapper-devel/libdevmapper >= 1.0.0 to  compile libvirt

解决方案:yum install device-mapper-devel

4、出现问题:checking libxml2 xml2-config >= 2.6.0 ... configure: error: Could not find libxml2 anywhere (see config.log for details).

解决方案:yum install libxml2-devel

5、问题:configure: error: libnl-devel >= 1.1 is required for macvtap support
解决方案: yum -y install libnl-devel

6、问题:启动Libvirt出现问题:libvirtd: error: Unable to obtain pidfile. Check /var/log/messages or run without --daemon for more

解决方案:

(1)查找到libvirtd.pid文件,根据libvirt的安装不同,位置可能不同:

$ sudo find / -name libvirtd.pid

[sudo] password for cloud:

/usr/local/var/run/libvirtd.pid

(2)删除:$sudo rm /usr/local/var/run/libvirtd.pid

(3)启动:$sudo libvirtd -d

Libvirt API的C语言调用相关推荐

  1. python调用libvirt_通过python获取kvm虚拟机的监控信息(基于libvirt API)

    通常在我们的云环境中,为了保证云平台中虚拟机的正常运行,基本都需要这样一个功能,就是收集虚拟机的监控数据,比如cpu的使用率.内存的使用率.磁盘io.网络io等基本信息.可以利用这些信息及时调整云平台 ...

  2. python调用lib_基于python调用libvirt API

    基于python调用libvirt API 1.程序代码 #!/usr/bin/python import libvirt import sys def createConnection(): con ...

  3. libvirt 用c语言编译,基于C语言libvirt API简单小程序

    libvirt API简单小程序 1.程序代码如下 #include #include int getDomainInfo(int id) { virConnectPtr conn = NULL; v ...

  4. python api调用 验证码_Python语言调用创蓝253短信验证码API文档

    本文主要向大家介绍了Python语言调用创蓝253短信验证码API文档,通过具体的内容向大家展示,希望对大家学习Python语言有所帮助. #!/usr/local/bin/python #-*- c ...

  5. 511遇见易语言调用API制作易语言模块

    类模块 集模块 免注册 免查杀模块 多线程模块 创建调用 模块方法名称 视频源码链接 类模块集模块API调用(最新推荐) 易语言模块API视频教程类模块集模块API调用 大漠免注册免查杀类模块(最新推 ...

  6. 易语言调用API控制组合框高度宽度居中下拉方向

    本课视频通过易语言调用API控制了易语言组合框的高度.展开列表.关闭列表.列表项目文字居中,向上弹出下拉框等等. API控制组合框高度宽度居中下拉方向视频教程源码: .版本 2.程序集 窗口程序集_启 ...

  7. 使用IDA PRO+OllyDbg+PEview 追踪windows API 动态链接库函数的调用过程

    标 题: [原创]使用IDA PRO+OllyDbg+PEview 追踪windows API 动态链接库函数的调用过程. 作 者: shayi 时 间: 2015-02-12,05:19:54 链 ...

  8. 《CUDA高性能并行计算》----2.2 需要知道的CUDA API和C语言拓展

    本 节 书 摘 来 自 华 章 出 版 社 <CUDA高性能并行计算> 一 书 中 的 第2章,第2.2节, 作 者 CUDA for Engineers: An Introduction ...

  9. 跨语言调用Hangfire定时作业服务

    背景 Hangfire允许您以非常简单但可靠的方式执行后台定时任务的工作.内置对任务的可视化操作.非常方便. 但令人遗憾的是普遍都是业务代码和hagnfire服务本身聚合在一个程序中运行,极大的限制了 ...

最新文章

  1. ReSharper修改命名风格
  2. linux ls命令 --time-style选项 日期时间格式控制
  3. post xmlrpc.php,宝塔面板WordPress /xmlrpc.php经常被post恶意数据
  4. 软件工程硕士和计算机硕士论文题目,计算机硕士毕业论文答辩自述
  5. 计算机程序输入x是3求输出七年级的题,如图所示是计算机程序计算,若开始输入,则最后输出的结果是  ▲  .  ——青夏教育精英家教网——...
  6. JS基础语法(04)-逗号运算符
  7. bindService执行成功后,低概率出现onServiceConnected没有被调用
  8. 英语笔记-20151209
  9. 从源码编译Chrome(chromium)
  10. scikit-learn学习之贝叶斯分类算法
  11. Python2 倒计时,还不快来掌握 Python3 酷炫的新特性? | 原力计划
  12. J2EE框架技术(SpringMVC) 知识点笔记(2)
  13. Ubuntu 18.04 LTS版本 GoldenDict安装与配置
  14. IP信息解析和地理定位,以及免费GeoLite2-City.mmdb的使用教程
  15. js的间隔调用和延迟调用
  16. 在html5中flex布局详解,Flex布局详解(一)
  17. 推荐机制 协同过滤和基于内容推荐的区别
  18. iOS 中如何识别图片清晰度
  19. 小白终是踏上了这条不归路----小文的mysql学习笔记(8)----分页查询
  20. JAVA之旅(二十八)——File概述,创建,删除,判断文件存在,创建文件夹,判断是否为文件/文件夹,获取信息,文件列表,文件过滤

热门文章

  1. 状态估计3(扩展卡尔曼滤波)
  2. 代理模式——B站动力节点
  3. 中海时代述说电商2020年平台如何选择
  4. 黄色或微黄色油状物DBCO-PEG5-Acid,DBCO-PEG5-COOH,Azadibenzocyclooctyne-PEG5-acid的化学性质
  5. 远程控制基恩士plc
  6. 创建TypeScript工程错误排查
  7. 武汉计算机专业有哪些,武汉有哪些计算机专业的大学
  8. java网上拍卖管理系统设计与实现(SSM项目竞拍)+毕业论文+毕业设计+数据库文档
  9. 利用Python进行数据分析:数据规整(基于DataFrame)
  10. 激励一下自己 一万小时定律