KVM virtualization solution series KVM management tool-libvirt introduction

As a rising star, KVM dominates the public cloud hypervisor market, such as a large number of cloud vendors based on secondary development of OpenStack. The veteran commercial VMware dominates the private cloud hypervisor market and is still the first choice for small and medium-sized enterprises to build private clouds. However, it is also currently challenged by Hyper-V.

Hypervisor virtualization technology has many implementation methods, such as KVM, QEMU, VMware, XEN, HyperV, etc., and different technologies also make the drivers and APIs they provide diverse and different. With so many hypervisors, is there a tool that provides a unified API interface to manage these hypervisors uniformly? This is the key to cloud capabilities.

Computer scientist David Wheeler has a famous saying: "Any problem in computer science can be solved by adding an intermediate layer." So, can we improve the underlying Hypervisor technology by adding an intermediate layer? Shield the differences and provide a unified API interface for upper-level management tools. The answer is yes.

Libvirt is such a tool. Libvirt provides an intermediate layer between the underlying hypervisor and upper-level management tools. As a middle layer, Libvirt uniformly encapsulates different virtual machines at the bottom layer and provides a unified API for upper-layer management tools, thereby conveniently realizing the management of virtual machines. Its architecture is shown in Figure 1.

Insert image description here

Figure 1. Libvirt architecture

To avoid ambiguity in the terminology used, here are the definitions of some specific concepts used in the libvirt documentation:

concept definition
Node It refers to a physical machine, with the hypervisor and domain running on the node;
Hypervisor It refers to the virtualization software layer, also called a virtual machine monitor, which virtualizes a node so that it can run multiple virtual machines;
Domain It is an operating system instance running on the hypervisor, usually a virtual machine;

The relationship between nodes, hypervisors and domains can be simply represented using Figure 2.

Insert image description here

Figure 2. Relationship between nodes, hypervisors, and domains

1. Introduction to Libvirt

1.1. Libvirt open source software

Libvirt is a free and open source software, and the license used is LGPL. Software programs that use the libvirt API library to call do not have to choose open source and comply with the GPL license.

Libvirt is a collection of software that is an API, daemon, and management tool for managing virtualization platforms.

Libvirt can realize virtual machine management, virtualized network and storage management.

1.2. libvirt main goals

The main goal of Libvirt is to provide a unified API for various underlying hypervisors so that upper-layer management tools can manage multiple different virtualization technologies in a single way.

1.3. Main components of libvirt

Libvirt has three main components, including a long-term stable C language API library, a daemon process (libvirtd) and a default command line tool (virsh).

Libvirt API is a software library that provides virtual machine management support for other virtual machine management tools (such as virsh, virt-manager, etc.).

The Libvirtd daemon is responsible for managing the domain on the node. Management tools such as virsh and virt-manager all need to rely on the libvirtd daemon to indirectly access the Hypervisor and configuration files, so this daemon must be running. If you close this process , then management tools such as virsh and virt-manager will not be available.

Virsh is the default command line tool for virtual machine management in the libvirt open source project, which will be introduced in detail in subsequent chapters.

1.4. Main functions of libvirt

The main functions of Libvirt include the following five parts:

  1. Domain management , various virtual machine life cycle operations, such as starting, stopping, pausing, saving, restoring, and migrating; hot-plug operations of various types of devices, including disks, network interfaces, memory, CPUs, etc.
  2. For remote connections , all functions of libvirt can be executed on the machine running the libvirtd daemon, including remote physical nodes. libvirt supports a variety of remote network connection methods, such as SSH, TCP protocols, TLS encrypted transmission, etc.
  3. Storage management , any node running the libvirtd daemon can use libvirt to manage different types of storage, such as creating different types of file images (qcow2, vmdk, raw, qde, vmdk, etc.), mounting NFS shares, and viewing existing LVM Volume groups, create new LVM volume groups and logical volumes, partition disk devices, mount iSCSI shares, use RDB remote storage supported by Ceph systems, etc. In libvirt, storage management also supports remote management.
  4. Network management , any node running the libvirtd daemon can use libvirt to manage physical and logical network interfaces, view existing network interfaces, configure network interfaces, bridge management, VLAN management, port binding, etc.
  5. Based on virtual NAT and routing networks , any node running the libvirtd daemon can manage and create virtual networks through libvirt. libvirt virtual network implements a router using firewall rules to provide virtual machines with transparent access to the host network.

1.5. libvirt language binding

Libvirt supports multiple language packages, including C, C++, C#, Go, Java, OCaml, Perl, PHP, Python, Ruby, D-Bus and other languages, which is very convenient for development and integration.

1.6. Virtualization supported by libvirt

Libvirt supports a variety of virtualization technologies, including platform virtualization such as KVM, QEMU, Xen, VMware, VirtualBox, and Hyper-V, as well as container virtualization such as OpenVZ and LXC.

1.7. Operating systems supported by libvirt

Libvirt supports a variety of operating systems, including Linux, FreeBSD, Windows, and OS-X.

2. Introduction to Libvirt management tools

Libvirt has been widely used in the industry. Management tools based on Libvirt API include command line tools, graphical tools, Web management tools, cloud management platform tools, etc., as shown in Figure 1.

2.1. Command line tool based on libvirt API

According to the official website of libvirt, the statistics of command line tools based on libvirt API are shown in Table 1.

Table 1. Command line tools based on libvirt API

name Definition
guestfish Guestfish is an interactive shell and command line tool for inspecting and modifying virtual machine file systems. It uses libvirt to find virtual machines and their associated disks.
virsh Virsh is an interactive shell and batch scripting tool that can be used for domain, network and storage management. It is part of the libvirt core distribution.
virt-clone Allows cloning of disk images and configurations of existing virtual machines to form new virtual machines. It automatically copies the data to the new disk image and updates the UUID, MAC address, and name in the configuration.
virt-df Check the utilization of each file system in the virtual machine. This tool looks at the virtual machine disk and determines how much space is being used. It can handle common Linux file systems and LVM volumes.
virt-image Provides a method for deploying virtual appliances. In libvirt, the configuration of the virtual machine (i.e. domain) is described in a portable XML format. During deployment, the configuration of the virtual machine is converted to XML format.
virt-install It provides a convenient and easy-to-use way to install virtual machines, supporting local configuration through CDs and ISO images, as well as remote configuration through NFS, HTTP and FTP.
virt-top It is a tool used to display the running status and resource usage of virtual machines, such as CPU, memory, network and disk utilization, etc.
virt-what A shell script used to detect virtualization platform types. It can detect platform types such as QEMU/KVM, VMware, Hyper-V, VirtualBox, OpenVZ/Virtuozzo, Xen, LXC, IBM PowerVM and Parallels.
step SystemTap is a dynamic method for monitoring and tracking the operations of the running Linux kernel. Starting from version 2.4, the front-end application stap can collect virtual machine data through libvirt.
vagrant-libvirt Vagrant-Libvirt is a Vagrant plugin that manages virtual machines through libvirt, a command-line tool for developers that can deploy and redeploy virtual machine environments very quickly and easily.
virt-lightning Virt-Lightning uses libvirt, cloud-init and libguestfs to allow anyone to quickly spin up new virtual machines. It is very much like the container CLI, but with virtual machines.

2.2. Migration tool based on libvirt API

According to the official website of libvirt, the statistics of migration tools based on libvirt API are shown in Table 2.

Table 2. Migration tools based on libvirt API

name Definition
virt-p2v P2V migration is the migration of physical machines to virtual machines. Then virt-p2v migration is the migration of a physical machine to a KVM virtual machine. The virt-p2v tool is included in libguestfs.
virt-v2v V2V migration is migration between different virtualization environments. Then the virt-v2v migration is virtual machine (Xen, VMware)->KVM virtual machine, and the virt-p2v tool is included in libguestfs.
vmware2libvirt Part of the virt-goodies package, vmware2libvirt is a Python script for migrating vmware images to libvirt.

2.3. Graphical tools based on libvirt API

According to the official website of libvirt, the statistics of graphical tools based on libvirt API are shown in Table 3.

Table 3. Graphical tools based on libvirt API

name Definition
virt-manager It is a general desktop management tool that can manage virtual machines across local and remote access. It is mainly used in personal and small office scenarios and can manage up to 10-20 hosts and virtual machines of the host.
virt-v2v V2V migration is migration between different virtualization environments. Then the virt-v2v migration is virtual machine (Xen, VMware)->KVM virtual machine, and the virt-p2v tool is included in libguestfs.
virt-viewer It is a graphical interface tool for displaying virtual machines. It uses GTK-VNC or SPICE-GTK protocol and uses libvirt API to query the VNC or SPICE server-side information of the virtual machine. It is often used to replace traditional VNC client viewers, because the latter usually does not support SSL/TLS encryption with x509 authentication authorization, while virt-viewer does.
qt-virt-manager Qt GUI for creating and controlling a VM, another virtual entity (aka network, storage, interface, secret, network filter). Integrated LXC/SPICE/VNC viewer for accessing the text console associated with a virtual machine or container.
qt-remote-viewer 用于访问远程桌面或虚拟机的Qt VNC/SPICE查看器。

2.4. IaaS云计算管理平台工具

根据libvirt官方网站的显示,基于libvirt API的IaaS云计算管理平台工具统计如表4所示。

表4. 基于libvirt API的IaaS云计算管理平台工具

名称 释义
Cracow Cloud One CC1系统为私有云计算提供了完整的解决方案。带有管理模块和简单安装程序的直观Web访问界面使您可以轻松受益于私有云计算技术。
Eucalyptus Eucalyptus 是一个开源的,与AWS兼容的,本地部署的IaaS云软件平台。Eucalyptus使用libvirt 虚拟化 API直接与 Xen 和 KVM 管理程序交互。
Nimbus Nimbus是一个开源工具包,专注于为科学界提供IaaS功能,它使用libvirt与所有KVM和Xen虚拟机进行通信。
Snooze Snooze是一个开源的、可扩展的、自动化的、节能的虚拟机管理框架,主要用于私有云。Snooze使用libvirt API实现虚拟机的监控、实时迁移和生命周期管理。
OpenStack CC1系统为私有云计算提供了完整的解决方案。带有管理模块和简单安装程序的直观Web访问界面使您可以轻松受益于私有云计算技术。
Cracow Cloud One OpenStack是一个“云操作系统”,可用于公共云和私有云。它的各个部分负责计算、存储和网络资源,并使用仪表板与用户交互。计算部分使用libvirt来实现 虚拟机的监控、生命周期等的管理。
KubeVirt KubeVirt是个Kubernetes的一个虚拟机管理插件,使其在原本调度容器之余能够并行调度传统虚拟机。
Cherrypop Cherrypop是一个去中心化的云软件,节点自动检测其他节点并自动分配虚拟机和工作负载,宿主机也没有最低限制,非常适合在低端服务器架设云。
ZStack ZStack是一款开源IaaS软件,旨在通过使用API自动管理数据中心内的所有资源(计算、存储、网络等),从而符合软件定义数据中心的原则。ZStack 在管理方面的主要优势是可扩展性、性能和快速、用户友好的部署。

2.5. 软件库工具

根据libvirt官方网站的显示,基于libvirt API的软件库工具统计如表5所示。

表5. 基于libvirt API的库工具

名称 释义
libguestfs Libguestfs是用于访问和修改虚拟机磁盘镜像的一组工具集,它提供了访问和编辑虚拟机中的文件、脚本化修改虚拟机中的信息、监控磁盘使用和空闲的统计信息、P2V、V2V等丰富的功能。
libvirt-sandbox 一个库和命令行工具,用于简化虚拟化沙箱的创建,目前支持 KVM、QEMU 或 LXC 作为后端,与 systemd 的集成有助于对 apache 等系统服务进行沙箱化。
Ruby Libvirt Object bindings 允许使用简单的 ruby 对象来操作管理程序、访客、存储、网络等。它基于本地 ruby 绑定。

2.6. 监控工具

根据libvirt官方网站的显示,基于libvirt API的监控工具统计如表6所示。

表6. 基于libvirt API的监控工具

名称 释义
collectd Libvirt-plugin是collectd的一部分,并收集统计虚拟机操作系统信息。通过这种方式,可以搜集每个虚拟机的CPU、网络接口和块设备使用情况,而无需在虚拟机系统上安装collectd。
host sFlow Host sFlow是一个在KVM管理程序上运行的轻量级代理,它链接到libvirt库并导出所有虚拟机的标准化CPU、内存、网络和磁盘指标。
munin Guido Günther提供的插件允许使用Munin监控各种事物,例如网络和阻止 I/O。
nagios-virt Nagios-virt是一个配置工具,用于向Nagios添加对虚拟化域的监控。您可以使用此工具为Xen或QEMU/KVM虚拟机设置新的Nagios安装,或者与现有的Nagios 安装集成。
PCP PCP libvirt PMDA(插件)是PCP工具包的一部分,提供虚拟机管理程序和虚拟机信息以及完整的虚拟机性能指标集。它支持每个虚拟机的pCPU、vCPU、内存、块设备、网络接口和性能事件指标。

2.7. Web管理工具

根据libvirt官方网站的显示,基于libvirt API的Web管理工具统计如表7所示。

表7. 基于libvirt API的Web管理工具

名称 释义
AbiCloud AbiCloud是一个开源云平台管理器,允许在您的数据中心轻松部署私有云。AbiCloud的主要区别之一是用于管理基础架构的丰富的网络界面,您只需拖放 虚拟机即可部署新服务。
Kimchi Kimchi是一个基于HTML5的KVM管理工具。它旨在尽可能简单地使用KVM并创建您的第一个虚拟机。Kimchi通过libvirt管理KVM虚拟机,使用支持HTML5的浏览器通过Web访问管理界面。
oVirt oVirt是一个私有云平台软件,提供了中型规模集群主机管理能力,可做服务器虚拟化,也可桌面虚拟化。
VMmanager VMmanager是一种用于虚拟化管理的软件解决方案,可用于托管虚拟机和构建云。VMmanager不仅可以管理一台服务器,还可以管理大型虚拟机管理程序集群。它提供了许多功能,例如允许在集群节点之间进行负载平衡的实时迁移、监控 CPU、内存。
mist.io Mist.io是一个开源项目和服务,可以帮助您以统一的方式管理您的虚拟机,为您的所有基础架构(多个公共云提供商、基于OpenStack的公共/私有云、Docker 服务器、裸机服务器和现在的 KVM 管理程序)。
Ravada Ravada是用于管理虚拟桌面基础架构(VDI)的开源工具。它非常容易安装和使用。按照文档,您将在几分钟内准备好部署虚拟机。对用户的唯一要求是Web浏览器和轻量级远程查看器。

3. Libvirt API介绍

Libvirt的核心功能就是提供一套统一的API用来管理虚拟机,libvirt API主要划分为五个大类,如图3所示。

Insert image description here

Figure 3. libvirt API types

  • virConnectPtr
    indicates establishing a connection with the Hypervisor. By calling the virConnectOpen function, the connection is established with the Hypervisor. After the connection is established, the virtual machine of the Hypervisor can be managed. Connecting to the Hypervisor API is a prerequisite for the use of all other APIs.
  • virConnectPtr
    represents an active or defined domain (i.e. exists as a permanent configuration file and storage, but is not currently running on the node). To manage a domain, you must first obtain the domain object virConnectPtr, and then you can operate the domain. After obtaining the domain object virConnectPtr, you can perform domain query, domain life cycle control and other operations.
  • virNetworkPtr
    represents an active or defined network (i.e. exists as a permanent configuration file and storage but is not currently active). libvirt first needs to create a virNetworkPtr object before it can query or control the virtual network.
  • virStorageVolPtr
    represents a storage volume, usually a domain block device, that is, an image file. The management of storage volumes by libvirt is mainly the management of domain image files. The formats of these image files include raw, qcow2, vmdk, qed, etc. To manage storage volumes with libvirt, you first need to create the storage volume object virStorageVolPtr, and then you can query or control it.
  • virStoragePoolPtr
    represents a storage pool, which is a logical area used to allocate and store storage volumes. Libvirt's management of storage pools includes management of local basic file systems, ordinary network shared file systems, iSCSI shared file systems, LVM partitions, etc. libvirt needs to be based on the storage pool object virStoragePoolPtr to perform query and control operations.

Guess you like

Origin blog.csdn.net/jianghu0755/article/details/129776841