제 가상화 섹션을 읽으셨다면 지금까지 제 초점이 약간의 클라우드 관련 작업과 이미지 리마스터링과 함께 VMware 및 VirtualBox에 집중되어 있다는 것을 알고 계실 것입니다. 이제 분기할 시간입니다. 오늘 저는 KVM을 사용하여 완전히 새로운 자습서 시대를 공식적으로 시작하려고 합니다. 나중에 Xen과 다른 괴상한 짐승이 등장하겠지만 지금은 KVM이 주제입니다. 피>
이 가이드를 시작으로 다른 상용 솔루션에 대한 무료 오픈 소스 대안으로 사용할 수 있는 RedHat에서 개발한 KVM(커널 기반 가상 머신) 기술에 대해 알아봅니다. KVM을 다운로드, 설치 및 설정하는 방법, 가상 머신을 관리하는 데 사용할 수 있는 도구, 사용 가능한 옵션, 명령줄 사용 및 스크립팅 등에 대해 알아봅니다. 또한 고급 네트워킹 및 스토리지 구성은 물론 다른 멋진 기능도 살펴볼 것입니다. 시작하겠습니다. 피>
KVM - 용어집
KVM 작동 방식에 대한 매우 간략한 개요부터 시작하겠습니다. 주요한 내용은 없고 기본 용어를 알 수 있도록 간단한 소개만 있습니다. 걱정하지 마세요. 곧 모든 것이 매우 간단해질 것입니다. 피>
KVM은 Intel-VT 및 AMD-V로 알려진 최신 Intel 및 AMD 프로세서의 CPU 가상화 기술 확장을 활용하여 작동합니다. KVM은 메모리에 로드된 커널 모듈을 사용하여 프로세서를 활용하고 수정된 QEMU를 기반으로 하는 사용자 모드 드라이버를 통해 가상 머신을 생성하고 실행할 수 있는 하드웨어 계층을 에뮬레이트합니다. KVM은 CPU 확장 없이 실행할 수도 있지만 QEMU를 사용하는 순수한 에뮬레이션 모드에서 실행되므로 상당한 성능 저하가 발생합니다. 피>
KVM은 VMware 제품 또는 VirtualBox와 유사한 그래픽 관리 도구 또는 여러 방법을 사용하는 명령줄을 통해 관리할 수 있습니다. 피>
가장 널리 사용되는 GUI는 RedHat에서 개발한 VMM(Virtual Machine Manager)입니다. 이 도구는 일반 패키지 이름인 virt-manager로도 알려져 있습니다. virt-install, virt-clone, virt-image 및 virt-viewer를 포함하여 각각 가상 머신을 프로비저닝, 복제, 설치 및 확인하는 데 사용되는 다양한 지원 도구가 함께 제공됩니다. VMM은 Xen 컴퓨터도 지원합니다. 피>
일반 KVM 명령 인터페이스는 virsh에서 제공합니다. 특히 virt-install과 같은 지원 도구를 사용하여 가상 머신을 생성할 수 있습니다. Ubuntu에는 Canonical에서 개발한 Ubuntu 빌드 프로비저닝에 사용할 수 있는 특별한 ubuntu-vm-builder 도구가 있습니다. 피>
많은 이름이 혼란스러울 수 있지만 쉽게 생각하면 아이디어를 얻을 수 있습니다. 그러나 조금 더 혼란스럽게 하기 위해 KVM에는 QEMU와 유사한 자체 구문도 있습니다. 권장되는 가상 머신 관리 방법은 아닙니다. 피>
자세한 내용은 다음 페이지를 참조하십시오.
커널 가상 머신 - 커뮤니티 Ubuntu 설명서
howtoforge.com의 KVM 자습서
KVM/Virsh - 커뮤니티 우분투 설명서
좋습니다. 1단계였습니다.
KVM - 장단점
KVM을 사용해야 합니까? 글쎄, 그것은 당신이 달성하고자하는 것에 달려 있습니다. 피>
일반 가정용 사용자, 가상화 애호가 또는 중급 괴짜라면 KVM을 시작하기가 약간 어려울 수 있습니다. VMware 및 Virtualbox 제품만큼 직관적이거나 친숙하지 않은 주로 명령줄 도구입니다. KVM은 제공 측면에서 강력하지만 GUI 관리 측면에서 경쟁에서 수년 뒤쳐져 있다고 느낍니다. 실제로 명령줄 도구로 사용하도록 설계되었기 때문에 장기적으로 더 나은 생산성과 더 많은 제어를 즐길 수 있습니다. 따라서 KVM은 비즈니스 환경에서 가장 적합합니다. 피>
또한 CPU가 가상화를 지원하지 않는 경우 KVM은 매우 느리고 비효율적인 에뮬레이션 모드에서 실행하게 되므로 큰 시간 낭비가 됩니다. KVM은 또한 Virtualbox와 충돌하는 것으로 알려져 있지만 이에 대해서는 별도의 자습서에서 자세히 설명합니다. 피>
따라서 KVM은 가상화에 관심이 많은 사람들, 대부분 관리자 및 전문가를 위한 것입니다. 그것은 당신의 가장 귀여운 집 장난감이 아니며 앞으로 몇 년 동안은 아닐 수도 있습니다. 그러나 기꺼이 파고들면 완전히 새로운 언어를 마스터하게 될 것이며 나중에 다른 기술과 함께 힘을 배가시키는 역할을 할 것입니다. VMware 또는 Virtualbox는 GUI 도구를 사용하는 것을 선호하지만 KVM은 명령줄 스크립팅의 원시 효율성을 지향합니다. 피>
요약하자면 KVM은 무제한 사용 모드와 추가 라이센스 비용 또는 기능 계층화, 강력한 명령줄 인터페이스가 없는 무료 최신 가상화 솔루션을 찾고 있고 손을 더럽히는 것을 두려워하지 않는 경우에 적합합니다. KVM is not good for you if your CPU does not have virtualization extensions, you're afraid of writing scripts, have no desire to dabble in code, and prefer administratively simpler solutions like VMware Server, ESXi or Virtualbox. 피>
All, right, let's get going. 피>
Test platform
You can use KVM in pretty much any Linux distro. In general, RedHat flavors favor KVM. RHEL ships with KVM enabled in the operating system, so you can also find it in RedHat-based distros like CentOS, Scientific Linux, or Fedora. 피>
Since I'm running mostly Ubuntu at home, I decided to test in Ubuntu, installed on my rather brand-newish HP laptop, which has a revvy i5 processor that supports virtualization. Later this year, I'm planning on deploying either the newest release of CentOS or Scientific Linux on my Linux-dedicated multi-boot machine, so you'll see additional tutorials for those distros, too. We'll get to Xen there, too. 피>
This tutorial shows how to setup KVM on a 64-bit Ubuntu Lucid, the Long Term Release. Sequel guides and howtos will cover many other topics related to KVM, including using it alongside other virtualization technologies and resolving conflicts, advanced management functions, scripting, and more. 피>
피>
Now, finally, let's begin in earnest. 피>
Prerequisites
You need a CPU that supports virtualization. This can be checked thusly:
egrep -c '(vmx|svm)' /proc/cpuinfo
피>
If you get a non-zero value, you're good. BUT ... you will also need to check that virtualization technology is enabled in BIOS. Indeed, after enabling the feature, you will have to cold power-cycle the machine for the change to take effect. 피>
Once this is done, boot into your operating system and get KVM installed. 피>
To check, please run kvm-ok:
Download &install KVM
To get KVM install, please get these packages (true for apt commands):
apt-get install qemu-kvm libvirt-bin
Optionally, you can install these - most recommended:
apt-get install bridge-utils virt-manager python-virtinst
추신 The package names will vary between distributions. For instance, virt-install may come branded as python-virt-install or python-virtinst or even virt-install. The dependencies for virt-clone, virt-image and virt-viewer should be automatically resolved. 피>
Contrary to what most tutorials mention, you do NOT need bridge utilities. You only need them if you want to bridge your virtual adapters with your physical cards. I've shown you a detailed example of this in my Virtualbox networking tutorial. 원리는 동일합니다. 피>
Most tutorials also mention the fact that most Wireless network interfaces do not support bridging. This may be the case, but in all my testing, I was able to successfully bridge my Wireless adapters, so keep your hopes high. 피>
VMM (virt-manager) is highly recommended. Likewise, you want all the helper tools, including virt-viewer, virt-install, virt-image, and virt-clone. 피>
Lastly, you can also opt for ubuntu-vm-builder:
apt-get install ubuntu-vm-builder
You will also get a whole bunch of dependencies auto-resolved, so your downloads can take a while. 추신 On RedHat, use yum install. On SUSE, use zypper install. 피>
Conflict with Virtualbox
Again, contrary to what most tutorials say:you can have both KVM and Virtualbox installed on the same host. You may not get them running both at the same time. In other words, one or the other kernel module needs to be unloaded from memory. But there's no reason to rush ahead. Try, see if it works for you, and if not, only then take corrective actions. 피>
But this can be done in-vivo, so no worries there. You won't need to reboot or anything as drastic as that. I'll show you a separate tutorial that handles this case. In fact, I have both installed and running on the test host. 피>
Using KVM
Now, the really fun part. We will start with the VMM, as it is a GUI tool and this is what most people will and should start with. For all practical purposes, it's very similar to other tools you know, like the VMware console or perhaps Virtualbox. 피>
Virtual Machine Manager (VMM)
Let's take a tour. 피>
The first time you launch the program, it will show two categories, both not connected. These refer to your localhost KVM modules, still not in use. To use, right-click and choose connect. 피>
피>
To add new connections, click File> Add Connection. This will open a window that lets you specify the Hypervisor type and the connection type. VMM can use both local and remote connections, including QEMU/KVM and Xen. You can connect using all kinds of authentications methods. 피>
피>
피>
You can also autoconnect, which means that the next time you fire up VMM, these connections will be ready for you. This is similar to what VMware Server asks you when you start the program. Just for reference:
피>
Kernel versus Usermode
You may be asking what the difference between normal/default and Usermode is? Well, Usermode allows you to run without administrative privileges, but your network capability will be limited. All right, let's move on. 피>
VMM overview, continued
Let's see other functions, before we create a virtual machine. 피>
Network functionality can be reviewed or changed under Host Details. We will have a separate tutorial that teaches how to work with KVM network. And we'll setup bridge utilities, too, so don't worry. 피>
피>
Likewise, you can change the storage settings. There'll be a dedicated guide, I promise:
피>
Change preferences
The VMM has a handful of options you can tweak to make it look and behave smarter. You can enable the system tray icon, set a statistics polling interval, enable polling for disk and network metrics, which are deselected by default, configure console keyboard grabbing, console scaling, audio options, and set confirmation windows for machine activities. 피>
Later on, all of these will allow us to view our virtual machine metrics in more detail and with better control. For instance, showing an Ubuntu guest CPU, Disk I/O and Network I/O:
피>
Here's the system tray icon:
피>
Finally, we're ready to create a new virtual machine. 피>
Create virtual machine
We can do this using VMM or the command line. We will begin with the GUI. The first step is quite intuitive. Enter the name and the install media location. You can use local storage in the form of ISO images or CD/DVDs, HTTP or FTP servers, NFS area, or PXE. 피>
피>
We will use local install media. Next, choose either a physical device or an image. In our case, we will use an ISO. Then, choose the OS type and the version. This does not have to be precise, but an educated guess is good. It allows additional virtual machine optimization. 피>
피>
피>
Allocate RAM and CPUs. 피>
피>
The fourth step is quite interesting - storage. You can create a new image or use an existing one. You can set the size and preallocate all space, which is good for performance, plus it reduces fragmentation. 피>
피>
We will focus soon quite a bit more on the storage. For now, let's either assume we have a disk ready - or that we will create one in the default storage pool. Please note that if you're running in Usermode, you won't be able to write to /var, which is the default storage pool location. You will need to create a new storage pool that is accessible by non-admin users, but more about that in a separate article. 피>
Step 5 is a summary, with some advanced options. You can change your network type, set a fixed Mac address, choose the virtualization type, and the target architecture. If you're running in Usermode, your network options will be limited. If you're not using bridge utilities, you won't be able to bridge your interfaces. Lastly, if you have no CPU virtualization extensions, the Virt Type:field will read QEMU and not KVM. We will see an example of this later on, when we discuss the major drawbacks of running in the emulation mode. For now, here's what a typical Ubuntu virtual machine setup looks like:
피>
Our machine is ready to use. We will soon power it up and use it. 피>
Virtual machine options
Like VMM itself, the VM console has a few interesting options. You can send signals to your guest, you can switch virtual consoles, force reboot and power off, clone, migrate, save, take screenshots, and more. Again, very similar to the competition. 피>
피>
Here's a pair of screenshots teasers for the clone and migrate options. Down the road, we will have detailed tutorials, focusing both on the GUI and CLI functionality. 피>
피>
피>
Virtual machines running
The fun part. Here's a handful of nice screenshots ...
Let's begin with Ubuntu 10.10 Maverick, 32-bit version, boot menu:
피>
Puppy Linux, shown against a lovely desktop:
피>
Ubuntu running, NAT-ed, no worries. Notice the CPU utilization is very low. Important, pay attention for later on when we discuss the emulation only mode. I'm nagging you, but please bear with my ultra-turbo education. 피>
피>
피>
You can also scale the console window to fit guest; this is another option available in the viewer menu. Then, you can also use the preferences to autoscale the consoles. Here are Puppy and Ubuntu, side by side:
피>
Here's the system usage; minimal. With this kind of smart consumption, you can generously overcommit and enjoy more virtual machines than your physical hardware would normally permit, with a single machine bound to a core. 피>
피>
Eventually, you can also delete a machine and its associated files:
피>
Now that we're comfortable with basic usage, let's do some command line. 피>
Command line
Now, let's see the infamous command line. For example, using virsh to list all available virtual machines. 피>
virsh 'list --all'
피>
Here's the sequence of commands to get a virtual machine created and running using virt-install. Please note that I'm not a KVM guru. You have template code in the man pages, and you can find a billion examples online. 피>
피>
피>
The actual command is:
virt-install --connect qemu://system -n puppy -r 512 -f puppy.img -c lupu-520.iso --vnc --noautoconsole --os-type linux --accelerate --network=network:default
So what do we have here? 피>
--connect qemu:///system defines the type of hypervisor used. system is used when running on bare metal kernel as root. session is used for non-root users. You can recall the differences in VMM, with Usermode, right-click connect, you get the idea. This also works for xen. 피>
-n puppy is a unique virtual machine name. You can use virsh to rename or delete the guest if you're not satisfied with your choice. 피>
-r 512 specifies the RAM. 피>
-f specifies a disk file. In this case, I'm using a puppy.img disk image I created using a dd command. To conserve space, I created the image as a sparse file. You can learn more about how to create sparse files in my second cool Linux hacks article. 피>
-c specifies the CD-ROM, either a physical device or an ISO image. 피>
--vnc setups a guest console and exports it as a VNC server. --noautoconnect will not automatically open the console when the virtual machine is powered on. 피>
--os-type specifies the operating system for the guest. 피>
--accelerate allows KVM to use optimization functions that accelerate the performance of the guest system, if possible. 피>
--network defines the network type. We're using the default connection. 피>
We could have used many other functions, like setting up the number of cores or bounding the machine to a CPU core, setup a fixed MAC address for NIC, use no storage, change the keyboard map, and more. 피>
All of these are listed in the man pages. Not really intuitive, but becomes easier with use. In fact, the learning curve is not that high, despite the initial impression. Once you get the hang of virt-install, you can fiddle with other commands, start and stop machines with virsh, and Bob's your uncle. 피>
Other things
A few more details worth mentioning. 피>
Running in pure emulation mode (don't)
I told you this is completely inefficient. Now, a proof. For instance, take a look at Host Details Overview. In the Performance graph, CPU usage is max. at 100% of the available resources for the virtual machine, in this case one core, which translates to 25% utilization. Almost like DOS. This means that four virtual machines, no matter how tiny or hungry, will cripple a four-core host. 피>
피>
Additionally, the performance will be horrible. If an Ubuntu guest takes approx. one minute to boot with the image loaded on the internal 7,200rpm disk when running with Intel-VT extensions enabled, it takes about 20 minutes to do that in the emulation mode. I think this is a downside of QEMU/KVM compared to other solutions, which still offer fairly decent performance even without CPU extensions. 피>
More good reading
I highly recommend the KVM series on howtoforge.com, linked above. 피>
Then, you should also read these:
Discover the Linux Kernel Virtual Machine
KVM management tools
결론
I sincerely hope you've liked this tutorial. It's fairly long and detailed, even though it documents only the first steps to get started with KVM. But it does offer an insight into a lot of things, including initial setup and prerequisites, command-line and GUI tools, management options, how to create and run multiple virtual machines, and more. 피>
There are going to be a ton of sequels, which will cover advanced storage and networking configurations, including bridged networking, how to clone and migrate virtual machines, how to resolve conflicts with other virtualization software and more. Not strictly related, there are also going to be a whole bunch of articles on Xen and ESXi, too. 피>
As you can see, KVM is quite powerful, even though it may appear a bit daunting to new users. Its management options are definitely less newb-friendly than some of its rival, but luckily, some of the fear and confusion have been spirited away today. 피>
Well, I guess that would be all. 즐기다! 피>
건배. 피>