Introduction to Virtualization, Virsh and Virt-Manager
Upcoming SlideShare
Loading in...5
×
 

Introduction to Virtualization, Virsh and Virt-Manager

on

  • 266 views

 

Statistics

Views

Total Views
266
Views on SlideShare
258
Embed Views
8

Actions

Likes
0
Downloads
14
Comments
0

1 Embed 8

http://www.slideee.com 8

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Introduction to Virtualization, Virsh and Virt-Manager Introduction to Virtualization, Virsh and Virt-Manager Presentation Transcript

  • Introduction to Virtualization, Virsh Commands and Virt-Manager Chin Pin Chang 04/07/2014 1
  • Outline • Virtualization – Introduction – Types of Virtualization – KVM – Practice: KVM Installation • Virsh Commands – Introduction – Practice: 3 Units • Virt-Manager • Conclusion • References 2
  • Virtualization Introduction • Virtualization is a broad term that refers to the abstraction of computer physical resources such as servers, network, memory and storage 3
  • Virtualization Introduction (cont.) 4 • Without Virtualization • With Virtualization
  • Why Virtualization • Resource sharing • High utilization of resource • Reduce the number of physical servers • Ability to bring up new server quickly • Easy maintenance and monitoring 5
  • Types of Virtualization • Server Virtualization – Full virtualization, Paravirtualization, Hardware-assisted virtualization • Application Virtualization • Desktop Virtualization • Presentation Virtualization • Network Virtualization • Storage Virtualization 6
  • KVM Introduction • KVM (Kernel-based Virtual Machine) – A Linux kernel module that turns Linux into a hypervisor – Full virtualization 7
  • Install KVM • Check that your CPU supports hardware virtualization – 0 indicates that your CPU doesn’t support hardware virtualization – 1 or more indicates that it supports hardware virtualization 8
  • Install KVM (cont.) • Check BIOS – Support – Not support 9
  • Install KVM (cont.) • Install necessary packages – qemu-kvm – libvirt-bin – ubuntu-vm-builder – bridge-utils 10
  • Add Users to Libvirtd and KVM Groups • Add user "username" to libvirtd • Add user " username" to KVM • Need to re-login 11
  • Verify Installation • Check groups • Verify Installation • Change the device's group 12
  • Install Virt-manager • Install virt-manager • Start virt-manager 13
  • Step 1 - Create new virtual machine 14
  • Step 2 – Locate install media 15
  • Step 3 – Specify CPU and Memory 16
  • Step 4 – Specify Storage 17
  • Step 5 – Specify Network 18
  • Install Ubuntu Server 19
  • Virsh Introduction • Virsh is a command line interface tool for managing VM and the hypervisor 20
  • Virsh Introduction (cont.) • Virsh Commands Classification 21 – Domain management commands – Domain monitoring commands – Host and hypervisor commands – Interface commands – Network filter commands – Virtual networking commands – Node device commands – Secrets commands – Domain snapshot commands – Storage pool commands – Storage volume commands – Virsh commands
  • Virsh Commands Unit 1 Domain Management 22
  • Introduction • Domain management – Is used to manage VM – Major commands: define, start, destroy, suspend, resume and so on 23
  • How to use virsh 24
  • define Item Content Description Define, but don't start, a guest domain from an XML file Input 1. XML file Example # define vm1.xml Response Domain vm1 defined from vm1.xml 25
  • Define a VM 26
  • XML for VM <domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'> <name>vm1</name> <uuid>b7cb10e2-c6af-a328-ad75-3e09747f0564</uuid> <memory>524288</memory> <currentMemory>524288</currentMemory> <vcpu>1</vcpu> <os> <type arch='armv7l' machine='vexpress-a15'>hvm</type> <kernel>/root/zImage</kernel> <cmdline>earlyprintk=ttyAMA0 console=ttyAMA0 mem=512M root=/dev/vda rw ip=192.168.20.56::192.168.20.101:vm1:eth0:off --no-log</cmdline> <dtb>/root/guest-vexpress.dtb</dtb> </os> <features> <acpi/> <pae/> </features> <!-- <cpu> <model>cortex-a15</model> </cpu> --> 27
  • XML for VM (cont.) <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-arm</emulator> <disk type='file' device='disk'> <driver name='qemu' type='raw' cache='none'/> <source file='/root/nfs/ubuntu1G.img'/> <target dev='vda' bus='virtio'/> </disk> <interface type='bridge'> <source bridge='virbr0'/> <mac address='52:54:00:12:34:55'/> <model type='virtio'/> </interface> <console type='pty'/> </devices> </domain> 28
  • XML parameters • name – Virtual machine name • uuid – A globally unique identifier for the virtual machine • current memory – The actual allocation of memory for the VM • type – The type of operating system in the virtual machine • kernel – The fully-qualified path to the kernel image in the host OS 29
  • XML parameters (cont.) • cmdline – The arguments to be passed to the kernel at boot time • dtb – The fully-qualified path to the device tree binary image in the host OS • emulator – The fully qualified path to the device model emulator binary • disk – The main container for describing disks • source file – The resource on the host that is being accessed in the guest 30
  • XML parameters (cont.) • target – The source can be accessed in the guest • interface type – A network interface visible to the guest • source bridge – The interface of the network • mac address – The address of the network • model type – The model of emulated network interface 31
  • start Item Content Description Start a guest domain, either from the last managed save state, or via a fresh boot if no managed save state is present Input 1.domain Example # start vm1 Response Domain vm1 started 32
  • Start VM 33
  • domid Item Content Description Convert a domain name or UUID to domain id Input 1. domain Example # domid vm1 Response 1 34
  • domname Item Content Description Convert a guest domain id or UUID to guest domain name Input 1. domain Example # domname 1 Response vm1 35
  • domuuid Item Content Description Convert a guest domain name or id to guest domain UUID Input 1. domain Example # domuuid vm1 Response b7cb10e2-c6af-a328-ad75-3e09747f0564 36
  • VM Information • The domain ID • The domain name • The domain uuid 37
  • autostart Item Content Description Enable and disable the automatic starting of a guest domain when the libvirt daemon starts Input 1. domain Example # autostart vm1 Response Domain vm1 marked as autostarted 38
  • Auto start VM 39
  • list Item Content Description Returns a list of guest domains Input N/A Example # list Response virsh # list Id Name State ---------------------------------------------------- 1 vm1 running 40
  • List VM 41
  • console Item Content Description Connect the virtual serial console for the guest Input 1. domain Example # console vm1 Response Connected to domain vm1 Escape character is ^] 42
  • Connect to VM 43
  • Connect to VM (cont.) 44 • Launch Apache service • Check Apache service
  • Connect to VM (cont.) • Check the IP of the VM 45
  • Connect to VM (cont.) • Check /var/www/index.html • Web page 46
  • suspend Item Content Description Suspend a running guest domain Input 1.domain Example # suspend vm1 Response Domain vm1 suspended 47
  • Suspend VM • Web page 48
  • resume Item Content Description Resume a guest domain Input 1.domain Example # resume vm1 Response Domain vm1 resumed 49
  • Resume VM • Web page 50
  • save Item Content Description Save the running state of a guest domain to a file Input 1.domain 2.file Example # save vm1 image Response Domain vm1 saved to image 51
  • restore Item Content Description Restore a guest domain Input 1.file Example # restore image Response Domain restored from image 52
  • Save and Restore scenario S0 Save the VM Restore the VM Start the VM Modify index.htm S0S2S1 53 Step 4Step 3Step 2Step 1
  • Step 1 • Save the VM • The saved file 54
  • Step 2 and 3 • Start the VM • Modify /var/www/index.html • Web page 55
  • Step 4 • Restore the VM • Web page 56
  • destroy Item Content Description Immediately terminates a running guest domain, releasing any resources in use by it Input 1.domain Example # destroy vm1 Response Domain vm1 destroyed 57
  • Destroy VM 58
  • The memory information of the host • Before destroying the VM • After destroying the VM 59
  • undefine Item Content Description Remove the configuration for an inactive guest domain Input 1.domain Example # undefine vm1 Response Domain vm1 has been undefined 60
  • Undefine VM 61
  • Virsh Commands Unit 2 Interface Management and Network Management 62
  • Introduction • Interface management – To create an interface on the host for VM 63
  • iface-define Item Content Description Define a physical host network interface Input 1. XML file Example # iface-define br1.xml Response Interface br1 defined from br1.xml 64
  • Define an interface • Interface br1 65
  • XML for Interface <interface type='bridge' name='br1'> <start mode='onboot'/> <bridge> <interface type='vlan' name='bond0.1'> <vlan tag='1'> <interface name='bond1'/> </vlan> </interface> </bridge> </interface> 66
  • XML parameters • interface type – Network interface type • interface name – The name of interface • bridge type – The type of bridge • vlan tag – Use to tag of the vlan 67
  • iface-start Item Content Description Enables and starts a physical host network interface Input 1. interface Example # iface-start br1 Response Interface br1 started 68
  • Start interface 69
  • iface-name Item Content Description Returns the physical host interface name for a MAC address Input 1. interface(MAC address) Example # iface-name 3a:a0:42:19:ca:b2 Response br1 70
  • iface-mac Item Content Description Returns the MAC address for a physical host network interface Input 1. interface Example # iface-mac br1 Response 3a:a0:42:19:ca:b2 71
  • Interface Information • The interface name • The interface mac 72
  • iface-destroy Item Content Description Shut down and disable a physical host network interface Input 1. interface Example # iface-destroy br1 Response Interface br1 destroyed 73
  • Destroy interface 74
  • iface-undefine Item Content Description Removes the configuration information for a physical host network interface Input 1. interface Example # iface-undefine br1 Response Interface br1 undefined 75
  • Undefine interface 76
  • Introduction • Network management – Libvirt has the capability to define virtual networks which can then be used by domains and linked to actual network devices 77
  • net-define Item Content Description Adds a new permanent virtual network from an XML file, without starting it Input 1. file Example # net-define vlan1.xml Response Network vlan1 defined from vlan1.xml 78
  • Define network • Network vlan1 79
  • XML for Network <network > <name>vlan1</name> <forward mode='bridge'/> <bridge name='br1' /> </network> 80
  • XML parameters • name – Virtual network name • forward mode – Inclusion of the forward element indicates that the virtual network is to be connected to the physical LAN • bridge name – The name of a bridge device 81
  • net-start Item Content Description Starts a (previously defined) inactive virtual network Input 1. network Example # net-start vlan1 Response Network vlan1 started 82
  • Start network 83
  • net-autostart Item Content Description Enable or disable the automatic starting of a virtual network, when the libvirt daemon starts Input 1. network Example # net-autostart vlan1 Response Network vlan1 marked as autostarted 84
  • Auto start network 85
  • net-info Item Content Description Displays basic information for a virtual network Input 1. network Example # net-info vlan1 Response Name vlan1 UUID f1f1cd7e-b623-4d7e-94c8-2047da1decef Active: yes Persistent: yes Autostart: yes Bridge: br1 86
  • Network Information 87
  • net-name Item Content Description When given a network UUID, returns its corresponding network name Input 1. network Example # net-name f1f1cd7e-b623-4d7e-94c8-2047da1decef Response vlan1 88
  • net-uuid Item Content Description When given a network name, returns its corresponding UUID Input 1. network Example # net-uuid vlan1 Response f1f1cd7e-b623-4d7e-94c8-2047da1decef 89
  • Network Information • The network name • The network uuid 90
  • net-destroy Item Content Description Shuts down a running virtual network Input 1. network Example # net-destroy vlan1 Response Network vlan1 destroyed 91
  • Destroy network 92
  • net-undefine Item Content Description Removes an inactive virtual network from the libvirt configuration Input 1. network Example # net-undefine vlan1 Response Network vlan1 has been undefined 93
  • Undefine network 94
  • Interface and Network scenario 95 Host virbr0 br1 br2 VM1 VM2 VM3 IP: 192.168.1.101 192.168.1.102 192.168.1.103 vlan1 vlan2
  • Example • Define the interfaces br1 and br2 96
  • XML for host 97 • br1.xml <interface type='bridge' name='br1'> <start mode='onboot'/> <bridge> <interface type='vlan' name='bond0.1'> <vlan tag='1'> <interface name='bond1'/> </vlan> </interface> </bridge> </interface>
  • XML for host (cont.) 98 • br2.xml <interface type='bridge' name='br2'> <start mode='onboot'/> <bridge> <interface type='vlan' name='bond0.2'> <vlan tag=‘2'> <interface name='bond2'/> </vlan> </interface> </bridge> </interface>
  • XML for VM • Modify VM1.xml • Modify VM2.xml • Modify VM3.xml 99
  • Define VM • Define VM1, VM2 and VM3 100
  • Start VM • Start VM1, VM2 and VM3 101
  • Start interface • Start interface br1 and br2 102
  • Connect to VM • Assign IP (192.168.0.101) to VM1 103
  • Connect to VM (cont.) • Assign IP (192.168.0.102) to VM2 104
  • Connect to VM (cont.) • Assign IP (192.168.0.103) to VM3 105
  • Result • VM1 ping VM2 • VM1 ping VM3 106
  • Result (cont.) • VM3 ping VM1 • VM3 ping VM2 107
  • Virsh Commands Unit 3 Snapshot and Migrate 108
  • Introduction • Snapshot – Snapshots take the disk, memory, and device state of a VM at a point-of-time, and save it for future use • --disk-only – The snapshot will only include disk state 109
  • Snapshot scenario 110 Create a folder and modify index.htm Start the VM Restart the VM Revert the snapshot Step 4Step 3Step 2Step 1 S0 S3S2S1 S1 Step 5
  • snapshot-create Item Content Description Create a snapshot (disk and RAM) from XML Input 1. domain 2. xml Example # snapshot-create vm1 snaptest.xml Response Domain snapshot snaptest created from 'snaptest.xml' 111
  • 112 • Start VM • Take a snapshot Create a snapshot for VM
  • Create a folder in VM 113 • Start VM • Create a folder "test"
  • Launch Apache service • Check /var/www/index.html • Web page 114
  • Launch Apache service (cont.) • Modify the /var/www/index.html • Web page 115
  • snapshot-revert Item Content Description Reverts a domain to a given snapshot Input 1. domain 2. snapshotname Example # snapshot-revert vm1 snaptest Response N/A 116
  • Revert snapshot • Folder • Web page 117
  • snapshot-delete Item Content Description Removes a snapshot, and all of it's children, from a domain Input 1. domain 2. snapshotname Example # snapshot-delete --domain vm1 snaptest --metadata Response Domain snapshot snaptest deleted 118
  • Delete snapshot 119
  • Introduction • Migrate – Migration is the process of moving a virtual machine from one host or storage location to another 120
  • Migration 121 Source VM Download a file Destination VM Download a file Migration Network IP: 192.92.26.120 IP: 192.92.26.108 NFS /Data/image VM image
  • Set up NFS server for images • Install NFS server packages – nfs-common – nfs-kernel-server 122 • Set shared path and permission
  • Set up NFS server for images (cont.) • Start NFS server 123 • Check NFS path
  • Set up NFS client – hypervisor • Install NFS client packages – nfs-common 124 • Mount image • Check
  • Set up NFS client – hypervisor (cont.) • Restart NFS server 125 • Check image on client
  • migrate Item Content Description Migrates a guest domain to another host Input 1.domain 2.dest uri Example # migrate vm1 qemu+ssh://140.92.26.108/system Response pass 126
  • Start VM 127
  • Download a file to VM 128
  • Migrate VM to destination host • Source host 129 The URI of the destination host
  • After migration • Destination host 130
  • Verify the file • The file size 131
  • Virt-manager Introduction • The virt-manager (Virtual Machine Manager) application is a graphic user interface for managing virtual machines through libvirt 132
  • Main window 133
  • Connection window 134
  • Define VM 135
  • Start VM 136
  • Connect to VM 137
  • Verify connection 138 • Virt-manager
  • Suspend VM 139
  • Resume VM 140
  • Save VM 141
  • Save VM (cont.) 142
  • Restore VM 143
  • Clone VM 144
  • Check CPU usage of VM 145
  • Destroy VM 146
  • Delete VM 147
  • Conclusion • Virtualization – High utilization of physical resource • Virsh – The main interface for managing virtualization environment through Libvirt • Virt-manager – Graphic user interface for managing virtualization environment through Libvirt 148
  • Question 149 • Mail:walkerchang@iii.org.tw
  • References • http://libvirt.org/ • http://en.wikipedia.org/wiki/Virtualization • http://en.wikipedia.org/wiki/Kernel-based_Virtual_Machine • http://www.slideshare.net/trupti242/virtuallization- questions# • https://access.redhat.com/site/documentation/en- US/Red_Hat_Enterprise_Linux/ • http://trac.nchc.org.tw/cloud • https://help.ubuntu.com/community/KVM/Installation • http://www.ubuntu-tw.org/modules/tinyd0/ 150