Introduction to Virtualization, Virsh and Virt-Manager

2,090 views
1,935 views

Published on

Published in: Software, Technology
0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,090
On SlideShare
0
From Embeds
0
Number of Embeds
34
Actions
Shares
0
Downloads
131
Comments
0
Likes
9
Embeds 0
No embeds

No notes for slide

Introduction to Virtualization, Virsh and Virt-Manager

  1. 1. Introduction to Virtualization, Virsh Commands and Virt-Manager Chin Pin Chang 04/07/2014 1
  2. 2. Outline • Virtualization – Introduction – Types of Virtualization – KVM – Practice: KVM Installation • Virsh Commands – Introduction – Practice: 3 Units • Virt-Manager • Conclusion • References 2
  3. 3. Virtualization Introduction • Virtualization is a broad term that refers to the abstraction of computer physical resources such as servers, network, memory and storage 3
  4. 4. Virtualization Introduction (cont.) 4 • Without Virtualization • With Virtualization
  5. 5. 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
  6. 6. Types of Virtualization • Server Virtualization – Full virtualization, Paravirtualization, Hardware-assisted virtualization • Application Virtualization • Desktop Virtualization • Presentation Virtualization • Network Virtualization • Storage Virtualization 6
  7. 7. KVM Introduction • KVM (Kernel-based Virtual Machine) – A Linux kernel module that turns Linux into a hypervisor – Full virtualization 7
  8. 8. 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
  9. 9. Install KVM (cont.) • Check BIOS – Support – Not support 9
  10. 10. Install KVM (cont.) • Install necessary packages – qemu-kvm – libvirt-bin – ubuntu-vm-builder – bridge-utils 10
  11. 11. Add Users to Libvirtd and KVM Groups • Add user "username" to libvirtd • Add user " username" to KVM • Need to re-login 11
  12. 12. Verify Installation • Check groups • Verify Installation • Change the device's group 12
  13. 13. Install Virt-manager • Install virt-manager • Start virt-manager 13
  14. 14. Step 1 - Create new virtual machine 14
  15. 15. Step 2 – Locate install media 15
  16. 16. Step 3 – Specify CPU and Memory 16
  17. 17. Step 4 – Specify Storage 17
  18. 18. Step 5 – Specify Network 18
  19. 19. Install Ubuntu Server 19
  20. 20. Virsh Introduction • Virsh is a command line interface tool for managing VM and the hypervisor 20
  21. 21. 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
  22. 22. Virsh Commands Unit 1 Domain Management 22
  23. 23. Introduction • Domain management – Is used to manage VM – Major commands: define, start, destroy, suspend, resume and so on 23
  24. 24. How to use virsh 24
  25. 25. 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
  26. 26. Define a VM 26
  27. 27. 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
  28. 28. 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
  29. 29. 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
  30. 30. 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
  31. 31. 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
  32. 32. 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
  33. 33. Start VM 33
  34. 34. domid Item Content Description Convert a domain name or UUID to domain id Input 1. domain Example # domid vm1 Response 1 34
  35. 35. domname Item Content Description Convert a guest domain id or UUID to guest domain name Input 1. domain Example # domname 1 Response vm1 35
  36. 36. 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
  37. 37. VM Information • The domain ID • The domain name • The domain uuid 37
  38. 38. 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
  39. 39. Auto start VM 39
  40. 40. 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
  41. 41. List VM 41
  42. 42. 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
  43. 43. Connect to VM 43
  44. 44. Connect to VM (cont.) 44 • Launch Apache service • Check Apache service
  45. 45. Connect to VM (cont.) • Check the IP of the VM 45
  46. 46. Connect to VM (cont.) • Check /var/www/index.html • Web page 46
  47. 47. suspend Item Content Description Suspend a running guest domain Input 1.domain Example # suspend vm1 Response Domain vm1 suspended 47
  48. 48. Suspend VM • Web page 48
  49. 49. resume Item Content Description Resume a guest domain Input 1.domain Example # resume vm1 Response Domain vm1 resumed 49
  50. 50. Resume VM • Web page 50
  51. 51. 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
  52. 52. restore Item Content Description Restore a guest domain Input 1.file Example # restore image Response Domain restored from image 52
  53. 53. Save and Restore scenario S0 Save the VM Restore the VM Start the VM Modify index.htm S0S2S1 53 Step 4Step 3Step 2Step 1
  54. 54. Step 1 • Save the VM • The saved file 54
  55. 55. Step 2 and 3 • Start the VM • Modify /var/www/index.html • Web page 55
  56. 56. Step 4 • Restore the VM • Web page 56
  57. 57. 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
  58. 58. Destroy VM 58
  59. 59. The memory information of the host • Before destroying the VM • After destroying the VM 59
  60. 60. 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
  61. 61. Undefine VM 61
  62. 62. Virsh Commands Unit 2 Interface Management and Network Management 62
  63. 63. Introduction • Interface management – To create an interface on the host for VM 63
  64. 64. 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
  65. 65. Define an interface • Interface br1 65
  66. 66. 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
  67. 67. 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
  68. 68. 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
  69. 69. Start interface 69
  70. 70. 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
  71. 71. 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
  72. 72. Interface Information • The interface name • The interface mac 72
  73. 73. 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
  74. 74. Destroy interface 74
  75. 75. 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
  76. 76. Undefine interface 76
  77. 77. 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
  78. 78. 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
  79. 79. Define network • Network vlan1 79
  80. 80. XML for Network <network > <name>vlan1</name> <forward mode='bridge'/> <bridge name='br1' /> </network> 80
  81. 81. 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
  82. 82. net-start Item Content Description Starts a (previously defined) inactive virtual network Input 1. network Example # net-start vlan1 Response Network vlan1 started 82
  83. 83. Start network 83
  84. 84. 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
  85. 85. Auto start network 85
  86. 86. 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
  87. 87. Network Information 87
  88. 88. 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
  89. 89. 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
  90. 90. Network Information • The network name • The network uuid 90
  91. 91. net-destroy Item Content Description Shuts down a running virtual network Input 1. network Example # net-destroy vlan1 Response Network vlan1 destroyed 91
  92. 92. Destroy network 92
  93. 93. 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
  94. 94. Undefine network 94
  95. 95. 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
  96. 96. Example • Define the interfaces br1 and br2 96
  97. 97. 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>
  98. 98. 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>
  99. 99. XML for VM • Modify VM1.xml • Modify VM2.xml • Modify VM3.xml 99
  100. 100. Define VM • Define VM1, VM2 and VM3 100
  101. 101. Start VM • Start VM1, VM2 and VM3 101
  102. 102. Start interface • Start interface br1 and br2 102
  103. 103. Connect to VM • Assign IP (192.168.0.101) to VM1 103
  104. 104. Connect to VM (cont.) • Assign IP (192.168.0.102) to VM2 104
  105. 105. Connect to VM (cont.) • Assign IP (192.168.0.103) to VM3 105
  106. 106. Result • VM1 ping VM2 • VM1 ping VM3 106
  107. 107. Result (cont.) • VM3 ping VM1 • VM3 ping VM2 107
  108. 108. Virsh Commands Unit 3 Snapshot and Migrate 108
  109. 109. 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
  110. 110. 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
  111. 111. 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. 112. 112 • Start VM • Take a snapshot Create a snapshot for VM
  113. 113. Create a folder in VM 113 • Start VM • Create a folder "test"
  114. 114. Launch Apache service • Check /var/www/index.html • Web page 114
  115. 115. Launch Apache service (cont.) • Modify the /var/www/index.html • Web page 115
  116. 116. 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
  117. 117. Revert snapshot • Folder • Web page 117
  118. 118. 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
  119. 119. Delete snapshot 119
  120. 120. Introduction • Migrate – Migration is the process of moving a virtual machine from one host or storage location to another 120
  121. 121. 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
  122. 122. Set up NFS server for images • Install NFS server packages – nfs-common – nfs-kernel-server 122 • Set shared path and permission
  123. 123. Set up NFS server for images (cont.) • Start NFS server 123 • Check NFS path
  124. 124. Set up NFS client – hypervisor • Install NFS client packages – nfs-common 124 • Mount image • Check
  125. 125. Set up NFS client – hypervisor (cont.) • Restart NFS server 125 • Check image on client
  126. 126. 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
  127. 127. Start VM 127
  128. 128. Download a file to VM 128
  129. 129. Migrate VM to destination host • Source host 129 The URI of the destination host
  130. 130. After migration • Destination host 130
  131. 131. Verify the file • The file size 131
  132. 132. Virt-manager Introduction • The virt-manager (Virtual Machine Manager) application is a graphic user interface for managing virtual machines through libvirt 132
  133. 133. Main window 133
  134. 134. Connection window 134
  135. 135. Define VM 135
  136. 136. Start VM 136
  137. 137. Connect to VM 137
  138. 138. Verify connection 138 • Virt-manager
  139. 139. Suspend VM 139
  140. 140. Resume VM 140
  141. 141. Save VM 141
  142. 142. Save VM (cont.) 142
  143. 143. Restore VM 143
  144. 144. Clone VM 144
  145. 145. Check CPU usage of VM 145
  146. 146. Destroy VM 146
  147. 147. Delete VM 147
  148. 148. 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
  149. 149. Question 149 • Mail:walkerchang@iii.org.tw
  150. 150. 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

×