📜 ⬆️ ⬇️

Work with KVM virtual machines. Introduction

As promised , I begin a series of articles on how we did the rental service of dedicated servers based on KVM .

In this introductory article, I will briefly describe all the software tools used in the development of the service. More details about them will be discussed in the following articles.


')

Debian



Debian

Why Debian ? This operating system is close and clear to me, so when choosing a distribution kit, torment, anguish and throwing were not tested. He has no particular advantages over Red Hat Enterprise Linux, but it was decided to work with a familiar system.

If you plan to independently deploy the infrastructure using similar technologies, I would advise RHEL to take it: thanks to good documentation and well written application programs, it will be two times easier, then surely two times easier, and thanks to an advanced certification system, you can easily will find a number of professionals at the proper level of friends in this OS.

We repeat, we decided to use Debian Squeeze with a set of Sid / Experimental packages and some packages backported and assembled with our patches.
The plans have a publication repository with packages.

KVM



KVM

When choosing a virtualization technology, two options were considered - Xen and KVM.

I note that I personally do not know Xen very well, its architecture, and even more minor features - I mostly got to know him as a guest. There is no reason to say that Xen is bad (because it has not yet fully entered the core, or it has something wrong with performance, or for some other reason). Nothing definite can be said in terms of performance: in some tests, KVM is 10–20 percent ahead of Xen in all indicators, and in some places Xen wins. In fact, at the moment they are almost equal in functionality, performance, reliability. And in principle, the day is near when Xen will also enter the core . Already included in the kernel virtually-a-machine.blogspot.com/2011/06/xen-support-in-mainline-linux-kernel.html .

Also, the fact of the presence of a huge number of developers, hosters, and commercial solutions based on Xen was taken into account - the more interesting it was to implement the solution based on KVM.

The main reason why we decided to use KVM is the need to run virtual machines with FreeBSD and, in the long run, MS Windows.

libvirt


libvirt

To manage virtual machines, it turned out to be extremely convenient to use libvirt and products that use its API: virsh , virt-manager , virt-install , etc.

libvirt is a system that stores virtual machine settings, manages them, keeps statistics on them, makes sure that the interface rises at the start of the virtual machine, connects devices to the machine - in general, performs a lot of useful work and a little more.

Of course, the solution is not perfect. Of the minuses libvirt should be called:



cgroups



cgroups

The main problem in the implementation of the service at the very beginning seemed to be the limitation of resources for virtual machines. In Xen, this problem was solved with the help of an internal sheduler that allocates resources between virtual machines - and what is the most beautiful, it was possible to limit disk operations as well.

In KVM, nothing like this happened until the cgroups core resource allocation mechanism appeared. As usual in Linux, access to these functions was implemented through the special cgroup file system, in which, using the usual write () system calls, you could add a process to a group, assign it its weight in parrots, specify the kernel on which it will work, specify the disk bandwidth that this process can use, or, again, assign it a weight.

The profit is that all this is implemented inside the kernel, and it can be used not only for the server, but also for the desktop (which was used in the famous “ The ~ 200 Line Linux Kernel ”). And in my opinion, this is one of the most significant changes in the 2.6 branch, not counting the favorite # 12309 , and not the regular file system. Well, unless, except POHMELFS (but it is pure because of the name).

libguestfs



libguestfs

I have a very ambiguous attitude towards this utility library.

On the one hand, it looks like this:

libguestfs is a swiss knife


And yet this thing is damn difficult to build from source, and even more so in a package: sometimes it seems to me that Linux From Scratch is somewhat easier to build from scratch.

On the other hand, it’s a very powerful thing that allows you to create images for virtual machines, modify them, compress, install grub, modify partition tables, manage configuration files, transfer “iron” machines to a virtual environment, transfer virtual machines from one image to another, transfer virtual machines from the image to the iron and, frankly, here my imagination brings a little. Oh yes: you can still run the daemon inside a Linux virtual machine and access the virtual machine data live, and do all this on the shell, python, perl, java, ocaml. This is a short and far from complete list of what can be done with libguestfs .

Interestingly, most of the code in libguestfs is generated at build time, as well as the project documentation. Ocaml, perl is very widely used. The code itself is written in C, which then turns into OCaml, and repeated pieces of code are generated by themselves. Working with images is carried out by launching a special service image (supermin appliance), to which commands are sent through the channel. Inside this image there is some rescue set of utilities, such as parted, mkfs and other useful tools for the system administrator.

I recently began to use it even at home when I picked out the data I needed from the nandroid image. But this requires a kernel with yaffs support.

Other



Below are some more interesting links to the description of the program tools used - read and study yourself if interested. For example, about the utility for mass work with configuration files, KVM best practices from comrades from IBM. Recommend!

  1. A post by Daniel Berrange on using cgroups with KVM and LXC.
  2. Richard Jones post about using libguestfs to get a small size of the “base” image of a virtual machine.
  3. BKL # 12309 at bugzilla.kernel.org


In the next part



The next part will be about installing the necessary programs, and their basic configuration.

Source: https://habr.com/ru/post/120432/


All Articles