Recently in the study of KVM, the process is not too fast, recently organized a KVM virtual machine technology Learning notes, now share to everyone, but also for everyone to make a reference. A friend in need can come to know.
The management of the KVM virtual machine is mainly through the Virsh command to the virtual machine.
1. View the KVM virtual machine configuration file and running status
(1) KVM virtual machine default profile location:/etc/libvirt/qemu/
The Autostart directory is configured with a KVM virtual machine boot boot directory.
(2) Virsh command Help
# Virsh-help
or directly virsh the command and, then executes the child command. as shown below.
[Root@node1 ~]# Virsh
Welcome to use Virsh, virtualized interactive terminals.
Enter: ' Help ' to obtain the command's assistance information
' Quit ' exit
Virsh # Help
......
(3) View the status of the KVM virtual machine
# Virsh List--all
2. KVM Virtual Machine Boot
# Virsh Start oeltest01
3. KVM virtual body machine or power off
(1) Shutdown
By default, the Virsh tool does not shut down the Linux virtual machine, and the Linux operating system needs to turn on and start the Acpid service. This service must be configured to install a KVM Linux virtual machine.
# Chkconfig Acpid on
# Service Acpid Restart
Virsh shutdown
# Virsh Shutdown oeltest01
(2) Force power off
# Virsh Destroy wintest01
4. Start the virtual machine through the configuration file
# Virsh Create/etc/libvirt/qemu/wintest01.xml
5. Configure the Power-on self-starter virtual machine
# Virsh Autostart oeltest01
The Autostart directory is the KVM virtual machine boot boot directory, and you can see the KVM Profile link in the directory.
6. Export KVM Virtual machine configuration file
# Virsh Dumpxml wintest01 >/etc/libvirt/qemu/wintest02.xml
A KVM virtual machine profile can be backed up in this way.
7. Adding and removing KVM virtual machines
(1) Remove the KVM virtual machine
# Virsh Undefine wintest01
Description: This command simply deletes the wintest01 configuration file and does not delete the virtual disk file. As shown in the following figure.
(2) Redefining the virtual machine configuration file
Restore the definition of the original KVM virtual machine by exporting the backup configuration file and redefine the virtual machine.
# Mv/etc/libvirt/qemu/wintest02.xml/etc/libvirt/qemu/wintest01.xml
# Virsh Define/etc/libvirt/qemu/wintest01.xml
8. Edit the KVM virtual machine configuration file
# Virsh Edit wintest01
Virsh Edit invokes the VI command for editing the/etc/libvirt/qemu/wintest01.xml configuration file. can also be directly through the VI command to edit, modify, save.
Can but not recommend directly through VI Edit.
[Root@node1 qemu]# Vi/etc/libvirt/qemu/wintest01.xml <!--warning:this is a auto-generated FILE. CHANGES to IT ARE likely to is overwritten and LOST.
Changes to this XML configuration should is made Using:virsh edit wintest01 or other application using the Libvirt API. --> <domain type= ' KVM ' > <name>wintest01</name> <uuid> fe31ea48-7d6a-f3cb-cede-2f9bd9dec2bd</uuid> <memory unit= ' KiB ' >524288</memory> <
Currentmemory unit= ' KiB ' >524288</currentMemory> <vcpu placement= ' static ' >2</vcpu> <os>
<type arch= ' x86_64 ' machine= ' rhel6.4.0 ' >hvm</type> <boot dev= ' HD '/> </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset= ' UTC '/> <on_poweroff>destroy </on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> < devices> <emulator>/usr/libexec/qemu-kvm</emulator> <disk type= ' file ' dEvice= ' disk ' > <driver name= ' qemu ' type= ' raw ' cache= ' None '/> <source file= '/data/wintest01.img '/> < Target dev= ' hda ' bus= ' ide '/> <address type= ' drive ' controller= ' 0 ' bus= ' 0 ' target= ' 0 ' unit= ' 0 '/> </disk> & Lt;disk type= ' block ' device= ' cdrom ' > <driver name= ' qemu ' type= ' raw '/> <target ' dev= hdc ' bus= ' ' ide '/> < readonly/> <address type= ' drive ' controller= ' 0 ' bus= ' 1 ' target= ' 0 ' unit= ' 0 '/> </disk> <controller Type= ' USB ' index= ' 0 ' > <address type= ' PCI ' domain= ' 0x0000 ' bus= ' 0x00 ', ' slot= ' 0x01 ' function= 0x2 '/> ' controller> <controller type= ' ide ' index= ' 0 ' > <address type= ' PCI ' domain= ' 0x0000 ' bus= ' 0x00 ' "slot= '
function= ' 0x1 '/> </controller> <interface type= ' bridge ' > <mac address= ' 52:54:00:2b:2f:fe '/> <source bridge= ' br0 '/> <address type= ' pci ' domain= ' 0x0000 ' bus= ' 0x00 ', ' slot= ' ' 0x03 ' function= ' 0x0 ', ', ', '/> ' interface> <serial type= ' pty ' > <target port= ' 0 '/> </serial> <console type= ' pty ' > <target type= ' serial ' port= ' 0 '/> </console> <input type= ' mouse ' bus = ' ps2 '/> <graphics type= ' vnc ' port= ' 5911 ' autoport= ' no ' listen= ' 0.0.0.0 ' > <listen ' type= ' address ' address= ' 0.0.0.0 '/> </graphics> <video> <model type= ' Cirrus ' vram= ' 9216 ' heads= ' 1 '/> <address ' type= ' PCI ' domain= ' 0x0000 ' bus= ' 0x00 ' slot= ' 0x02 ' function= ' 0x0 ',/> </video> <memballoon model= ' Virtio ' > <
Address type= ' PCI ' domain= ' 0x0000 ' bus= ' 0x00 ' slot= ' 0x04 ' function= ' ' 0x0 ', </memballoon> </devices>
<seclabel type= ' None '/> </domain>
9. Other Virsh Orders
(1) Suspend server
# Virsh Suspend oeltest01
(2) Restore the server
# Virsh Resume oeltest01
Virsh commands abound. Can perform a variety of maintenance tasks, this article only from the maintenance and management point of view examples of common commands, for the use of this command to provide a way of thinking.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.