KVM 管理工具:libvirt
libvirt 简介
libvirt XML 配置
- 节点 Node:节点是虚机(domain) 运行的物理机器,hypervisor 也运行在节点之上。
- domain: 虚机在 libvirt 中表示为 domain(域),一个 domain 就是一个虚机。
- hypervisor:虚拟机监控器,KVM 就是使用硬件辅助的全虚拟化方案的 hepervisor。
|
disk(磁盘)
|
任何磁盘设备,包括软盘(floppy)、硬盘(hard disk)、光驱(cdrom)或者半虚拟化驱动都使用 <disk> 元素来定义。方式:
<disk type='**' device='**'>。其中:
type 用来指定device source 的类型:"file", "block", "dir", "network", 或者 "volume"。具体的 source 由 <source> 标签定义。
device 用来指定 device target 的类型:"floppy", "disk", "cdrom", and "lun", 默认为 "disk" 。具体的 target 由 <target> 标签定义。
(1)volume 类型的 disk
<disk type='volume' device='disk'> (2)file 类型的 disk
<disk type='file' snapshot='external'> (3)block 类型的 disk
<disk type='block' device='cdrom'> (4)network 类型的 disk
<disk type='network' device='cdrom'> |
|
Host device assignment (主机设备分配)
|
<hostdev mode='subsystem' type='usb'> #USB 设备直接分配 |
|
Network interface (网卡)
|
有几种 interface 类型:
(1)type = ‘network’ 定义一个连接 Virtual network 的 interface
<devices> (2)type=‘birdge’ 定义一个 Bridge to LAN(桥接到物理网络)的interface:前提是主机上存在一个 bridge,该 bridge 已经连到物理 LAN
<interface type='bridge'> #连接到 br0 (3)type=‘ethernet’定义一个使用指定脚本连接到 LAN 的 interface
<devices> (4)type=‘direct’ 定义一个直接连到物理网卡(Direct attachment to physical interface)的 interface:需要 Linux macvtap 驱动支持
<interface type='direct' trustGuestRxFilters='no'> (5)type=‘hostdev’ 定义一个由主机 PCI 网卡直接分配(PCI Passthrough)的 interface:分配主机上的网卡给虚机
<devices> |
|
metadata(元数据)
|
domain 的 metadata,用来表示 domain 的属性,从而区别于其它 domain:
<metadata> |
|
CPU
|
CPU 配置,cpu mode 有三种模式:host-model,custom 和 host-passthrough。
host-model:根据 node 上的 CPU 特性,在 domain 上选择一个最接近的标准 CPU 型号,如果不指定 cpu mode,默认就是 host-model。
custom: 表示基于某个基础 CPU 做个性化定制。
host-passthrough:直接将物理 CPU 特性暴露给虚拟机使用。
<cpu mode='host-model' check='partial'> |
|
cputune
|
cputune 标签可对 cpu 进行更多调节:
<cputune> |
|
os
|
os 标签定义操作系统架构,hvm 表示硬件辅助的虚拟机
<os> |
virsh 创建 domain
[root@compute-1 admin]# virsh list
Id Name State
----------------------------------------------------
1331 instance-00001c38 running
[root@compute-1 admin]# virsh dominfo 1331
Id: 1331
Name: instance-00001c38
UUID: 50df6317-642b-48f3-9a53-fbc3c440f56f
OS Type: hvm
State: running
CPU(s): 6
CPU time: 73898.6s
Max memory: 33554432 KiB
Used memory: 33554432 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: none
Security DOI: 0
[root@compute-1 admin]# virsh vcpuinfo 1331
VCPU: 0
CPU: 11
State: running
CPU time: 12235.4s
CPU Affinity: -----------y-------------------------------------------- VCPU: 1
CPU: 39
State: running
CPU time: 12081.0s
CPU Affinity: ---------------------------------------y----------------
[root@compute-1 admin]# virsh edit 1331
[root@compute-1 admin]# virsh edit demo.xml
[root@compute-1 admin]# virsh create demo.xml
libvirt API
[admin@compute-1 ~]$ virsh -c qemu:///system list
error: failed to connect to the hypervisor
error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission denied
[admin@compute-1 ~]$ virsh -c qemu:///session list
Id Name State
---------------------------------------------------- [admin@compute-1 ~]$ sudo su
[root@compute-1 admin]# virsh -c qemu:///system list
Id Name State
----------------------------------------------------
1331 instance-00001c38 running
1332 instance-00001c3a running [root@compute-1 admin]# virsh list # virsh list 默认 list 当前用户的 domain
Id Name State
----------------------------------------------------
1331 instance-00001c38 running
1332 instance-00001c3a running
[lianhua@controller-0 ~]$ ll /usr/lib64/python2.7/site-packages/libvirt
libvirt_lxc.py libvirt_lxc.pyo libvirtmod_qemu.so libvirt.py libvirt.pyo libvirt_qemu.pyc
libvirt_lxc.pyc libvirtmod_lxc.so libvirtmod.so libvirt.pyc libvirt_qemu.py libvirt_qemu.pyo
#!/usr/bin/python
# Get domain info via libvirt python API
# Test env: python2.7 and libvirt-python-2.0.0 on KVM host import libvirt
import sys def createConnection():
conn = libvirt.openReadOnly(None)
if conn == None:
print "Failed to open connection to QEMU/KVM"
sys.exit(1)
else:
print "connection successfully"
return conn def getDomInfoByName(conn, name):
try:
localDom = conn.lookupByName(name)
except:
print 'Failed to get the domain info with name "%s"' % name
return 1 print "domain id: %d name: %s " % (localDom.ID(), localDom.name())
print "domain state: %s " % (localDom.state(0))
print "domain info: %s " % (localDom.info())
print "vCPUS: %d " % localDom.maxVcpus() def getDomInfoByID(conn, id):
try:
localDom = conn.lookupByID(id)
except:
print 'Failed to get the domain info with id "%d"' % id
return 1 print "lookup domain id: %d, name: %s" % (localDom.ID(), localDom.name()) def closeConnection(conn):
print "close connection session"
try:
conn.close()
except:
print "Failed to close the session"
return 1 if __name__ == '__main__':
name1 = "instance-00002d2e"
name2 = "notExist"
id1 = 321
id2 = 999
conn = createConnection()
getDomInfoByName(conn, name1)
getDomInfoByName(conn, name2)
getDomInfoByID(conn, id1)
getDomInfoByID(conn, id2)
closeConnection(conn)
[root@compute-1 qemu-kvm]# virsh list
Id Name State
----------------------------------------------------
321 instance-00002d2e running [root@compute-1 qemu-kvm]# python libvirt-test.py
connection successfully
domain id: 321 name: instance-00002d2e
domain state: [1, 5]
domain info: [1, 33554432L, 33554432L, 3, 1546499830000000L]
vCPUS: 3
libvirt: QEMU Driver error : Domain not found: no domain with matching name 'notExist'
Failed to get the domain info with name "notExist"
lookup domain id: 321, name: instance-00002d2e
libvirt: QEMU Driver error : Domain not found: no domain with matching id 999
Failed to get the domain info with id "999"
close connection session
KVM 管理工具:libvirt的更多相关文章
- KVM管理工具 WebVirtMgr
WEB管理工具 WebVirtMgr WebVirtMgr是一个基于libvirt的Web界面,用于管理虚拟机.它允许您创建和配置新域,并调整域的资源分配.VNC查看器为来宾域提供完整的图形控制台.K ...
- 虚拟化技术之kvm管理工具virsh常用基础命令(一)
在上一篇博客中,我们了解了KVM基础架构和部署以及图形管理工具virt-manager安装虚拟机的过程,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/13499 ...
- KVM管理工具webvirtmgr的使用
WebVirtMgr的日常配置:添加宿主机,创建虚拟机,磁盘扩容,快照等具体操作记录如下: 一.创建虚拟机 1.创建存储池 点击创建的宿主机,进入虚拟机部署界面 点击“存储池”按钮,创建存储池(即创建 ...
- 虚拟化技术之kvm管理工具virsh常用基础命令(二)
上一篇博客我们主要聊了下virsh 管理kvm虚拟机的命令相关用法和说明,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/13508231.html:今天我们来继 ...
- kvm管理工具Webvirtmgr安装
虚拟机版本vmware workstation 15.5.0 pro (也就是linux版) cat /etc/redhat-release CentOS Linux release 7.4.17 ...
- Mac安装Linux的KVM管理工具virt-manager
安装: brew tap jeffreywildman/homebrew-virt-manager brew install virt-manager virt-viewer 中途会碰到很多问题,可以 ...
- KVM管理工具
Ovirt:功能强大,RHEV的开源版本 WebVirtMgr:virt-manager的WEB模式的替代品 ConVirt:分为开源版.商业版 Openstack:开源框架,复杂程度较高
- 虚拟化技术之kvm WEB管理工具kimchi
在前面的博客中,我们介绍了kvm的各种工具,有基于图形管理的virt-manager.有基于命令行管理的virt-install .qemu-kvm.virsh等等:今天我们来介绍一款基于web界面的 ...
- virsh命令行管理工具
virsh命令行管理工具 Libvirt有两种控制方式,命令行和图形界面 图形界面: 通过执行名virt-manager,启动libvirt的图形界面,在图形界面下可以一步一步的创建虚拟机,管理虚拟机 ...
- 基于KVM、Xen、OpenVZ等虚拟化技术的WEB在线管理工具
1.Proxmox proxmox是一个开源的虚拟化管理平台,支持集群管理和HA.在存储方面,proxmox除了支持常用的lvm,nfs,iscsi,还支持集群存储glusterfs和ceph,这也是 ...
随机推荐
- 中企网安信息科技:协同办公OA信息化管理系统概述
由华企网安总公司北京中企网安信息科技有限责任公司开发的<协同办公OA信息化管理系统>,获得国家版权局颁发的计算机软件著作权登记证书. 协同办公OA信息化管理系统是一种综合性的软件系统,用于 ...
- 如何实现CesiumJS的视效升级?
CesiumJS作为一款强大的地理可视化引擎,为我们提供了丰富的地球数据可视化和交互展示的能力.然而,随着用户需求的不断增加和技术的不断进步,如何进一步提升CesiumJS的视觉效果成为了一个重要的问 ...
- ASR项目实战-架构设计
一般而言,业务诉求作为架构设计的输入. 需求清单 对于语音识别产品而言,需满足的需求,举例如下: 功能需求 文件转写. 长文件转写,时长大于60秒,小于X小时,X可以指定为5. 短文件转写,时长小于6 ...
- Python——第三章:内置函数(上)
Python中的内置函数 基础数据类型相关(38) 和数字相关(14) 数字类型(4) bool--布尔型 int--整型 float--浮点型 complex--虚数 机制转换(3) bin--二进 ...
- Python——第二章:元组
元组 tuple 使用小括号组成 特点: 元组是不可变的,固定了某些数据. t = ("张无忌", "赵敏", "呵呵哒") print(t ...
- hwclock详解
linux下hwclock命令详解 hwclock(hardware clock) 功能说明:显示与设定硬件时钟. 语 法:hwclock [--adjust][--debug][--directis ...
- [ACTF2020 新生赛]Exec 1
[ACTF2020 新生赛]Exec 1 审题 发现题目有ping功能,猜测是命令执行漏洞. 知识点 linux系统命令 解题 先ping127.0.0.1,观察是否正常执行. 发现正常后执行ls / ...
- Vue源码学习(十九):router基本原理
好家伙, 0.什么是路由? 路由就是匹配到对应路径显示对应的组件! 那么我们要如何去实现? 我们来回忆一下这router怎么用的 1. 声明式路由配置:在路由配置对象中,定义路径与组件的映射关系. ...
- .NET技术分享日活动-202107
2021年7月3日下午,个人组织举办了山东地区的第二次山东.NET技术分享日活动.围绕互联网技术.大数据.机器学习.业务实践等方向进行创新技术的实践分享. 本次技术分享日活动面向了山东地区广大的.NE ...
- 一文带你了解Web前端发展历程
摘要:自互联网行业发展以来,web前端不断发展变化着.在前人的基础上,后人有幸能够站在前人的肩膀上行走.前端的发展变化不仅是继承式的迭代,同时也是不断的变革和创造. 一.前端到底是个什么? 简单点说, ...