八、XML配置文件详解

八、demo.xml模板详解
8.1 保存node虚拟机配置文件
[root@room8pc205 ~]# virsh dumpxml node1 >/root/node1.xml
8.2 清除模板
[root@room8pc205 ~]# virsh undefine node1
8.3 注释
— <!— 注释开始
— --> 注释结尾
8.4 注意
— xml标签必须成对出现
8.5 xml配置文件详细讲解
<domain type='kvm' id='8'> #id=8个性化设置做虚拟机模板时需要去掉
<name>node1</name> #虚拟机的名字
<uuid>04cd0fc4-5ecd-42b7-a989-55f558332a5e</uuid> #uuid个性化设置,做虚拟机模板时需去掉
<memory unit='KiB'>2048000</memory> #虚拟机最大使用内存,可以手动调整
<currentMemory unit='KiB'>2048000</currentMemory> #创建虚拟机使用的内存
<vcpu placement='static'>2</vcpu> #cpu的数量,可以手动调整
<resource>
<partition>/machine</partition> #资源设置可以删除,一般不管他
</resource>
- 系统配置及引导设备,丌需要修改
<os>
<type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
<boot dev='hd'/>
<bootmenu enable='yes'/>
<bios useserial='yes'/>
</os>
–电源相关配置无需修改
<features>
<acpi/>
<apic/>
</features>
— cpu配置,可以修改成使用真机cpu(比较重要)
<cpu mode='host-passthrough' check='none'/>
— 时钟相关配置,可以初除
<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='qcow2'/>
<source file='/var/lib/libvirt/images/node1.img'/>
<backingStore type='file' index='1'>
<format type='raw'/>
<source file='/var/lib/libvirt/images/node.qcow2'/>
<backingStore/>
</backingStore>
<target dev='vda' bus='virtio'/>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</disk>
如果需要新增硬盘改动如下:
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/node2.img'/> #node2.img需要qemu.img创建
<target dev='vdb' bus='virtio'/> # dev(设备){ bus(总线)}hda(pci) :最差;sdb(scsi):一般用于服务器;vda(virtio) :虚拟化专用总线技术
</disk>
– usb相关设备配置,可以不管
<controller type='usb' index='0' model='piix3-uhci'>
<alias name='usb'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'>
<alias name='pci.0'/>
</controller>
<controller type='virtio-serial' index='0'>
<alias name='virtio-serial0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</controller>
— 网卡
<interface type='bridge'>
<mac address='52:54:00:f2:0e:2e'/>
<source bridge='vbr'/>
<target dev='vnet0'/>
<model type='virtio'/>
<alias name='net0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
— 新增网卡格式
<interface type='bridge'>
<source bridge='vbr'/> #需要重新制定交换机这儿不做更改
<target dev='vnet0'/>
<model type='virtio'/>
</interface>
<serial type='pty'>
<source path='/dev/pts/2'/>
<target type='isa-serial' port='0'>
<model name='isa-serial'/>
</target>
<alias name='serial0'/>
</serial>
<console type='pty' tty='/dev/pts/2'>
<source path='/dev/pts/2'/>
<target type='serial' port='0'/>
<alias name='serial0'/>
</console>
<channel type='unix'>
<source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-8-node1/org.qemu.guest_agent.0'/>
<target type='virtio' name='org.qemu.guest_agent.0' state='connected'/>
<alias name='channel0'/>
<address type='virtio-serial' controller='0' bus='0' port='1'/>
</channel>
<input type='mouse' bus='ps2'>
<alias name='input0'/>
</input>
<input type='keyboard' bus='ps2'>
<alias name='input1'/>
</input>
<memballoon model='virtio'>
<alias name='balloon0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</memballoon>
</devices>
— 驱劢安全标签,可初除
<seclabel type='dynamic' model='dac' relabel='yes'>
<label>+107:+107</label>
<imagelabel>+107:+107</imagelabel>
</seclabel>
</domain>

 

posted @ 2021-07-19 16:51  落樰兂痕  阅读(587)  评论(0)    收藏  举报