我是靠谱客的博主 平淡蜜蜂,这篇文章主要介绍在KVM虚拟机中的配置xml的代码详解,现在分享给大家,希望可以做个参考。

在RHEL6中,用于从磁盘启动的XML文件

  这里以dcs01.xml为例:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<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 定义开始

复制代码
1
<domain type='kvm'>
登录后复制

  2、guest的short name。由字母和数字组成,不能包含空格

复制代码
1
<name>dcs01</name>
登录后复制

  3、uuid,由命令行工具 uuidgen生成。

复制代码
1
<uuid>e5fff551-bbe1-e748-c8e4-8ecb3bffb902</uuid>
登录后复制

  4、在不reboot guest的情况下,guset可以使用的最大内存,以KB为单位

复制代码
1
<memory>1048576</memory>
登录后复制

  5、guest启动时内存,可以通过virsh setmem来调整内存,但不能大于最大可使用内存。

复制代码
1
<currentMemory>1048576</currentMemory>
登录后复制

  6、分配的虚拟cpu

复制代码
1
<vcpu>1</vcpu>
登录后复制

  7、有关OS
架构:i686、x86_64
machine:宿主机的操作系统
boot:指定启动设备,可以重复多行,指定不同的值,作为一个启动设备列表。

复制代码
1
2
3
4
<os> <type arch='x86_64' machine='rhel6.0.0'>hvm</type> <boot dev='hd'/> </os>
登录后复制

  8、处理器特性

复制代码
1
2
3
4
5
<features> <acpi/> <apic/> <pae/> </features>
登录后复制

  9、时钟。使用本地时间:localtime

复制代码
1
<clock offset='localtime'/>
登录后复制

  10、定义了在kvm环境中power off,reboot,或crash时的默认的动作分别为destroy和restart。其他允许的动作包括: preserve,rename-restart.。
destroy:停止该虚拟机。相当于关闭电源。
restart重启虚拟机。

复制代码
1
2
3
<on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash>
登录后复制

  11、设备定义开始

复制代码
1
<devices>
登录后复制

  12、模拟元素,此处写法用于kvm的guest

复制代码
1
<emulator>/usr/libexec/qemu-kvm</emulator>
登录后复制

  13、用于kvm存储的文件。在这个例子中,在guest中显示为IDE设备。
使用qemu-img命令创建该文件,kvm image的默认目录为:/var/lib/libvirt/images/

复制代码
1
2
3
4
5
6
<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模式下。

复制代码
1
2
3
4
5
<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:

复制代码
1
2
3
4
5
6
<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...)

复制代码
1
2
3
4
5
<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地址。

复制代码
1
2
3
4
<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 的模式下。

复制代码
1
2
3
4
<interface type='bridge'> <source bridge='br1'/> <model type='virtio' /> </interface>
登录后复制

  15、输入设备

复制代码
1
2
<input type='tablet' bus='usb'/> <input type='mouse' bus='ps2'/>
登录后复制

  16、定义与guset交互的图形设备。在这个例子中,使用vnc协议。listen的地址为host的地址。prot为-1,表示自动分配端口号,通过以下的命令查找端口号:
virsh vncdisplay <KVM Guest Name>

  这里未设置

复制代码
1
<graphics type='vnc' port='-1' autoport='yes'/>
登录后复制

  17、设备定义结束

复制代码
1
</devices>
登录后复制

  18、KVM定义结束

复制代码
1
</domain>
登录后复制

centos_x86_6.4
b9dcdd92-9b9b-14d6-3938-1982a9746a12
2097152
2097152
1
hvm
destroy
restart
restart
/bin/qemu-kvm

复制代码
1
2
<disk type='file' device='disk'> <driver name='qemu' type='qcow2'/>
登录后复制

#目的镜像路径 在这个例子中,在guest中显示为IDE设备。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<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'>
登录后复制

#虚拟机网络连接方式

复制代码
1
2
3
<mac address='52:54:00:78:f9:5a'/> <source bridge='br0'/> <target dev='vnet27'/>
登录后复制

## 使用virtio: 采用普通的驱动,即硬盘和网卡都采用默认配置情况下,硬盘是 ide 模式, 而网卡工作在 模拟的rtl 8139 网卡下,速度为100M 全双工。 采用 virtio 驱动后,网卡工作在 1000M 的模式下,硬盘工作是SCSI模式下

复制代码
1
2
3
4
5
<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]

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<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的代码详解的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是平淡蜜蜂最近收集整理的关于在KVM虚拟机中的配置xml的代码详解的全部内容,更多相关在KVM虚拟机中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(122)

评论列表共有 0 条评论

立即
投稿
返回
顶部