1. What is libvirt?
The trilogy of virtual cloud implementation: virtualization technology implementation-> Virtual Machine Management-> Cluster Resource Management (cloud management ). Various Virtualization Technologies provide basic management tools. For example, start, stop, configure, and connect to the console. ** In this way, there are two problems when building cloud management: ** 1) If hybrid virtual technology is used, the upper layer needs to call different management tools for different Virtualization Technologies, very troublesome. * 2) virtualization technology is developing rapidly, and both system virtualization and container virtualization are developing and evolving. There may be new virtualization technologies that are more in line with the current application scenarios and need to be migrated in the past. In this way, the management platform needs to be significantly modified. In order to adapt to changes, we often use layers to make them transparent, and set an abstract management layer in virtual machines and cloud management. Libvirt is playing this role. With it, the above two problems can be solved. Libvirt provides various APIs for the upper layer to manage different virtual machines. Libvirt is a collection of software for managing virtual machines and other virtualization functions, such as storage management and network management. It includes an api library, a daemon (libmongod), and a command line tool (virsh). libvirt itself is built on an abstract concept. The main goal of libvirt is to provide a set of convenient and reliable programming interfaces for various virtualization tools, and manage a variety of different virtualization provision methods in a single way.
2. Main functions supported by libvirt
Virtual Machine Management:It includes different domain lifecycle operations, such as startup, stop, pause, save, recovery, and migration. Supports hot swapping of multiple device types, including disks, NICS, memory, and CPU.
Remote machine support:As long as libvirt is running on the machine
Daemon, including remote machines, can be accessed and used by all libvirt functions. Supports remote transmission over multiple networks, using the simplest SSH without additional configuration work.
Storage Management:Any host running libvirt daemon can be used to manage different types of storage: Create File images of different formats (qcow2, vmdk, raw, etc) mount nfs sharing, column-specific LVM volume groups, create new LVM volume groups and logical volumes, partition unprocessed disk devices, and mount iSCSI sharing. Because libvirt can work remotely, all of which can be used by remote hosts.
Network Interface Management:Any host running libvirt daemon can be used to manage physical and logical network interfaces. Virtual Nat and routing-Based Network: Any host running libvirt daemon can be used to manage and create virtual networks.
3. Use of libvirt tool virsh:
Below are common commands for virsh:
(InstanceName is the name of the VM instance)
Virsh list # display local active virtual machine virsh list-all # display all local virtual machines (Active + inactive) virsh define ubuntu. XML # define a virtual machine through the configuration file (this virtual machine is not active yet) virsh start InstanceName # Start the non-active virtual machine virsh create Ubuntu named ubuntu. XML # create a virtual machine (after creation, the virtual machine is executed immediately and becomes an active host) virsh suspend InstanceName # Pause the Virtual Machine virsh resume InstanceName # Start the paused Virtual Machine virsh shutdown InstanceName # Shut down the Virtual Machine virsh destroy InstanceName # force stop the Virtual Machine virsh dominfo InstanceName # display the Basic Information # virsh domid InstanceName # display the Virtual Machine ID virsh domuuid InstanceName # display the virtual machine's uuidvirsh domstate InstanceName # display the current state of the Virtual Machine virsh dumpxml InstanceName # display the current configuration of the Virtual Machine file (it may be different from the configuration when defining a virtual machine, when a virtual machine is started, the virtual machine must be assigned an ID number, UUID, VNC port number, and so on) virsh setmem InstanceName 512000 # Set the memory size for the inactive Virtual Machine virsh setvcpus InstanceName 4 # set the number of CPUs for the inactive Virtual Machine virsh edit InstanceName # edit the configuration file (generally after the virtual machine is defined
4. libvirt supports the following virtual technologies:
Currently, the following Virtualization Technologies are supported: xen, qemu, KVM, lxc, openvz, virtualbox, test, storage, and User Mod Linux.
5. libvirt language binding
The libvirt library is implemented in C (C ++ supported) and contains direct support for python. However, it also supports a large number of language bindings. Currently, you have bound Ruby, Java, Perl, and ocaml. Libvirt supports the most popular system programming languages (C and C ++) and Multiple scripting languages. Therefore, libvirt can be easily applied regardless of the language you focus on.
Virtual Machine value libvirt resolution