KVM虚拟机技术学习总结
最近在学习KVM,进程不算太快,近期整理了一下KVM虚拟机技术学习笔记,现在就分享给大家,也给大家做个参考。有需要的朋友可以来了解一下。
KVM虚拟机的管理主要是通过virsh命令对虚拟机进行管理。
1. 查看KVM虚拟机配置文件及运行状态
(1)KVM虚拟机默认配置文件位置:/etc/libvirt/qemu/
autostart目录是配置kvm虚拟机开机自启动目录。
(2)virsh命令帮助
#virsh-help
或直接virsh命令和,再执行子命令。如下所示。
[root@node1~]#virsh
欢迎使用virsh,虚拟化的交互式终端。
输入:'help'来获得命令的帮助信息
'quit'退出
virsh#help
……
(3)查看kvm虚拟机状态
#virshlist--all
2. KVM虚拟机开机
#virshstartoeltest01
3.KVM虚拟机关机或断电
(1)关机
默认情况下virsh工具不能对linux虚拟机进行关机操作,linux操作系统需要开启与启动acpid服务。在安装KVMlinux虚拟机必须配置此服务。
#chkconfigacpidon
#serviceacpidrestart
virsh关机
#virshshutdownoeltest01
(2)强制关闭电源
#virshdestroywintest01
4.通过配置文件启动虚拟机
#virshcreate/etc/libvirt/qemu/wintest01.xml
5.配置开机自启动虚拟机
#virshautostartoeltest01
autostart目录是kvm虚拟机开机自启动目录,可以看到该目录中有KVM配置文件链接。
6.导出KVM虚拟机配置文件
#virshdumpxmlwintest01>/etc/libvirt/qemu/wintest02.xml
KVM虚拟机配置文件可以通过这种方式进行备份。
7.添加与删除KVM虚拟机
(1) 删除kvm虚拟机
#virshundefinewintest01
说明:该命令只是删除wintest01的配置文件,并不删除虚拟磁盘文件。如下图所示。
(2) 重新定义虚拟机配置文件
通过导出备份的配置文件恢复原KVM虚拟机的定义,并重新定义虚拟机。
#mv/etc/libvirt/qemu/wintest02.xml/etc/libvirt/qemu/wintest01.xml
#virshdefine/etc/libvirt/qemu/wintest01.xml
8.编辑KVM虚拟机配置文件
#virsheditwintest01
virshedit将调用vi命令编辑/etc/libvirt/qemu/wintest01.xml配置文件。也可以直接通过vi命令进行编辑,修改,保存。
可以但不建议直接通过vi编辑。
[root@node1qemu]#vi/etc/libvirt/qemu/wintest01.xml <!-- WARNING:THISISANAUTO-GENERATEDFILE.CHANGESTOITARELIKELYTOBE OVERWRITTENANDLOST.Changestothisxmlconfigurationshouldbemadeusing: virsheditwintest01 orotherapplicationusingthelibvirtAPI. --> <domaintype='kvm'> <name>wintest01</name> <uuid>fe31ea48-7d6a-f3cb-cede-2f9bd9dec2bd</uuid> <memoryunit='KiB'>524288</memory> <currentMemoryunit='KiB'>524288</currentMemory> <vcpuplacement='static'>2</vcpu> <os> <typearch='x86_64'machine='rhel6.4.0'>hvm</type> <bootdev='hd'/> </os> <features> <acpi/> <apic/> <pae/> </features> <clockoffset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/libexec/qemu-kvm</emulator> <disktype='file'device='disk'> <drivername='qemu'type='raw'cache='none'/> <sourcefile='/data/wintest01.img'/> <targetdev='hda'bus='ide'/> <addresstype='drive'controller='0'bus='0'target='0'unit='0'/> </disk> <disktype='block'device='cdrom'> <drivername='qemu'type='raw'/> <targetdev='hdc'bus='ide'/> <readonly/> <addresstype='drive'controller='0'bus='1'target='0'unit='0'/> </disk> <controllertype='usb'index='0'> <addresstype='pci'domain='0x0000'bus='0x00'slot='0x01'function='0x2'/> </controller> <controllertype='ide'index='0'> <addresstype='pci'domain='0x0000'bus='0x00'slot='0x01'function='0x1'/> </controller> <interfacetype='bridge'> <macaddress='52:54:00:2b:2f:fe'/> <sourcebridge='br0'/> <addresstype='pci'domain='0x0000'bus='0x00'slot='0x03'function='0x0'/> </interface> <serialtype='pty'> <targetport='0'/> </serial> <consoletype='pty'> <targettype='serial'port='0'/> </console> <inputtype='mouse'bus='ps2'/> <graphicstype='vnc'port='5911'autoport='no'listen='0.0.0.0'> <listentype='address'address='0.0.0.0'/> </graphics> <video> <modeltype='cirrus'vram='9216'heads='1'/> <addresstype='pci'domain='0x0000'bus='0x00'slot='0x02'function='0x0'/> </video> <memballoonmodel='virtio'> <addresstype='pci'domain='0x0000'bus='0x00'slot='0x04'function='0x0'/> </memballoon> </devices> <seclabeltype='none'/> </domain>
9.其它virsh命令
(1)挂起服务器
#virshsuspendoeltest01
(2)恢复服务器
#virsh resumeoeltest01
virsh命令丰富。可以执行各种维护任务,本文只是从维护与管理的角度例举了常用的命令,为该命令的使用提供一个思路。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。