Work with KVM virtual machines. Introduction

    As promised , I’m starting a series of articles on how we did the service of renting dedicated servers based on KVM .

    In this introductory article, I will briefly talk about all the software tools used in the process of developing a service. They will be described in more detail in the following articles.



    Debian



    Debian

    Why Debian ? This operating system is close to me and understandable, so when choosing a distribution kit torment, torment and throwing was not tested. It has no special 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 you to take RHEL: thanks to good documentation and well-written application programs, this will be, if not an order of magnitude, then certainly twice as easy, and thanks to the developed certification system, you can easily will find a number of specialists who are familiar at the proper level in this OS.

    We, again, decided to use Debian Squeeze with a set of packages fromSid / Experimental and some packages backported and compiled with our patches.
    The plans include publishing a repository with packages.

    Kvm



    Kvm

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

    I note that personally I do not know Xen very well, its architecture, and even more so minor features - basically I met him as a guest. There is no reason to say that Xen is somehow bad (because it has not yet fully entered the kernel, or it has something wrong with the 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 respects, but somewhere it wins Xen. In fact, at the moment they are almost equal in functionality, performance, reliability. And, in principle, the day is not far off when Xen will also enter the core . Already part of the kernelvirtually-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 using its API: virsh , virt-manager , virt-install , etc.

    libvirt is a system that stores the settings of virtual machines, manages them, keeps statistics on them, monitors them so that the interface rises at the start of the virtual machine, connects devices to the machine - in general, it does a lot of useful work and a little more than that.

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

    • Absolutely insane error messages.
    • Inability to change part of the virtual machine configuration on the fly, although QMP ( QEMU Monitor Protocol ) allows this.
    • Sometimes for some reason it is impossible to connect to libvirtd - it stops responding to external events.


    cgroups



    cgroups

    The main problem in the implementation of the service at the very beginning was the limitation of resources for virtual machines. In Xen, this problem was solved with the help of an internal sheduler, distributing resources between virtual machines - and most beautifully, the ability to limit disk operations including was implemented.

    KVM didn’t have anything like this before the cgroups core resource allocation mechanism appeared . As usual on Linux, access to these functions was implemented through a special cgroup file systemin 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 him weight.

    The profit is that all this is implemented inside the kernel, and you can use it not only for the server, but also for the desktop (which was used in the famous " The ~ 200 Line Linux Kernel Patch That Does Wonders "). And in my opinion, this is one of the most significant changes in the 2.6 branch, not counting the favorite # 12309 , and not filing the next file system. Well, perhaps, except for POHMELFS (but purely because of the name).

    libguestfs



    libguestfs

    My attitude to this utility library is very ambiguous.

    On the one hand, it looks something like this:

    libguestfs is a swiss knife


    And yet this thing is damn hard to compile from source and even more so into a package: sometimes it seems to me that Linux From Scratch is a little 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, set grub, modify the partition table, manage configuration files, transfer “iron” machines to a virtual environment, transfer virtual machines from one image to another, transfer virtual machines from an image to hardware and, frankly, here my imagination fails a bit. Oh yes: you can still run the daemon inside the Linux virtual machine and access the virtual machine data live, and do all this on shell, python, perl, java, ocaml. This is a short and far from complete list of what libguestfs can do ..

    Interestingly, most of the code in libguestfs is generated at the time of assembly, as well as the project documentation. Very widely used is ocaml, perl. The code itself is written in C, which is then wrapped in OCaml, and repeating pieces of code are generated themselves. Work with images is carried out by launching a special service image (supermin appliance), into which commands are sent through the channel inside it. Inside this image there is some rescue set of utilities, such as parted, mkfs and other system administrators useful in the household.

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

    Other



    Below are a few more interesting links to the description of the used software tools - to read and study on your own, if interested. For example, about a utility for mass work with configuration files, KVM best practices from colleagues from IBM. Recommend!

    1. Daniel Berrange's post on using cgroups with KVM and LXC.
    2. Richard Jones post on using libguestfs to get a small “basic” virtual machine image.
    3. BKL # 12309 on bugzilla.kernel.org


    In the next part



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

    Also popular now: