IAAS-libvirt介绍。

Libvirt介绍

 

Libvirthypervisor无关,其提供与多种操作系统虚拟化能力进行交互的API与工具库。

Libvirt提供了一个通用稳定的抽象层,可以安全的操作物理机上的虚拟机,同时为了可以远程交互,Libvirthypervisor支持的范围内提供了创建,修改,监控,迁移,停止 domain的一系列API,虽然可以使用Libvirt同时访问多个物理机,但是API层做了限制,只允许访问单个物理机。

Libvirt被设计为可以支持多种虚拟化环境,这意味着大部分通用的能力在API上是被支持的,也因为此,在于通用型之间为了平衡,一些特殊的能力是不被支持的,譬如不支持虚拟化的告警策略或者多节点管理,不过API的稳定性确保这些特性可以在Libvirt实现。为了保持这种稳定性,Libvirt视图隔离这些虚拟化框架中频繁变更的应用。

Libvirt意在作为单虚拟化节点上的高级管理工具和应用,唯一例外的是虚拟机在多个物理机的迁移能力。提供了一系列API用来定义,监控,和使用管理节点的资源,这些资源包括cpumemorystoragenetwork以及NUMA分区,虽然一个单独的物理机可以被管理程序分配一个管理节点,但是这应该确保使用安全的协议来操作。

术语定义:

术语

定义

Domain

运行在被hypervisor支持的虚拟机的上,表示一个操作系统的实例,对于容器虚拟化来说,表示的是操作系统的子系统。

Hypervisor

相对于物理机来说,有自己特殊配置的可以支持虚拟化的软件层

Node

物理机,可以是不同的类型,譬如存储类型,数据库类型等

Storage Pool

存储池,一个存储介质的集合,例如物理硬盘驱动器,一个存储池被切分为多个卷,这些卷可以分配给一个或者多个虚拟机

Volume

卷,存储池上分配的存储空间,卷可以指定给虚拟机使用,一般更多的是在虚拟机领域内被作为虚拟硬盘驱动器使用

on

对象模型

Libvirt中的对象使用xml进行配置(也就是应用程序与libvirt交互的时候,通过API传输的数据承载体是xml格式)。关于每种对象的xml定义详细参见:https://libvirt.org/format.html

Hypervisor connections

  • 无论作为一个Libvirt的客户端应用运行在本地节点还是通过网络访问远端的节点,都需要建立一个连接
  • 连接是通过virConnectPtr对象管理,并通过URI标记。URI的schema和path决定了连接哪钟hypervisor,而URI的host部分决定是那个hypervisor节点。
  • 允许应用同时建立多个连接,包括一个机器的不同hypervisor。例如一台主机同时支持KVM和LXC虚拟化。
  • 一个连接对象可以被多个线程复用,一旦一个连接被建立,就可能获取其它管理对象的句柄或者创建一个新的管理对象
  • 表示一个正在运行的虚拟机或者一个可以启动虚拟机的配置。
  • 一个Guest domain使用具有唯一标识的一个virDomainPtr对象表示
  • 唯一标识对象具有ID,名称,UID三个属性:

Guest domains

ID:正整数,单个主机上运行状态的虚拟机是唯一的,非运行状态没有ID

Name:字符串,一个主机上的所有虚拟机之间名称唯一,字符串只允许包含:字母数字(A—Z,0—9),连字符(-)和下划线(^)字符

UUID:16字节,任意主机的所有虚拟机之间唯一,RFC4122定义了UUID的格式和提供算法保证唯一性。

  • 提供创建geust domains,管理已经存在的guest dmains的一系列API
  • Geust domain分为零时的和永久的,零时的guest domain只有在其运行状态才可以被管理,一旦关机,其所有痕迹都会消失,永久的guest domain 的配置数据被存储在hypervisor主机的数据存储上,因此,即使断电,依然可以被管理。一个临时的guest 可以在其运行的状态下通过定义配置属性转换为永久的guest

Virtual networks

Virtual networks提供一种在一台主机内,可以连接一个或者多个虚拟机的网络设备的方法。可以支持:

  • 与宿主机的隔离型
  • Allow routing of traffic off-node via the active network interfaces of the host OS. This includes the option to apply NAT to IPv4 traffic.
  • 一个虚拟网络由具有两个唯一标识virNetworkPtr对象表示

Name:字符串,只允许包含:a-Z,0-9,-,_ 字符,在一台主机的所有虚拟网络之间Name唯一

UUID:16字节,任意主机的所有虚拟网络之间唯一,RFC4122定义了UUID的格式和提供算法保证唯一性。

  • 虚拟网络也分为零时的和永久的,同Geust domains描述相同。
  • Libvirt被安装后,每个host将获得一个名为default的虚拟网络,其提供DHCP服务为geust,并且允许NAT IP连接到主机的网口,这对于使用间歇性网络的大部分主机很有用,譬如使用无线网络的笔记本。

Storage pools

存储吃对象提供了一种管理一台主机上所有类型存储的机制,例如本地磁盘,逻辑卷组,iSCSI目标,光线HBA,以及本地/网络文件系统。一个池由表示的是可以被分配为多个独立的卷所组成的数据存储。其使用一对唯一身份的virStoragePoolPtr对象表示。

Name:字符串,只包含a-Z,0-9,-,_ 一台主机上唯一。

UUID:同上

存储池也分为零时的和永久的,同上述定义

 

Storage volumes

存储卷对象提供在一个存储池内的存储块的分配管理。可以是磁盘分区,逻辑卷,SCSI/iSCSI LUN,或者本地/网络文件系统中的文件。一旦被分配,一个卷给一个或者多个虚拟机提供磁盘。

一个卷通过具有三个标识属性的virStorageVolPtr 对象表示。

Name:字符串,只允许包含a-Z,0-9,-,_  一个存储池呢唯一。具有稳定不可变形

Key:一个存储池内唯一,任意字符串,具有稳定不可变性

Path:表示卷的文件系统路径,具有稳定不可变性,即使重新启动后也保持不变

Host devices

主机设备提供了主机上可用的硬件设备的视图,包含物理的USB,PCI设备,与提供例如网卡,磁盘,磁盘控制器,声卡等的逻辑设备。设备被排列为可以识别的关系树结构来识别。主机设备使用virNodeDevPtr 对象来标识,有一个通用属性,不过特殊的设备类型可以有自己的唯一标识符

Name:字符串,主机上所有设备中唯一,命名由主机的操作系统决定。名称不能保证在重新启动后保持不变。

物理设备可以从主机OS的驱动程序(可以从geust domain隐式删除所有关联的逻辑设备)解除绑定,物理设备的信息在使用存储和网络API来确定可配置的资源的时候是很有用的

驱动模型

1:屏蔽不同虚拟化技术的差异,稳定,公开的API&ABI集合。不同虚拟化技术有不同的Driver ABI

2:应用程序可以通过指定URI来决定使用哪种虚拟化技术的ABI

3Libvirt对应用程序提供了查询主机支持的hypervisorABI类型额API

 

Hypervisor Driver

Hypervisor

URI

描述

详细介绍

Xen:

xen:///

The open source Xen hypervisor providing paravirtualized and fully virtualized machines.A single system driver runs in the Dom0 host talking directly to a combination of the hypervisor,xenstored and xend

https://libvirt.org/drvxen.html

QEMU

qemu:///system

Any open source QEMU based virtualization technology, including KVM. A single privileged system driver runs in the host managing QEMU processes. Each unprivileged user account also

has a private instance of the driver

https://libvirt.org/drvqemu.html

UML

uml:///system

The User Mode Linux kernel, a pure paravirtualization technology. A single privileged system driver runs in the host managing UML processes. Each unprivileged user account also has a private instance of the driver

https://libvirt.org/drvuml.html

OpenVZ

openvz:///system

The OpenVZ container based virtualization technology, using a modified Linux host kernel.

A single privileged system driver runs in the host talking to the OpenVZ tools

https://libvirt.org/drvopenvz.html

LXC

lxc:///

The native Linux container based virtualization technology, available with Linux kernels since

2.6.25. A single privileged system driver runs in the host talking to the kernel

https://libvirt.org/drvlxc.html

Remote:

 Example URI to talk to Xen over a TLS channel

 xen+tls://somehostname/. Example URI to talk to QEMU over a SASL channel qemu+tcp:///

somehost/system

Generic secure RPC service talking to a libvirtd daemon. Encryption and

authentication using a choice of TLS, x509 certificates, SASL (GSSAPI/Kerberos) and SSH

tunneling. URIs follow the scheme of the desired driver, but with a hostname filled in, and a data

transport name appended to the URI scheme

VMware ESX

vpx://example-vcenter.com/dc1/srv1     (VPX over HTTPS, select ESX server 'srv1' in datacenter 'dc1')

esx://example-esx.com                  (ESX over HTTPS)

gsx://example-gsx.com                  (GSX over HTTPS)

esx://example-esx.com/?transport=http  (ESX over HTTP)

esx://example-esx.com/?no_verify=1     (ESX over HTTPS, but doesn't verify the server's SSL certificate)

https://libvirt.org/drvesx.html

Storage Driver

后端存储类型

详细说明

Directory backend

https://libvirt.org/storage.html#StorageBackendDir

Local filesystem backend

Network filesystem backend

Logical Volume Manager (LVM) backend

Disk backend

iSCSI backend

SCSI backend

Multipath backend

RBD (RADOS Block Device) backend

Sheepdog backend

NodeDevice Driver

LIVirt提供了物理和虚拟主机设备的管理,如USBPCISCSI和网络设备。包括上述设备提供的各种虚拟化能力,例如SR-IOVNPIVMDEVDRM

生成主机设备的xml定义属性如下:

属性

描述

Name

The device's name will be generated by libvirt using the subsystem, like pci and the device's sysfs basename.

Path

正确的指向设备的系统文件路径

Parent

此元素标识设备层次结构中的父节点。如果设备没有任何父级,则该元素的值将对应于设备父级的名称元素或计算机。

Driver

此元素报告在该设备中使用的驱动程序。此元素在输出XML中的存在取决于底层设备管理器(最有可能的UDEV)是否公开了有关驱动程序的信息。

Capability

描述设备的支持特性,有一个决定设备的类型的必须属性。当前支持的属性为: system, pci, usb, usb_device, net, scsi, scsi_host (Since 0.4.7), fc_host, vports, scsi_target (Since 0.7.3), storage (Since 1.0.4), scsi_generic (Since 1.0.7), drm (Since 3.1.0), and mdev (Since 3.4.0). 这些元素可以嵌套,此时可以更进一步指定设备的具体能力。具体支持的设备type的详细使用模型和介绍参见:

https://libvirt.org/drvnodedev.html

远程管理

Libvirt内部对driver提供了可以远程管理Libvirt管理程序的能力,但是并不直接在API上暴漏给应用程序。此外Libvirt内部包含了本地RPC服务。Libvirt-qpid项目提供了QPID消息服务的agent,将所有LIVIVT托管对象和操作暴漏到了消息总线上,暴漏的能力与LibvirtC-API几乎一致

RPC服务的Server端由Libvirtd守护进程提供,守护进程必须运行在被管理的主机上。默认部署中,守护进程只监听本地UNIX socket连接。只允许Libvirt客户端使用SSH隧道传输数据,使用X509证书或SASL凭据。

Transport

Description

Tls

A TCP socket running the TLS protocol on the

wire. This is the default data transport if none is

explicitly requested, and uses a TCP connection

on port 16514. At minimum it is necessary to

configure the server with a x509 certificate

authority and issue it a server certificate. The

libvirtd server can, optionally, be configured

to require clients to present x509 certificates as a

means of authentication.

1:这是Libvirt默认的传输通道

2:TCP端口16514

Tcp

A TCP socket without the TLS protocol on

the wire. This data transport should not be

used on untrusted networks, unless the SASL

authentication service has been enabled

and configured with a plug-in that provides

encryption. The TCP connection is made on port

16509.

1:TCP端口16509

2:没有采用TLS安全协议传输,不应该使用在非信任网络内(如DMZ区),除非启用了SASL身份认证服务并使用提供加密能力的插件配

Unix

A local only data transport, allowing users to

connect to a libvirtd daemon running as a

different user account. As it is only accessible

on the local machine, it is unencrypted. The

standard socket names are /var/run/

libvirt/libvirt-sock for full management

capabilities and /var/run/libvirt/

libvirt-sock-ro for a socket restricted to

read only operations.

1:本地数据传输。

Ssh

The RPC data is tunneled over an SSH

connection to the remote machine. It requires

Netcat (nc) is installed on the remote machine

and that libvirtd is running with the UNIX domain

socket enabled. It is recommended that SSH

be configured to not require password prompts

to the client application. For example, if using

SSH public key authentication it is recommended

an ssh-agent by run to cache key credentials.

GSSAPI is another useful authentication mode

for the SSH transport allowing use of a preinitialized

Keberos credential cache.

1:远端机器必须安装netcat程序

2:Libvirtd守护进程必须打开UNIX socket开关

3:建议ssh配置为不需要对客户端进行密码提示的模式

Ext

Any external program that can make a

connection to the remote machine by means

that are outside the scope of libvirt. If none of

the built-in data transports are satisfactory, this

allows an application to provide a helper program

to proxy RPC data over a custom channel.

 应用可以自定义数据传输通道

efinition

API

支持的客户端语言有: c#, go, java, ocaml, perl, python, php, ruby

https://libvirt.org/docs/libvirt-appdev-guide/en-US/pdf/libvirt-0.9-Application_Development_Guide-en-US.pdf

API涉及的对象有列下,监控统计,配置管理都涉及,对于配置管理基本都是XML数据内容。

 

总结

如上信息主要参考libvirt官网文档,以及API手册。通过此篇应该了解如下信息:

1libvirt支持多种hypervisorstorage,并且应用程序可以基于其规范扩展dirver插件以满足产品使用。

2libvirtAPI有哪些(可以配置管理哪些对象,可以获取哪些对象的哪些指标),如何使用

扩展延伸:

1:既然libvirt层面支持了lxc,为什么还会额外出现libcontainerdocker针对lxc容器的抽象层api),

2:为什么额外会出现lxd(直接操作内核态lxc,提供restAPI,命令行API,守护进程),为什么在openstack生态圈中会出现nova-compute直接到lxd的模式?

3GPU,FPGA等异构专属设备如何通过libvirt操作的详细实践步骤。

猜你喜欢

转载自www.cnblogs.com/hrbeu05/p/9030677.html