这里以dcs01.xml为例:
<domain type='kvm'> <name>dcs01</name> <uuid>e5fff551-bbe1-e748-c8e4-8ecb3bffb902</uuid> <memory>1048576</memory> <currentMemory>1048576</currentMemory> <vcpu>1</vcpu> <os> <type arch='x86_64' machine='rhel6.0.0'>hvm</type> <boot dev='hd'/> </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset='localtime'/> <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='/home/kvm/images/dcs01.img'/> <target dev='hda' bus='ide'/> <address type='drive' controller='0' bus='0' unit='0'/> </disk> <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <target dev='hdc' bus='ide'/> <readonly/> <address type='drive' controller='0' bus='1' unit='0'/> </disk> <controller type='ide' index='0'> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> </controller> <interface type='bridge'> <mac address='52:54:00:ad:75:98'/> <source bridge='br0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> <input type='tablet' bus='usb'/> <input type='mouse' bus='ps2'/> <graphics type='vnc' port='-1' autoport='yes'/> <video> <model type='vga' 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='0x05' function='0x0'/> </memballoon> </devices> </domain>
解释以下:
1、kvm guest 定义最先
<domain type='kvm'>
2、guest的short name。由字母和数字构成,不能包含空格
<name>dcs01</name>
3、uuid,由敕令行东西 uuidgen生成。
<uuid>e5fff551-bbe1-e748-c8e4-8ecb3bffb902</uuid>
4、在不reboot guest的情况下,guset能够运用的最大内存,以KB为单元
<memory>1048576</memory>
5、guest启动时内存,能够经由过程virsh setmem来调解内存,但不能大于最大可运用内存。
<currentMemory>1048576</currentMemory>
6、分派的假造cpu
<vcpu>1</vcpu>
7、有关OS
架构:i686、x86_64
machine:宿主机的操作系统
boot:指定启动装备,能够反复多行,指定差别的值,作为一个启动装备列表。
<os> <type arch='x86_64' machine='rhel6.0.0'>hvm</type> <boot dev='hd'/> </os>
8、处理器特征
<features> <acpi/> <apic/> <pae/> </features>
9、时钟。运用当地时候:localtime
<clock offset='localtime'/>
10、定义了在kvm环境中power off,reboot,或crash时的默许的行动分别为destroy和restart。其他许可的行动包含: preserve,rename-restart.。
destroy:住手该假造机。相当于封闭电源。
restart重启假造机。
<on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash>
11、装备定义最先
<devices>
12、模仿元素,此处写法用于kvm的guest
<emulator>/usr/libexec/qemu-kvm</emulator>
13、用于kvm存储的文件。在这个例子中,在guest中显现为IDE装备。
运用qemu-img敕令建立该文件,kvm image的默许目次为:/var/lib/libvirt/images/
<disk type='file' device='disk'> <driver name='qemu' type='raw' cache='none'/> <source file='/home/kvm/images/dcs01.img'/> <target dev='hda' bus='ide'/> <address type='drive' controller='0' bus='0' unit='0'/> </disk>
补充:能够定义多个磁盘。
运用virtio:
采纳一般的驱动,即硬盘和网卡都采纳默许设置情况下,网卡事情在 模仿的rtl 8139 网卡下,速率为100M 全双工。采纳 virtio 驱动后,网卡事情在 1000M 的形式下。
采纳一般的驱动,即硬盘和网卡都采纳默许设置情况下,硬盘是 ide 形式。采纳 virtio 驱动后,硬盘事情是SCSI形式下。
<disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/usr/local/kvm/vmsample/disk.os'/> <target dev='vda' bus='virtio'/> </disk>
CD-ROM device:
<disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <target dev='hdc' bus='ide'/> <readonly/> <address type='drive' controller='0' bus='1' unit='0'/> </disk>
14、运用网桥范例。确保每一个kvm guest的mac地点唯一。将建立tun装备,名称为vnetx(x为0,1,2...)
<interface type='bridge'> <mac address='52:54:00:ad:75:98'/> <source bridge='br0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface>
补充:
运用默许的假造收集替代网桥,即guest为NAT形式。也能够省略mac地点元素,如许将自动生成mac地点。
<interface type='network'> <source network='default'/> <mac address="3B:6E:01:69:3A:11"/> </interface>
默许分派192.168.122.x/24的地点,也能够手动指定。网关为192.168.122.1
运用virtio:
采纳一般的驱动,即硬盘和网卡都采纳默许设置情况下,网卡事情在 模仿的rtl 8139 网卡下,速率为100M 全双工。采纳 virtio 驱动后,网卡事情在 1000M 的形式下。
<interface type='bridge'> <source bridge='br1'/> <model type='virtio' /> </interface>
15、输入装备
<input type='tablet' bus='usb'/> <input type='mouse' bus='ps2'/>
16、定义与guset交互的图形装备。在这个例子中,运用vnc协定。listen的地点为host的地点。prot为-1,示意自动分派端口号,经由过程以下的敕令查找端口号:
virsh vncdisplay <KVM Guest Name>
这里未设置
<graphics type='vnc' port='-1' autoport='yes'/>
17、装备定义完毕
</devices>
18、KVM定义完毕
</domain>
centos_x86_6.4
b9dcdd92-9b9b-14d6-3938-1982a9746a12
2097152
2097152
1
hvm
destroy
restart
restart
/bin/qemu-kvm
<disk type='file' device='disk'> <driver name='qemu' type='qcow2'/>
#目标镜像途径 在这个例子中,在guest中显现为IDE装备。
<source file='/home/template_make/centos_x86_6.4.img'> <seclabel model='selinux' relabel='no'/> </source> <target dev='hda' bus='ide'/> <alias name='ide0-0-0'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk> <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/home/template_make/CentOS-6.4-x86_64-bin-DVD1.iso'/> <target dev='hdc' bus='ide'/> <readonly/> <alias name='ide0-1-0'/> <address type='drive' controller='0' bus='1' target='0' unit='0'/> </disk> <controller type='usb' index='0'> <alias name='usb0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> </controller> <controller type='ide' index='0'> <alias name='ide0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> </controller> <interface type='bridge'>
#假造机收集连接体式格局
<mac address='52:54:00:78:f9:5a'/> <source bridge='br0'/> <target dev='vnet27'/>
## 运用virtio: 采纳一般的驱动,即硬盘和网卡都采纳默许设置情况下,硬盘是 ide 形式, 而网卡事情在 模仿的rtl 8139 网卡下,速率为100M 全双工。 采纳 virtio 驱动后,网卡事情在 1000M 的形式下,硬盘事情是SCSI形式下
<model type='virtio'/> <alias name='net0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> <input type='mouse' bus='ps2'/>
#vnc体式格局登录,端口号自动分派 能够经由过程virsh vncdisplay来查询[vncdisplay domainId]
<graphics type='vnc' port='5915' autoport='yes' listen='0.0.0.0'> <listen type='address' address='0.0.0.0'/> </graphics> <video> <model type='cirrus' vram='9216' heads='1'/> <alias name='video0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> </video> <memballoon model='virtio'> <alias name='balloon0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </memballoon> </devices> <seclabel type='dynamic' model='selinux' relabel='yes'> <label>unconfined_u:system_r:svirt_t:s0:c362,c396</label> <imagelabel>unconfined_u:object_r:svirt_image_t:s0:c362,c396</imagelabel> </seclabel></domain>
以上就是在KVM假造机中的设置xml的代码详解的细致内容,更多请关注ki4网别的相干文章!