KVM tools and enterprise usage
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

KVM tools and enterprise usage

  • 4,815 views
Uploaded on

Open Source Virtualization based on KVM and available tools like Libvirt, Libguestfs, Qemu, ...

Open Source Virtualization based on KVM and available tools like Libvirt, Libguestfs, Qemu, ...

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,815
On Slideshare
4,813
From Embeds
2
Number of Embeds
1

Actions

Shares
Downloads
214
Comments
0
Likes
11

Embeds 2

http://www.linkedin.com 2

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Virtualize with KVM Tools and Enterprise usage by Vincent Van der Kussen
  • 2. #whoami● Using Linux since 1996● Sysadmin / Engineer / Opensource Enthousiast● @vincentvdk● http://blog.vanderkussen.org
  • 3. So what is this KVM thing anyway?
  • 4. Its NOT!
  • 5. KVM : overviewKernel-based Virtual Machine, a Kernel module thatturns Linux into a hypervisorCreated by Quramnet (bought by Red Hat 2008)Supports x86 (32 and 64 bit), s390, PowerpcIncluded in Linux kernel since 2.6.20Needs a CPU with virtualization extention !
  • 6. KVM : overview● Each vm is a process● Each virtual cpu is a thread● Open source
  • 7. FeaturesCPU and memory overcommitHigh performance paravirtual I/OHotplug (cpu, block, nic)SMP guestsLive MigrationPower management
  • 8. FeaturesPCI Device Assigenment and SR-IOVKSM (Kernel Samepage Merging)SPICENUMA
  • 9. KVM : differencesNot your typical VMWare workstation or VirtualBox.VirtManager comes close but still a little rough on theedgesKVM is meant for virtualization on servers. Desktopusage is not always ideal(think vSphere, HyperV,..).
  • 10. Overview Toolslibvirt (api)VirshQemuVirtManagerLibguestfsvirt-v2v
  • 11. Overview toolssVirtvirt-*BoxgrinderVirtIO (not really a tool)Spice
  • 12. Libvirt : The Virtualization API
  • 13. Libvirt : overview● “The Virtualization API”● Toolkit to interact with the virtualization layer● Written in C● LGPL● Has bindings for common languages (Python, Ruby, Perl, PHP, Java,..)● Supports AMQP via libvirt-qpid
  • 14. Libvirt : overview● Provides management of – Virtual machines – Virtual networks – Storage● Does NOT provide multi node management features like load balancing● Suspend / resume support
  • 15. Libvirt : terminology Node a physical machine
  • 16. Libvirt : termonology HypervisorA software layer that allows a node to run virtual machines
  • 17. Libvirt : terminologie DomainAn instance (“virtual machine”) running on the hypervisor
  • 18. Libvirt : overviewSupports also : VMWare Microsoft HyperV XEN KVM OpenVZ Virtualbox LXC
  • 19. virsh
  • 20. Virsh overviewCommand line for libvirtEnables scriptingLibvirtd needs to be startedMost commands require root privileges
  • 21. Virsh usagevirsh <command> <domain-id> [OPTIONS]virsh <command> <domain-id> [OPTIONS]
  • 22. Virsh usage Connect to hypervisor on the localhost virsh connect qemu:///system virsh connect qemu:///system or virsh virshConnect to hypervisor on remote system over SSH virsh -c qemu+ssh://user@host.domain.foo/system virsh -c qemu+ssh://user@host.domain.foo/system
  • 23. Virsh usage
  • 24. Virsh : storage● Define storage pool ● Local filesystem (ext3, ext4,...) ● Directory based ● ISCSI ● NFS ● LVM (uses volume group) ● Physical disk ● multipath
  • 25. Virsh : create storage pool <pool type="dir"> <name>LOCAL-STORAGE</name>Xml file -> <target> <path>/VMS</path> </target> </pool> [root@localhost ~]# virsh pool-define dir_pool.xml [root@localhost ~]# virsh pool-define dir_pool.xml Pool LOCAL-STORAGE defined from dir_pool.xml Pool LOCAL-STORAGE defined from dir_pool.xml [root@localhost ~]# virsh pool-start LOCAL-STORAGE [root@localhost ~]# virsh pool-start LOCAL-STORAGE Pool LOCAL-STORAGE started Pool LOCAL-STORAGE started
  • 26. Virsh : create storage pool [root@localhost ~]# virsh pool-list [root@localhost ~]# virsh pool-list Name Name State State Autostart Autostart ----------------------------------------- ----------------------------------------- default default active active yes yes LOCAL-STORAGE LOCAL-STORAGE active active no no[root@localhost ~]# virsh[root@localhost ~]# virsh pool-autostart LOCAL-STORAGE pool-autostart LOCAL-STORAGE Pool LOCAL-STORAGE Pool LOCAL-STORAGE marked as autostarted marked as autostarted
  • 27. Virsh : create VM● VM is defined in xml file● Manual creation of VMs disks[root@localhost ~]# qemu-img create[root@localhost ~]# qemu-img create /VMS/vm02-fromxml.img 5G /VMS/vm02-fromxml.img 5GFormatting /VMS/vm02-fromxml.img,Formatting /VMS/vm02-fromxml.img, fmt=raw size=5368709120 fmt=raw size=5368709120● Define VM in libvirt and start it[root@localhost ~]# virsh define vm02_from_xml.xml[root@localhost ~]# virsh define vm02_from_xml.xmlDomain vm02-fromxml defined from vm02_from_xml.xmlDomain vm02-fromxml defined from vm02_from_xml.xml[root@localhost ~]# virsh start vm02-fromxml[root@localhost ~]# virsh start vm02-fromxmlDomain vm02-fromxml startedDomain vm02-fromxml started
  • 28. 1 <domain type=kvm>2 <name>vm02-fromxml</name>3 <uuid></uuid>4 <memory>128288</memory>5 <currentMemory></currentMemory>6 <vcpu>2</vcpu>7 <os>8 <type arch=x86_64 machine=pc-0.14>hvm</type>9 <boot dev=hd/>10 </os>11 <features>12 # features such as ACPI are defined here13 </features>14 <devices>15 <emulator>/usr/bin/qemu-kvm</emulator>16 <disk type=file device=disk>17 <driver name=qemu type=raw cache=none/>18 <source file=/VMS/vm02-fromxml.img/>19 <target dev=vda bus=virtio/>20 <alias name=virtio-disk0/>21 <address type=pci domain=0x0000 bus=0x00 slot=0x04 function=0x0/>22 </disk>23 </devices>24 </domain>
  • 29. Virsh : list vms[root@localhost ~]# virsh list --all[root@localhost ~]# virsh list --all Id Name Id Name State State-------------------------------------------------------------------- 4 vm01 4 vm01 running running - vm02-fromxml - vm02-fromxml shut off shut off[root@localhost ~]#[root@localhost ~]#
  • 30. Virsh : live migrationvirsh migrate --live <guestname> qemu+ssh://<destination host>/systemvirsh migrate --live <guestname> qemu+ssh://<destination host>/system
  • 31. Virsh : snapshots● Only on qcow2 images # virsh snapshot-create <domain> # virsh snapshot-create <domain> # virsh snapshot-list <domain> # virsh snapshot-list <domain> Name Name Creation Time Creation Time State State --------------------------------------------------- --------------------------------------------------- 1295973577 1295973577 2011-01-25 17:39:37 +0100 running 2011-01-25 17:39:37 +0100 running 1295978837 1295978837 2011-01-25 19:07:17 +0100 running 2011-01-25 19:07:17 +0100 running # virsh snapshot-restore <domain> <snapshotname> # virsh snapshot-restore <domain> <snapshotname>
  • 32. Qemu
  • 33. qemu● KVM istself cannot create VMs● KVM is “just” a hypervisor● Qemu as user space process● Qemu communicates via /dev/kvm
  • 34. qemu● Qemu-img – Check – Convert – Create – Snapshot – Info
  • 35. Qemu Inspect image[root@HV01 ~]# qemu-img info /var/lib/libvirt/images/WIN7.img[root@HV01 ~]# qemu-img info /var/lib/libvirt/images/WIN7.imgimage: /var/lib/libvirt/images/WIN7.imgimage: /var/lib/libvirt/images/WIN7.imgfile format: rawfile format: rawvirtual size: 12G (12884901888 bytes)virtual size: 12G (12884901888 bytes)disk size: 12Gdisk size: 12G[root@HV01 ~]#[root@HV01 ~]#
  • 36. qemuExample :Convert raw to vmdk imageqemu-img convert -O vmdk <raw image> outimage.vmdkqemu-img convert -O vmdk <raw image> outimage.vmdk
  • 37. Qemu Supported disk formats● file ● cow● blkverify ● Raw● sheepdog ● vmdk● blkdebug ● vdi● qcow2 ● qcow● vvfat
  • 38. virtio● "full virtualization" is a nice feature because It allows you to run any operating system virtualized.● However, its slow because the hypervisor has to emulate actual physical devices.
  • 39. virtio● Virtio drivers solve this● Virtio drivers know they run in a virtualized environment. (no emulation)● Virtio drivers operate with hypervisor
  • 40. virt-*
  • 41. virt-*● Virt-install● Virt-viewer● Virt-clone● virt-top
  • 42. Virt-install ● Can create VM and disks in one go[root@localhost ~]# virt-install --connect qemu:///system --graphics[root@localhost ~]# virt-install --connect qemu:///system --graphicsvnc,listen=0.0.0.0 --name=vm01 --ram 512 --disk pool=LOCAL-vnc,listen=0.0.0.0 --name=vm01 --ram 512 --disk pool=LOCAL-STORAGE,size=10,bus=virtio,cache=none /STORAGE,size=10,bus=virtio,cache=none /--network network=default,model=virtio /--network network=default,model=virtio /--location=http://ftp.debian.org/debian/dists/squeeze/main/installer-amd64--location=http://ftp.debian.org/debian/dists/squeeze/main/installer-amd64Cannot open display:Cannot open display:Run virt-viewer --help to see a full list of availableRun virt-viewer --help to see a full list of available command line command lineoptionsoptionsDomain installation still in progress. You can reconnectDomain installation still in progress. You can reconnect to tothe console to complete the installation process.the console to complete the installation process.
  • 43. Virt-viewer● Connect to the VMs console with – RDP – VNC – SPICE● Default vnc port -> 5900● virt-viewer virt-viewer -c qemu:///system xpsp2 virt-viewer -c qemu:///system xpsp2
  • 44. virt-clone● Clones an existing VM (Duh!!)● Copies disk images● Defines new machine based on source – MAC address is auto generated● Deploy many similar machines from one image (template).
  • 45. virt-clone[root@HV01 ~]# virt-clone -o vm01 -n vm01-copy -f /[root@HV01 ~]# virt-clone -o vm01 -n vm01-copy -f //VMS/vm01-copy.img/VMS/vm01-copy.imgAllocating vm01-copy.imgAllocating vm01-copy.img | 10 GB | 10 GB 03:37 03:37Clone vm01-copy created successfully.Clone vm01-copy created successfully.[root@HV01 ~]#[root@HV01 ~]#
  • 46. virt-topvirt-top 20:40:19 - x86_64 2/2CPU 2666MHz 3962MBvirt-top 20:40:19 - x86_64 2/2CPU 2666MHz 3962MB4 domains, 4 active, 4 running, 0 sleeping, 0 paused, 0 inactive D:0 O:0 X:04 domains, 4 active, 4 running, 0 sleeping, 0 paused, 0 inactive D:0 O:0 X:0CPU: 2.8% Mem: 2560 MB (2560 MB by guests)CPU: 2.8% Mem: 2560 MB (2560 MB by guests) ID S RDRQ WRRQ RXBY TXBY %CPU %MEM ID S RDRQ WRRQ RXBY TXBY %CPU %MEM TIME TIME NAME NAME 14 14 R R 0 0 0 1220 0 1220 0 0 2.5 2.5 25.0 315:52.95 WIN7 25.0 315:52.95 WIN7 15 15 R R 0 0 4 146 4 146 42 42 0.2 0.2 12.0 12.0 0:54.64 vm01 0:54.64 vm01 11 11 R R 0 0 0 0 0.2 0.2 12.0 15:38.34 vm02-fromxml 12.0 15:38.34 vm02-fromxml 16 16 R R 0 0 0 104 0 104 0 0 0.0 0.0 12.0 12.0 0:54.82 vm01-copy 0:54.82 vm01-copy
  • 47. Virtual machine manager
  • 48. Virtual Machine Manager● A GUI for virsh and virt-*● Runs only on Linux/Unix● Can discover machines running libvirtd (nodes)● Local development / testing
  • 49. Virtual Machine Manager
  • 50. libguestfslibguestfs :Converting, Inspecting and modifying VMs
  • 51. libguestfs● Manipulation of VM images● Inspection of VM images● Exists out of several separate tools – List is available on http://virt-tools.org/docs/index.html● No need to login on the VM itself● Can be run on an active VM
  • 52. What is this image? Is it still needed?Developers like to keep stuff
  • 53. Libguestfs : virt-inspector● What if you just have an image● You cannot login to machine● You would like to know what version of a package is installed● Generate list of all VMs
  • 54. Libguestfs : virt-inspector Inspect the domain virt-inspector -d WIN7 virt-inspector -d WIN7 Inspect an image[root@HV01 VMS]# virt-inspector -a /var/lib/libvirt/images/WIN7.img[root@HV01 VMS]# virt-inspector -a /var/lib/libvirt/images/WIN7.img
  • 55. 1 <name>windows</name>2 <arch>i386</arch>3 <distro>windows</distro>4 <product_name>Windows 7 Professional</product_name>5 <product_variant>Client</product_variant>6 <major_version>6</major_version>7 <minor_version>1</minor_version>8 <windows_systemroot>/Windows</windows_systemroot>9 <windows_current_control_set>ControlSet001</windows_current_control_set>10 <hostname>btr-PC</hostname>11 <format>installed</format>
  • 56. 1 <applications>2 <application>3 <name>Mozilla Firefox 6.0.2 (x86 en-US)</name>4 <display_name>Mozilla Firefox 6.0.2 (x86 en-US)</display_name>5 <version>6.0.2</version>6 <install_path>C:Program FilesMozilla Firefox</install_path>7 <publisher>Mozilla</publisher>8 <url>http://www.mozilla.com/en-US/</url>9 <description>Mozilla Firefox 6.0.2 (x86 en-US)</description>10 </application>11 </applications>
  • 57. Libguestfs : virt-df ● Allows you to view filesystem layout and space free/used Virt-df <name of domain>[root@HV01 ~]# virt-df vm02-fromxml[root@HV01 ~]# virt-df vm02-fromxmlFilesystemFilesystem 1K-blocks 1K-blocks Used Used Available Available Use% Use%vm02-fromxml:/dev/sdbvm02-fromxml:/dev/sdb 3516418 3516418 3516418 3516418 0 0 100% 100%vm02-fromxml:/dev/sda1vm02-fromxml:/dev/sda1 495844 495844 30573 30573 439671 439671 7% 7%vm02-fromxml:/dev/VolGroup/lv_rootvm02-fromxml:/dev/VolGroup/lv_root 3652680 3652680 623180 623180 2843952 2843952 18% 18%[root@HV01 ~]#[root@HV01 ~]#
  • 58. Libguestfs : virt-win-reg● Modify registry of Windows machines virt-win-reg --merge <vmname>.img viostor-reg virt-win-reg --merge <vmname>.img viostor-reg
  • 59. Libguestfs : virt-win-regManually Prepare a Windows image with virtio drivers virt-win-reg --merge <vmname>.img viostor-reg virt-win-reg --merge <vmname>.img viostor-reg guestfish -i <vmname>.img guestfish -i <vmname>.img <fs>upload viostor.sys <fs>upload viostor.sys /WINDOWS/system32/drivers/viostor.sys /WINDOWS/system32/drivers/viostor.sys
  • 60. Libguestfs : virt-tar-out● Create backups from files on the VM # virt-tar-out -d vm01 /home home-vm01.tar # virt-tar-out -d vm01 /home home-vm01.tar● Create backups from files on the disk image # virt-tar-out -a /VMS/vm01.img /home home-vm01-disk.tar # virt-tar-out -a /VMS/vm01.img /home home-vm01-disk.tar
  • 61. virt-v2v :migration of virtual machines
  • 62. Virt-v2v : short overview● Tool to automate migrations to KVM/RHEV● Migrate to KVM or RHEV from – XEN – VMWare – KVM● Installs virtio drivers and reconfigures machine● Can be scripted for bulk operations
  • 63. Virt-v2v : migrate from Vmware to RHEV
  • 64. Virt-v2v : migrate from VMWare to RHEVvirt-v2v -ic esx://esx.example.com/?no_verify=1virt-v2v -ic esx://esx.example.com/?no_verify=1 -o rhev -o rhev-os storage.example.com:/exportdomain --network-os storage.example.com:/exportdomain --network rhevm vm- rhevm vm-namename
  • 65. Virt-v2v : migrate VMWare to KVM
  • 66. sVirt : secure your host and VMs
  • 67. sVirtVirtualization introduces new risks
  • 68. sVirt “Old” daysMachines where physically separated and “attackable” via the network
  • 69. sVirt With Virtualization :A flawed hypervisor can give access to ALL VMs running on it Bypassing network security
  • 70. sVirt sVirt :Apply MAC for guest and resourcesMAC policy is set by hypervisor host Based on SELinux (dont reinvent the wheel) Auto apply or manual
  • 71. Disk images[root@HV01 VMS]# ls -Z |grep vm01[root@HV01 VMS]# ls -Z |grep vm01qemu qemu system_u:object_r:svirt_image_t:s0:c656,c817qemu qemu system_u:object_r:svirt_image_t:s0:c656,c817 vm01-copy.img vm01-copy.imgqemu qemu system_u:object_r:svirt_image_t:s0:c690,c972qemu qemu system_u:object_r:svirt_image_t:s0:c690,c972 vm01.img vm01.img Processes[root@HV01 VMS]# ps auxZ | grep vm01 |awk {print $1"[root@HV01 VMS]# ps auxZ | grep vm01 |awk {print $1" " $22} " $22}system_u:system_r:svirt_t:s0:c690,c972system_u:system_r:svirt_t:s0:c690,c972 vm01 vm01system_u:system_r:svirt_t:s0:c656,c817system_u:system_r:svirt_t:s0:c656,c817 vm01-copy vm01-copy
  • 72. A lot of tools but what to do with them?
  • 73. RHEV is first example
  • 74. Build your own stack?Development environment?
  • 75. Enterprise usage
  • 76. RHEV 2.x● RHEV (Red Hat enterprise Virtualization) – Red Hat started adopting KVM (actually they bought it) – Released 2.1 – Running on Windows platform ( the horror.. ) – RHEV 2.2 will be latest release in 2.x series
  • 77. RHEV 3.0● Port from .Net to Java● Manager runs on Jboss – no more windows server side● Hypervisor based on RHEL 6 – Gives performance increase● Local storage● Reporing engine included● WAN optimized SPICE
  • 78. RHEV 3.0● Power User portal – Users can manage their own environment● RESTful API● Will be open sourced
  • 79. RHEV adoption
  • 80. OVA● Open Virtualization Alliance● Foster the adoption of KVM as an enterprise- ready open virtualization solution● Accelerate the emergence of an ecosystem of third-party solutions around KVM.● Encourage interoperability, promote best practices, and highlight examples of customer successes.
  • 81. Ova : members
  • 82. specvirt● Virtualization benchmark (score@ n VMs)● KVM – 3894@240● VmWare ESX 4.1 – 3723@228
  • 83. conclusions● KVM is till young● Adoption is growing● Builds on Linux features (feature velocity) – Selinux, Cgroups, Scheduler, ...● A lot of community activity● scalability● Growing ECO system● No vendor lockin● OVA (open virtualization alliance)
  • 84. Questions?
  • 85. http://www.flickr.com/photos/kalavinka/4617897952/ http://www.flickr.com/photos/zakh/337938459/ http://docs.redhat.com/docs/en- US/Red_Hat_Enterprise_Linux/6/html- single/Virtualization/index.htmlhttp://www.cyberciti.biz/faq/linux-kvm-vnc-for-guest-machine/ http://www.centos.org/docs/5/html/5.2/Virtualization/chap- Virtualization-Managing_guests_with_virsh.htmlhttp://heprc.phys.uvic.ca/sites/heprc.phys.uvic.ca/files/reports/vliet-wtr.pdf
  • 86. Grind out appliances
  • 87. BoxGrinder : overview● Create a VM “offline”● Runs on JBOSS● Use puppet/chef/.. to configure it further● Move from Fedora to RHEL by adjusting the file●