打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
CentOS / Redhat: Install KVM Virtualization S...

CentOS / Redhat: Install KVM Virtualization Software

by on June 12, 2010 · 27 comments

KVM (Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware containing virtualization extensions Intel VT or AMD-V. How do I install KVM under CentOS or Red Hat Enterprise Linux version 5.5?

The Linux kernel 2.6.20 and above included KVM. RHEL 5.5 (and upcoming RHEL 6) supports KVM out of box and it has also been ported to FreeBSD as a loadable kernel module. However, this tutorial is tested on both CentOS and RHEL 5.5 only running 64 bit Intel Xeon CPU (with Intel VT) and 64 bit kernels with SELinux running in enforcing mode.

Why KVM?

XEN allows several guest operating systems to execute on the same computer hardware and it is also included with RHEL 5.5. But, why use KVM over XEN? KVM is part of the official Linux kernel and fully supported by both Novell and Redhat. Xen boots from GRUB and loads a modified host operating system such as RHEL into the dom0 (host domain). KVM do not have concept of dom0 and domU. It uses /dev/kvm interface to setup the guest operating systems and provides required drivers. See the official wiki for more information.

Required Packages

You must install the following packages:

  1. kmod-kvm : kvm kernel module(s)
  2. kvm : Kernel-based Virtual Machine
  3. kvm-qemu-img : Qemu disk image utility
  4. kvm-tools : KVM debugging and diagnostics tools
  5. python-virtinst : Python modules and utilities for installing virtual machines
  6. virt-manager : Virtual Machine Manager (GUI app, to install and configure VMs)
  7. virt-viewer: Virtual Machine Viewer (another lightweight app to view VM console and/or install VMs)
  8. bridge-utils : Utilities for configuring the Linux Ethernet bridge (this is recommended for KVM networking)

KVM Package Group

RHEL comes with KVM software group which includes full virtualization support with KVM. You can list all packages in the group as follows:
# yum groupinfo KVM
Sample outputs:

Loaded plugins: rhnplugin, securitySetting up Group ProcessGroup: KVM Description: Virtualization Support with KVM Mandatory Packages:   celt051   etherboot-zroms   etherboot-zroms-kvm   kmod-kvm   kvm   kvm-qemu-img   qcairo   qffmpeg-libs   qpixman   qspice-libs Default Packages:   Virtualization-en-US   libvirt   virt-manager   virt-viewer Optional Packages:   celt051-devel   etherboot-pxes   etherboot-roms   etherboot-roms-kvm   gpxe-roms-qemu   iasl   kvm-tools   libcmpiutil   libvirt-cim   qcairo-devel   qffmpeg-devel   qpixman-devel   qspice   qspice-libs-devel

A Note About libvirt

libvirt is an open source API and management tool for managing platform virtualization. It is used to manage Linux KVM and Xen virtual machines through graphical interfaces such as Virtual Machine Manager and higher level tools such as oVirt. See the official website for more information.

A Note About QEMU

QEMU is a processor emulator that relies on dynamic binary translation to achieve a reasonable speed while being easy to port on new host CPU architectures. When used as a virtualizer, QEMU achieves near native performances by executing the guest code directly on the host CPU. QEMU supports virtualization when executing under the Xen hypervisor or using the KVM kernel module in Linux. When using KVM, QEMU can virtualize x86, server and embedded PowerPC, and S390 guests. See the official website for more information.

A Note About Virtio Drivers

Virtio is paravirtualized drivers for kvm/Linux. With this you can can run multiple virtual machines running unmodified Linux or Windows VMs. Each virtual machine has private virtualized hardware a network card, disk, graphics adapter, etc. According to Redhat:

Para-virtualized drivers enhance the performance of fully virtualized guests. With the para-virtualized drivers guest I/O latency decreases and throughput increases to near bare-metal levels. It is recommended to use the para-virtualized drivers for fully virtualized guests running I/O heavy tasks and applications.

Host Operating System

Your main operating system such as CentOS or RHEL is known as host operating system. KVM is a Linux kernel module that enables a modified QEMU program to use hardware virtualization. You only need to install KVM under host operating systems.

KVM Domains

It is nothing but a guest operating system running under host operating system. Each kvm domain must have a unique name and ID (assigned by system).

Guest Operating Systems

KVM supports various guest operating systems such as

  1. MS-Windows 2008 / 2000 / 2003 Server
  2. MS-Windows 7 / Vista / XP
  3. FreeBSD
  4. OpenBSD
  5. Sun Solaris
  6. Various Linux distributions.
  7. NetBSD
  8. MINIX
  9. QNX
  10. MS DOS
  11. FreeDOS
  12. Haiku
  13. Amiga Research OS

Install KVM

Type the following command to install KVM under RHEL or CentOS:
# yum install kvm virt-viewer virt-manager libvirt libvirt-python python-virtinst
OR
# yum groupinstall KVM

Important Configuration And Log Files (Directories) Location

The following files are required to manage and debug KVM problems:

  1. /etc/libvirt/ - Main configuration directory.
  2. /etc/libvirt/qemu/ - Virtual machine configuration directory. All xml files regarding VMs are stored here. You can edit them manually or via virt-manager.
  3. /etc/libvirt/qemu/networks/ - Networking for your KVM including default NAT. NAT is only recommended for small setup or desktops. I strongly suggest you use bridged based networking for performance.
  4. /etc/libvirt/qemu/networks/default.xml - The default NAT configuration used by NAT device virbr0.
  5. /var/log/libvirt/ - The default log file directory. All VM specific logs files are stored here.
  6. /etc/libvirt/libvirtd.conf - Master libvirtd configuration file.
  7. /etc/libvirt/qemu.conf - Master configuration file for the QEMU driver.

TCP/UDP Ports

By default libvirt does not opens any TCP or UDP ports. However, you can configure the same by editing the /etc/libvirt/libvirtd.conf file. Also, VNC is configured to listen on 127.0.0.1 by default. To make it listen on all public interfaces, edit /etc/libvirt/qemu.conf file.

Our Sample Setup

                                                                             +-------------> vm#1 ( 10.10.21.71 / 123.1.2.4, CentOS MySQL Server)                                                                             |                                                                             +-------------> vm#2 ( 10.10.21.72 / 123.1.2.5, FreeBSD 7 Web Server)LAN --> Switch    -->  eth0 --> -+   10.10.21.70                             |                                 | ---> br0 -+      +----------------+       +-------------> vm#3 ( 10.10.21.73 / 123.1.2.6, OpenBSD 4.x Firewall )                                 |           | ===> |   RHEL Server  |  -----+                                 |           |      |      KVM       |       +-------------> vm#4 ( 10.10.21.74 / 123.1.2.7, Solaris 10 Testing Server )                                 | ---> br1 -+      +----------------+       |Wan --> ISP Router --> eth1 --> -+   123.1.2.3                               +-------------> vm#5 ( 10.10.21.71 / 123.1.2.8, Windows Server Testing Server )                                                                             |                                                                             +-------------> vm#6 ( 10.10.21.71 / 123.1.2.9, RHEL Mail Server )

(Fig.01: Our sample server setup - you need to scroll to see complete diagram)

Where,

Host Configuration

  • OS - RHEL / CentOS v5.5 is our host operating system.
  • Host has two interface eth0 and eth1
  • LAN - eth0 with private ip
  • Internet - eth1 with public IPv4/IPv6 address.
  • Disk - 73x4 - 15k SAS disk in RAID 10 hardware mode. All VMs are stored on same server (later I will cover SAN/NFS/NAS configuration with live migration).
  • RAM - 16GB ECC
  • CPU - Dual core dual Intel Xeon CPU L5320 @ 1.86GHz with VT enabled in BIOS.

Virtual Machine Configuration

  • Bridged mode networking (eth0 == br0 and eth1 == br1) with full access to both LAN and Internet.
  • Accelerator virtio drivers used for networking (model=virtio)
  • Accelerator virtio drivers for disk (if=virtio) and disk will show up as /dev/vd[a-z][1-9] in VM.
  • Various virtual machines running different guest operating systems as per requirements.
This FAQ entry is 1 of 14 in the "CentOS / Redhat (RHEL) KVM Virtulization" series. Keep reading the rest of the series:
Table of Contents:
  1. CentOS / Redhat: Install KVM Virtualization Software
  2. CentOS / Redhat: KVM Bridged Network Configuration
  3. KVM virt-manager: Install CentOS As Guest Operating System
  4. KVM virt-install: Install FreeBSD / CentOS As Guest Operating System
  5. KVM: Install CentOS / RHEL Using Kickstart File (Automated Installation)
  6. Troubleshooting KVM Virtualization Problem With Log Files
  7. KVM Virsh: Redirect FreeBSD Console To A Serial Port
  8. KVM: Starting / Stopping Guest Operating Systems With virsh Command
  9. Linux KVM: Disable virbr0 NAT Interface
  10. FreeBSD / OpeBSD Running in KVM Does Not Accept FTP Traffic
  11. KVM: Start a Virtual Machine / Guest At Boot Time
  12. KVM virt-install: Install OpenBSD As Guest Operating System
  13. Linux KVM: OpenBSD Guest Hangs At Starting tty Flags
  14. KVM Virtualization: Start VNC Remote Access For Guest Operating Systems
What next? Facebook it - Tweet it - Print it - Email it -
Zdenek Styblik June 13, 2010 at 10:23 am

The heading should read ‘virtualization’.
Not bad summary though.

Reply

Vivek Gite June 13, 2010 at 11:02 am

Thanks for the heads up!

Reply

qt2r June 14, 2010 at 11:43 am

Excellent guide. thanks for sharing :)

Reply

cod3fr3ak June 14, 2010 at 3:41 pm

Which gives better results with non-virtual aware operating system, xen or kvm. I can never remember. I am considering trying to run Windows 7 within a xen or kvm instance on Centos 5.5. Does anyone know if it supports Directx? A couple of the games I play use it for 3d and effects rendering.

Reply

Bhaskar Chowdhury June 16, 2010 at 4:42 am

Hey Vivek!
This article is as good as others you have posted earlier.Keep up the good work man.Looking forward to the next installment of this article.

Cheers mate!

Reply

Paul June 17, 2010 at 7:48 am

Hi

as far as I’m aware Novell does not yet support KVM, it is included in SLES11 sp1 as a “technology preview”, I think they call it, ie they include it for you to test but it is not supported, at least not officially.

Cheers

Reply

Ian June 27, 2010 at 10:49 am

It was tech preview in sles11, fully supported in sles11sp1

Reply

mam June 22, 2010 at 10:21 am

I found error in one command yum groupinstall KMV, correct is yum groupinstall KVM

Reply

Vivek Gite June 22, 2010 at 2:05 pm

Thanks! The post has been updated.

Reply

rwilla August 5, 2010 at 6:49 am

You can list all packages in the group as follows: #yum groupinfo Virtualization

Reply

Rocky Patel October 14, 2010 at 4:45 pm

Hi,

I m getting this error while installing yum groupinstall KVM..

yum groupinstall KVM
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: mirrors.hns.net.in
* base: mirrors.hns.net.in
* extras: mirrors.hns.net.in
* updates: mirrors.hns.net.in
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package kvm.i386 0:36-1 set to be updated
—> Package virt-manager.i386 0:0.6.1-12.el5 set to be updated
–> Processing Dependency: python-virtinst >= 0.400.3 for package: virt-manager
—> Package virt-viewer.i386 0:0.0.2-3.el5 set to be updated
–> Running transaction check
—> Package python-virtinst.noarch 0:0.400.3-9.el5_5.1 set to be updated
–> Processing Conflict: libvirt conflicts kvm Finished Dependency Resolution
libvirt-0.6.3-33.el5_5.3.i386 from installed has depsolving problems
–> libvirt conflicts with kvm
Error: libvirt conflicts with kvm
You could try using –skip-broken to work around the problem
You could try running: package-cleanup –problems
package-cleanup –dupes
rpm -Va –nofiles –nodigest
The program package-cleanup is found in the yum-utils package.

Reply

Ice72 December 2, 2010 at 8:58 am

Hi,

great summary. On fedora core 14 the “yum install ” command not install the qemu-kvm.x86_64 which is installed if I use the command “yum install virtualization”

Reply

Hanif December 30, 2010 at 3:47 am

How about if I want the vcpu more than 16 cores

Reply

alessandroo June 21, 2011 at 8:48 am

hello,

Is kvm available on RHEL 5.5 32 bits ?

I have only a 32 bit processor…

Reply

Vivek Gite June 21, 2011 at 11:28 am

Running a 64 bit kernel (RHEL 64 bit) on the host operating system is recommended but not required. You can use 32bit but limited to 2GB ram per VM. A 32 bit server can only host 32-bit guest operating system.

Reply

alessandroo June 21, 2011 at 12:10 pm

ok thanks for this information, but its not really my request.
I have a RHEL 5.5 32bits distribution (i have only a proc 32bits, i dont have the choice) in a plateform test and i need to install KVM.

Is KVM compatible with a 32 bit distribution? Because i dont find the packet “kvm”, “libvirt”, “virt manager”

Reply

Vivek Gite June 21, 2011 at 12:20 pm

RHEL 5.5+ x86 removed 32bit kvm packages. Your options are as follows
a) Go with 64bit (x64) RHEL system as Redhat not planned create 32bit KVM as most VM server runs on 64 bit platform.
b) Go with 32 bit RHEL and compile new kernel with KVM
c) Use Ubuntu or other 32 bit Linux distro that support 32bit KVM

Reply

abdullah kamal August 23, 2011 at 4:06 pm

is it possible to create virtual data center in centos, currently this kind of technology is provided by the redhat.

Reply

Lio September 5, 2011 at 6:00 pm

Hi all
could anyone advise me to solve the problem
the problem is as following:
I’ve installed kvm with all its packages and when i want to install win 7 it will be stacked and does not go forward please help
i’ll be appreciated

Reply

ahmad September 7, 2011 at 9:09 am

Please note that RedHat/CentOS was configured to run KVM only on 64-bit operating systems.

Reply

Ivan September 18, 2011 at 2:50 pm

For the host Centos OS, what is the recommended installation configurations? (Server or Minimal)? I have chosen Minimal but couldn’t load any GUI for my centos…and is stuck at the step where it is suppose to load a GUI for virtual manager

Reply

Rashid Iqbal October 15, 2011 at 7:28 pm

I want to change the default location of virtual harddisk to another LVM volume.

How can I do this………?

Reply

luckysanj November 20, 2011 at 9:18 am

same thing from my side also….For the host Centos OS, what is the recommended installation configurations? (Server or Minimal)? I have chosen Minimal but couldn’t load any GUI for my centos…and is stuck at the step where it is suppose to load a GUI for virtual manager.

Reply

Sathish January 25, 2012 at 6:13 pm

Thanks, its very helpful for me :)

Reply

kuljinder mathoun February 28, 2012 at 6:42 pm

Do we have any equivalent application like VMware Virtual Center to manage KVM hosts?
I heard about OVIRT but it has some limitation.

Thanks

Reply

Rafi March 16, 2012 at 2:10 am

first thank you Vivek, for writing an article that brand new newbies could follow, nice organized. Further request to dumb it down by some server sizing how many CPUs, RAM etc especially for small cluster of 1-10 desktops (that is what we like to do)… also do you have articles on how to installed RHEL 64 on a brand new machine?

Sorry folks, I have to start somewhere, I am staring at my RHEL 6.2 ISO images, new server no OS on it, 3.0 GHz CPU quad core and 16 GB RAM. Plugged in and I have no CLUE. I absolutely cannot stand the other techies speak nor understand it.

Everything else I read, just went into total geekdom high brow type writeup/

Vivek any dummy level article that goes step by step or any material I could read up on will be deeply appreciated!!!

Reply

Rafi March 16, 2012 at 2:13 am

Just saw your TOC some install stuff there, will try that… thanks!

Reply

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
(2)KVM存储池与存储卷,使用virt
kvm 创建新虚拟机命virt-install 使用说明
linux 虚拟化实战
VMware下的Centos7实践Kvm虚拟化(通俗易懂)
Centos7上安装KVM虚拟机
在 CentOS 上安装和配置 KVM
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服