Libvirt (1)

Source: Internet
Author: User
Tags systemtap unix domain socket ssh access
Document directory
  • 1.1.1 libvirt Overview
  • 2.1.2 compiling, installation, and configuration of libvirt
1.1 lib1_1.1.1 about libvirt

When talking about KVM management tools, we must first introduce the famous libvirt, because libvirt is currently the most widely used tool for managing KVM virtual machines and application interfaces (APIS ), in addition, some common Virtual Machine management tools (such as virsh, virt-install, and virt-manager) and cloud computing framework platforms (such as openstack, opennebula, and eucalyptus) libvirt application interfaces are used at the underlying layer.

Libvirt is an open-source application interface, daemon process, and management tool designed for more convenient management of platform virtualization technology. It not only provides management of virtualized clients, it also provides management of virtual networks and storage. Although the libvirt project was initially designed for xen, it currently supports KVM and other hypervisors very well. Libvirt supports multiple virtualization solutions, including KVM, qemu, xen, VMWare, virtualbox, and other platform virtualization solutions. It also supports Linux container virtualization systems such as openvz and lxc, it also supports user-mode Linux (UML) virtualization. Libvirt is a free open-source software with a license of lgpl [1] (GNU loose General Public License ), software programs linked using the libvirt library do not need to be open-source and comply with the GPL license. Similar to open-source projects such as KVM and xen, libvirt also has its own developer community. As virtualization and cloud computing have become a technology hotspot in recent years, the libvirt project community is also active. At present, libvirt is developed mainly by RedHat as a powerful support company. As RedHat gradually prefers to support KVM (rather than xen) in virtualization ), therefore, libvirt's support for qemu/KVM is very mature and stable. Of course, companies such as IBM and Novell, as well as a large number of individual developers, contribute a lot to the code of the libvirt project.

Libvirt provides a set of stable C language application interfaces. Currently, libvirt is bound to other popular programming languages, libvirt libraries are available in advanced programming languages such as Python, Perl, Java, Ruby, PHP, and ocaml. Libvirt also provides QMF proxy for message systems (such as Apache qpid) based on amqp (Advanced Message Queue Protocol, this makes it easier to implement message communication between the host and the client, and between the client and the client in the cloud computing management system. Libvirt also provides security measures such as encryption and authentication for secure remote management of virtual clients. It is precisely because libvirt has these powerful functions and more stable application interfaces, and its license (license) is also relatively loose, libvirt application interfaces have been widely used in virtualization-based and cloud computing solutions. They serve as an intermediate adaptation layer connecting underlying hypervisor and upper-layer applications.

Libvirt supports a variety of different hypervisor through a driver-based architecture. Libvirt provides different drivers for different hypervisors: xen drivers, qemu drivers for qemu and KVM, and VMWare drivers for VMware. In the libvirt source code, you can easily find driver source code files such as qemu_driver.c, xen_driver.c, xenapi_driver.c, vmware_driver.c, and vbox_driver.c.

As an intermediate adaptation layer, libvirt makes the underlying hypervisor completely transparent to the upper-layer user space management tools, because libvirt shields the details of the underlying hypervisor, provides a unified and stable API for upper-layer management tools ). Through libvirt, some user space management tools can manage different hypervisors and clients running above. The basic interaction framework between them is shown in 1-1.

Figure 1-1 Virtual Machine Management Tool manages various types of virtual machines through libvirt

Several important concepts involved in libvirt are explained as follows:

1. node: A physical machine that may run multiple virtual clients. Both hypervisor and domain run on the node.

2. hypervisor: Also known as a virtual machine Monitor (vmm), such as KVM, xen, VMWare, and hyper-v. It is an underlying software layer in virtualization, it virtualizes a node and allows it to run multiple virtual clients (different clients may have different configurations and operating systems ).

3. Domain: a client operating system instance running on the hypervisor. The domain is also called an instance (for example, a client in Amazon's AWS cloud computing service is called an instance), a client operating system (Guest OS), and a virtual machine (Virtual Machine ), they all refer to the same concept.

The relationship between nodes, hypervisor, and domain can be expressed in Figure 1-2.

Figure 1-2 Relationship between nodes, hypervisor, and domain

After understanding the concepts of nodes, hypervisor, and domains, the goal of libvirt is to manage the domains on the nodes securely and efficiently, it provides a public and stable software layer. Of course, the management here includes both local and remote management. Specifically, the libvirt management function consists of the following five parts:

(1) domain management: includes the management of various lifecycles of the domain on the node, such as start, stop, pause, save, restore, and dynamic migration. There are also various device hot swapping operations, including disk, Nic, memory, and CPU. Of course, the support for these hot swapping varies with hypervisor.

(2) remote node management: as long as the libmongod daemon is running on the physical node, the remote management program can connect to the node process management operations. After authentication and authorization, all libvirt functions can be accessed and used. Libvirt supports multiple network remote transmission types, such as SSH, TCP socket, Unix domain socket, and TLS encrypted transmission. For example, libmongod is run on example.com and SSH access is allowed, on a remote management machine, you can use the following command line to connect to example.com to manage the domains on it.

Virsh-C qemu + SSH: // root@example.com/System

(3) Storage Management: Any host running the libmongod daemon can manage different types of storage through libvirt, such: create client images of different formats (qcow2, raw, qde, vmdk, etc) mount the NFS shared storage system, view existing LVM volume groups, create new LVM volume groups and logical volumes, partition disk devices, and mount iSCSI shared storage. Of course, in libvirt, storage management also supports remote management.

(4) Network Management: Any host running the libmongod daemon can use libvirt to manage physical and logical network interfaces. Including network interface cards, network interfaces, creating virtual network interfaces, bridging network interfaces, VLAN management, Nat network settings, and assigning virtual network interfaces to clients.

(5) provides a stable, reliable, and efficient application interface (API) to complete the previous four management functions.

Libvirt consists of three parts: the application programming interface (API) library, a daemon (libmongod), and a default command line management tool (virsh ). Application interfaces (APIS) provide library support for Virtual Machine Management for other virtual machine management tools (such as virsh and virt-manager. The libmongod daemon is responsible for managing the domain on the node. When you use various tools to manage virtual machines, the daemon must be running, in addition, this daemon can be divided into two types: libmongod with root permission, which has a large permission and can be used for all supported management work; libmongod with common user permissions, only limited management work can be compared. Virsh is a default Virtual Machine Management command line tool in the libvirt project. This tool is described in section 2.2.

2.1.2 compiling, installation, and configuration of libvirt 1. Compile and install libvirt from source code

If you only use libvirt, you do not need to compile libvirt from the source code. You only need to install the libvirt package on the Linux system. Some advanced users or developers may want to learn more about libvirt, or even modify the source code of libvirt to implement their own functions. Therefore, they still need to understand the process of compiling and installing libvirt from the source code.

The following describes how to compile and install libvirt 1.0.0 on a RHEL 6.3 system.

(1) Before compiling, check and clear libvirt installed on the system (if it has been installed). The command line is as follows:

[Root @ Jay-Linux kvm_demo] # Which libmongod

/Usr/sbin/libmongod

[Root @ Jay-Linux kvm_demo] # rpm-Q libvirt

Libvirt-0.9.10-21.el6.x86_64

[Root @ Jay-Linux kvm_demo] # rpm-e libvirt

[Root @ Jay-Linux kvm_demo] # libmongod-version

-Bash:/usr/sbin/libmongod: no such file or directory

(2) download the source code of libvirt

You can also use the GIT tool to clone the libvirt source code repository in development to your local machine.

Libvirt officially released the source code stored on the Web page is: http://libvirt.org/sources. On this page, the most recent source code tar.gz packages of libbench and compiled RPM packages such as libvirt-devel, libvirt-Python, libvirt-Java, and libvirt-PHP are downloaded. Libvirt also provides FTP download source code site: ftp://lib).org/lib /. Download the libw.-1.0.0.tar.gz source code package and decompress it using the following command line:

[Root @ Jay-Linux kvm_demo] # wget \ http://libvirt.org/sources/libvirt-1.0.0.tar.gz

 

-22:58:24-http://libvirt.org/sources/libvirt-1.0.0.tar.gz

HTTP request sent, awaiting response... 200 OK

Length: 21868950 (21 m) [application/X-gzip]

Saving to: Using libw.-1.0.0.tar.gz"

 

100% [=================>] 21,868,950 K/s in 2 m 29 s

 

23:00:54 (143 KB/S)-required lib1_-1.0.0.tar.gz "saved [21868950/21868950]

[Root @ Jay-Linux kvm_demo] # tar-zxf libvirt-1.0.0.tar.gz

The address of libvirt's latest git code repository under development is GIT: // lib2.16.org/lib2.16.git. You can also browse the code repositories in development, such as libvirt. Git and http://libvirt.org/git/, libvirt-java.git, and libvirt-php.git through web. In addition, the Python code bound to libvirt is stored in the libvirt source code repository (libvirt. Git), and there is no separate libvirt-Python code repository. The command line for downloading the libvirt code repository is as follows:

[Root @ Jay-Linux kvm_demo] # git clone git: // libcmd.org/libcmd.git

Initialized empty git repository in/root/kvm_demo/libvirt/. Git/

Remote: counting objects: 96578, done.

Remote: compressing objects: 100% (15214/15214), done.

Grouping objects: 52% (50926/96578), 51.28 MIB | 26 kib/s

Grouping objects: 52% (50927/96578), 51.31 MIB | 24 kib/s

Remote: Total 96578 (delta 80940), reused 96578 (delta 80940)

Grouping objects: 100% (96578/96578), 91.22 MIB | 63 kib/s, done.

Resolving deltas: 100% (80940/80940), done.

(3) configure and compile libvirt

The method for configuring and compiling libvirt is similar to that for most open-source projects in Linux. It runs the configure script to configure the compiling environment and then uses the make command to compile the environment, run the make install command.

Check which configuration options are available with the command "./configure-help". The command line operation is as follows:

[Root @ Jay-Linux kvm_demo] # cd libvirt-1.0.0

[Root @ Jay-Linux libvirt-1.0.0] #./configure-help

'Configure 'configures libvirt 1.0.0 to adapt to launch kinds of systems.

 

Usage:./configure [Option]… [Var = value]…

 

To assign environment variables (e.g., CC, cflags ...), Specify them

Var = value. See below for descriptions of some of the useful variables.

 

Defaults for the options are specified in brackets.

 

Configuration:

-H,-help display this help and exit

-Help = short display options specific to this package

-Help = recursive display the short help of all the supported ded packages

-V,-version display version information and exit

-Q,-quiet,-silent do not print 'checking... 'Messages

-Cache-file = File Cache test results in file [disabled]

-C,-config-Cache alias for '-Cache-file = config. cache'

-N,-no-create do not create output files

-Srcdir = dir find the sources in dir [configure DIR or '...']

 

Installation directories:

-Prefix = prefix install architecture-independent files in prefix

[/Usr/local]

-Exec-Prefix = eprefix install architecture-dependent files in eprefix

[Prefix]

 

By default, 'Make install' will install all the files in

'/Usr/local/bin','/usr/local/lib' etc. You can specify

An installation prefix other than '/usr/local 'using'-prefix ',

For instance '-Prefix = $ home '.

<! -Hundreds of lines of help options for libvirt configuration are omitted here.->

According to the configuration help information above, if you do not need "-Prefix =Prefix"Parameter specifies the custom installation path. By default, files related to libvirt will be installed in/usr/local/bin and/usr/local/lib directories.

The command for configuring the libvirt compiling environment is "./configure". The command line is as follows:

[Root @ Jay-libvirt-1.0.0] #./configure

Checking for a BSD-compatible install... /Usr/bin/install-C

Checking whether build environment is sane... Yes

Checking for a thread-safe mkdir-P... /Bin/mkdir-P

Checking for gawk... Gawk

Checking whether make sets $ (make )... Yes

Checking how to create a USTAR tar archive... Gnutar

<! -In this example, hundreds of rows of output information are omitted during the configuration process.->

Configure: Readline: Yes

Configure: Python: Yes

Configure: dtrace: No

Configure: numad: No

Configure: XML catalog:/etc/XML/catalog

Configure: init Script: RedHat

Configure: Console locks:/var/lock

Configure:

Configure: Privileges

Configure:

Configure: qemu: Root

Configure:

During the configuration process, the configuration may fail due to the lack of software packages required for compilation. You only need to install the corresponding software package as prompted, and then re-run the "./configure" command to configure the software package. By default, libvirt will configure qemu/KVM and VMWare Driver Support (if you can find the relevant dependent Library Program), libmongod and virsh will also be configured, by default, libvirt is configured to bind python. For xen and hyper-V Support, the configuration program automatically checks whether the current system contains hypervisor-related programs. If the detection succeeds, the corresponding driver is compiled.

The command for compiling libvirt is "make". The command line operation is as follows:

[Root @ Jay-libvirt-1.0.0] # Make-J 4

Make all-recursive

Make [1]: Entering directory '/root/kvm_demo/libvirt-1.0.0 ′

Making all in gnulib/lib

Make [2]: Entering directory '/root/kvm_demo/libvirt-1.0.0/gnulib/lib'

Gen alloca. h

Gen C ++ defs. h

Gen warn-on-use.h

<! -Hundreds of rows of output information during compilation are omitted here.->

Making all in examples/systemtap

Make [2]: Entering directory '/root/kvm_demo/libvirt-1.0.0/examples/systemtap'

Make [2]: Nothing to be done for 'all '.

Make [2]: Leaving directory '/root/kvm_demo/libvirt-1.0.0/examples/systemtap'

Make [2]: Entering directory '/root/kvm_demo/libvirt-1.0.0 ′

Make [2]: Leaving directory '/root/kvm_demo/libvirt-1.0.0 ′

Make [1]: Leaving directory '/root/kvm_demo/libvirt-1.0.0 ′

(4) install libvirt

Root permissions are not required during configuration and compilation, but root permissions are generally required for libvirt installation. Run the make install command to complete libvirt installation. The command line operation is as follows:

[Root @ Jay-libvirt-1.0.0] # make install

Making Install in gnulib/lib

Make [1]: Entering directory '/root/kvm_demo/libvirt-1.0.0/gnulib/lib'

Make install-AM

Make [2]: Entering directory '/root/kvm_demo/libvirt-1.0.0/gnulib/lib'

Make [3]: Entering directory '/root/kvm_demo/libvirt-1.0.0/gnulib/lib'

If test Yes = no; then \

Case 'linux-GNU 'In \

Darwin [56] *) \

Need_charset_alias = true ;;\

<! -Hundreds of lines of output information are omitted during installation.->

Make [2]: Entering directory '/root/kvm_demo/libvirt-1.0.0 ′

Make [2]: Nothing to be done for 'Install-Exec-am '.

/Bin/mkdir-p '/usr/local/lib/pkgconfig'

/Usr/bin/install-C-M 644 libvirt. pc'/usr/local/lib/pkgconfig'

Make [2]: Leaving directory '/root/kvm_demo/libvirt-1.0.0 ′

Make [1]: Leaving directory '/root/kvm_demo/libvirt-1.0.0 ′

(5) Check the installed libvirt

The libvirt installation will install executable programs such as libvirtd and virsh on the system, the libvirt api library will also be installed, and the python binding will be installed to check the installed files, the command line operation is as follows:

[Root @ Jay-Linux libvirt-1.0.0] # Which lib1_d

/Usr/local/sbin/lib1_d

[Root @ Jay-Linux libvirt-1.0.0] # libmongod-version

Libmongod (libvirt) 1.0.0

[Root @ Jay-libvirt-1.0.0] # Which virsh

/Usr/local/bin/virsh

[Root @ Jay-Linux libvirt-1.0.0] # virsh-version

1.0.0

 

[Root @ Jay-Linux libvirt-1.0.0] # ls/usr/local/include/libvirt/

Libvirt. h libvirt-qemu.h virterror. h

 

[Root @ Jay-Linux libvirt-1.0.0] # ls/usr/local/lib/libvirt *

/Usr/local/lib/libvirt. A/usr/local/lib/libvirt-qemu.so/usr/local/lib/libvirt. so.0

/Usr/local/lib/libvirt. La/usr/local/lib/libvirt-qemu.so.0/usr/local/lib/libvirt. so.0.1000.0

/Usr/local/lib/libvirt-qemu.a/usr/local/lib/libvirt-qemu.so.0.1000.0

/Usr/local/lib/libvirt-qemu.la/usr/local/lib/libvirt. So

 

/Usr/local/lib/libvirt:

Connection-driver

 

[Root @ Jay-Linux libvirt-1.0.0] # ls/usr/local/lib64/python2.6/Site-packages/* virt *

/Usr/local/lib64/python2.6/Site-packages/lib+mod. La/usr/local/lib64/python2.6/Site-packages/lib+mod. So

/Usr/local/lib64/python2.6/Site-packages/lib1_mod_qemu.la/usr/local/lib64/python2.6/Site-packages/libvirt. py

/Usr/local/lib64/python2.6/Site-packages/lib1_mod_qemu.so/usr/local/lib64/python2.6/Site-packages/lib1__qemu.py

If you use libraries such as libvirt immediately after installation, you may need to run ldconfig and other tools to update the shared library you just installed.

(6) Compile libvirt from the GIT code repository of libvirt

Compiling and installing lib.pdf from the gitsource code repository is similar to compiling and installing the tar.gz package from the libsource code repository. Here we will only introduce some differences in the pre-compilation configuration (configure. Use libvirt. when configuring the GIT source code repository, you must first run its own autogen. sh. By default, it downloads git: // git.sv.gnu.org/gnulib.git, generates configure configuration scripts based on the template, and initializes makefile files, finally, the configure file is automatically run to configure the compiling environment.

Run the following command to install libvirt from the GIT source code repository ):

[Root @ Jay-Linux kvm_demo] # cd libvirt. Git

[Root @ Jay-Linux libvirt. Git] #./autogen. Sh

[Root @ Jay-Linux libvirt. Git] # Make

[Root @ Jay-Linux libvirt. Git] # make install

By default, the directories installed after configuration and compilation may be different from the default directories provided by the Linux operating system release. For example: in RHEL 6.3, executable programs such as libmongod and virsh installed in the system rpm package are installed in the/usr/sbin/directory, libvirt. so, libvirt-qemu.so and other shared library files are installed in the/usr/lib64/directory, and from the previous step (5) Know That You compile and install, by default, libmongod and virsh are installed in the/usr/local/sbin directory, while libvirt. so, libvirt-qemu.so and so are installed in
/Usr/local/lib/directory. Autogen. the sh script provides the "-System" parameter. If this parameter is configured, the installation directory and the native system are consistent as much as possible, the command line operation is as follows (some command execution output information is omitted ):

[Root @ Jay-Linux libvirt. Git] #./autogen. Sh-System

[Root @ Jay-Linux libvirt. Git] # Make

[Root @ Jay-Linux libvirt. Git] # make install

[Root @ Jay-Linux libvirt. Git] # Which lib1_d

/Usr/sbin/libmongod

[Root @ Jay-Linux libvirt. Git] # Which virsh

/Usr/bin/virsh

[Root @ Jay-Linux libvirt. Git] # ls/usr/lib64/libvirt *

/Usr/lib64/libvirt. A/usr/lib64/libvirt-qemu.so/usr/lib64/libvirt. So

/Usr/lib64/libvirt. La/usr/lib64/libvirt-qemu.so.0/usr/lib64/libvirt. so.0

/Usr/lib64/libvirt-qemu.a/usr/lib64/libvirt-qemu.so.0.1000.0/usr/lib64/libvirt. so.0.1000.0

/Usr/lib64/libvirt-qemu.la/usr/lib64/libvirt-qemu.so.0.9.10/usr/lib64/libvirt. so.0.9.10

 

/Usr/lib64/libvirt:

Connection-driver

2. Install libvirt using a software package

Libvirt-related software packages are provided in many popular Linux versions (such as RHEL 6.x, fedora 17, and Ubuntu 12.10). Install libvirt-related software packages by installing common software packages. You can use Yum or RPM tool to install the corresponding RPM package in RHEL 6.3 currently used by the author, and view the RPM packages related to libvirt installed in a system. The command line is as follows:

[Root @ rhel6u3-ga ~] # Rpm-Qa | grep libvirt

Libvirt-python-0.9.10-21.el6.x86_64

Libvirt-java-javadoc-0.4.7-1.el6.noarch

Libvirt-qmf-0.3.0-6.el6.x86_64

Libvirt-client-0.9.10-21.el6.x86_64

Libvirt-lock-sanlock-0.9.10-21.el6.x86_64

Libvirt-java-devel-0.4.7-1.el6.noarch

Libvirt-0.9.10-21.el6.x86_64

Libvirt-snmp-0.0.2-3.el6.x86_64

Libvirt-java-0.4.7-1.el6.noarch

Libvirt-devel-0.9.10-21.el6.x86_64

Libvirt-cim-0.6.1-3.el6.x86_64

Of course, by default, RHEL 6.3 uses the qemu/KVM virtualization solution. Therefore, qemu-related software packages should be installed. The command line operations for viewing these software packages are as follows:

[Root @ rhel6u3-ga ~] # Rpm-Qa | grep qemu

Qemu-img-0.12.1.2-2.295.el6.x86_64

Qemu-kvm-0.12.1.2-2.295.el6.x86_64

Gpxe-roms-qemu-0.9.7-6.9.el6.noarch

Because libvirt is cross-platform and supports Microsoft's hyper-V virtualization, you can install libvirt on windows, or even compile libvirt. You can go to the libvirt official page to view and download the libvirt installer, http://libvirt.org/sources/win32_experimental/ that can run on Windows. However, because libvirt is mainly developed based on Linux, and most of the developers and individual developers in the companies that support it (such as RedHat) are Linux programmers, libvirt's Windows version is still under development, the development progress is not as fast as libvirt on Linux. The libvirt that can be downloaded is mentioned earlier.
Windows is also an experimental version, rather than an official product release version. Its functions are not guaranteed to be perfect.

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.