kvm 虛擬機XML文件

<domain type='kvm' id='29'>
//domain 是一個全部虛擬機都須要的根元素,它有兩個屬性,
//type定義使用哪一個虛擬機管理程序,值能夠是:xen、kvm、qemu、lxc、kqemu,
//第二個參數是id,它惟一的標示一個運行的虛擬機,不活躍的客戶端沒有id。
  <name>i-000039</name>
//name參數爲虛擬機定義了一個簡短的名字,必須惟一。

  <uuid>d59b03ce-2e78-4d35-b731-09d9ca9653af</uuid>
//uid爲虛擬機定義了一個全球惟一的標示符,uuid的格式必須遵循RFC 4122指定的格式,當建立虛擬機沒有指定uuid時會隨機的生成一個uuid。

  <memory unit='KiB'>4194304</memory>
  <currentMemory unit='KiB'>4194304</currentMemory>
  <memtune>
    <hard_limit unit='KiB'>4194304</hard_limit>
  </memtune>
    //memory 定義客戶端啓動時能夠分配到的最大內存,內存單位由unit定義,單位能夠是:K、KiB、M、MiB、G、GiB、T、TiB。默認是KiB。
  
  
  <vcpu placement='static'>1</vcpu>
  //vcpu的內容是爲虛擬機最多分配幾個cpu,值處於1~maxcpu之間,可選參數:cpuset參數指定虛擬cpu能夠映射到那些物理cpu上,物理 cpu用逗號分開,單個數字的標示單個cpu,
  //也能夠用range符號標示多個cpu,數字前面的脫字符標示排除這個cpu,current參數指定虛擬 機最少,placement參數指定一個domain的cpu的分配模式,值能夠是static、auto。
  
  
  <cputune>
    <shares>1024</shares>
    <period>100000</period>
    <quota>-1</quota>
  </cputune>
  <resource>
    <partition>/machine</partition>
  </resource>
  
  
 //操做系統啓動介紹
  <os>
    <type arch='x86_64' machine='pc-i440fx-2.8'>hvm</type>
    //type參數指定了虛擬機操做系統的類型,內容:hvm代表該OS被設計爲直接運行在裸金屬上面,須要全虛擬化,
    //而linux(一個很差的名字)指OS支 持XEN3hypervisor的客戶端ABI,
    //type一樣有兩個可選參數:arch指定虛擬機的CPU構架,machine指定機器的類型。
    //<boot dev='hd'/>dev屬性的值能夠是:fd、hd、cdrom、network,它常常被用來指定下一次啓動。boot的元素能夠被設置多個用來創建一個啓動優先規則。
    <bootmenu enable='yes' timeout='0'/>
    <bios useserial='yes'/>
  </os>
  
  Hypervisor的特性
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  Hypervisors容許特定的CPU/機器特性打開或關閉,全部的特性都在fearures元素中,如下介紹一些在全虛擬化中經常使用的標記:
pae:擴展物理地址模式,使32位的客戶端支持大於4GB的內存
acpi:用於電源管理
hap:Enable use of Hardware Assisted Paging if available in the hardware.
  
  
  
  //cpu分配
  <cpu>
    <topology sockets='1' cores='1' threads='1'/>
    <numa>
      <cell id='0' cpus='0' memory='4194304' unit='KiB'/>
    </numa>
  </cpu>
  
  時間設置
  <clock offset='variable' adjustment='0' basis='utc'>
    <timer name='rtc' track='guest'/>
  </clock>
  客戶端的時間初始化來自宿主機的時間,大多數操做系統指望硬件時鐘保持UTC格式,UTC也是默認格式,然而Windows機器卻指望它是’localtime’
clock的offset屬性支持四種格式的時間:UTC localtime timezone variable
UTC:當引導時客戶端時鐘同步到UTC時鐘
localtime:當引導時客戶端時鐘同步到主機時鐘所在的時區
timezone:The guest clock will be synchronized to the requested timezone using the timezone attribute.

  
  //控制週期:
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>preserve</on_crash>
  <on_lockfailure>poweroff</on_lockfailure>
  //當一個客戶端的OS觸發lifecycle時,它將採起新動做覆蓋默認操做,具體狀態參數以下:
 //on_poweroff:當客戶端請求poweroff時執行特定的動做
  //on_reboot:當客戶端請求reboot時執行特定的動做
  // on_crash:當客戶端崩潰時執行的動做
   //每種狀態下能夠容許指定以下四種行爲:
    //destory:domain將會被徹底終止,domain的全部資源會被釋放
    //restart:domain會被終止,而後以相同的配置從新啓動
    //preserver:domain會被終止,它的資源會被保留用來分析
    //rename-restart:domain會被終止,而後以一個新名字被從新啓動
  
  
  <devices>
  //全部的設備都是一個名爲devices元素的子設備(All devices occur as children of the main devices element.),如下是一個簡單的配置:
//<emulator>/usr/bin/kvm</emulator>
//emulator元素指定模擬設備二進制文件的全路徑
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='cdrom'>
      <backingStore/>
      <target dev='hdd' bus='ide'/>
      <readonly/>
      <boot order='2'/>
      <alias name='ide0-1-1'/>
      <address type='drive' controller='0' bus='1' target='0' unit='1'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/datastore/6ee684f1-8b25-4f0a-9721-fe96540c1870/ae386362-eed6-43a8-b5a8-11a42fabc0ed'/>
      <backingStore/>
      <target dev='vda' bus='virtio'/>
      <boot order='1'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x01' function='0x0'/>
    </disk>
    <controller type='usb' index='0' model='ich9-ehci1'>
      <alias name='usb'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </controller>
    <controller type='usb' index='1' model='pci-ohci'>
      <alias name='usb1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </controller>
    <controller type='ide' index='0'>
      <alias name='ide'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <controller type='scsi' index='0' model='virtio-scsi'>
      <alias name='scsi0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </controller>
    <controller type='virtio-serial' index='0'>
      <alias name='virtio-serial0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'>
      <alias name='pci.0'/>
    </controller>
    <controller type='pci' index='1' model='pci-bridge'>
      <model name='pci-bridge'/>
      <target chassisNr='1'/>
      <alias name='pci.1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </controller>
    <lease>
      <lockspace>6ee684f1-8b25-4f0a-9721-fe96540c1870</lockspace>
      <key>ae386362-eed6-43a8-b5a8-11a42fabc0ed</key>
      <target path='/datastore/6ee684f1-8b25-4f0a-9721-fe96540c1870/.6ee684f1-8b25-4f0a-9721-fe96540c1870/.leases' offset='4194304'/>
    </lease>
    
    
    網絡接口:
有好幾種網絡接口訪問客戶端:Virtual network、Bridge to LAN、Userspace SLIRP stack、Generic ethernet connection、Direct attachment to physical interface。
Virtual network:這種推薦配置通常是對使用動態/無線網絡環境訪問客戶端的狀況。
Bridge to LAN:這種推薦配置通常是使用靜態有限網絡鏈接客戶端的狀況。
    <interface type='bridge'>
      <mac address='00:16:3e:bd:8e:f3'/>
      <source bridge='vxlansw-000003'/>
      <virtualport type='openvswitch'>
        <parameters interfaceid='1fb6d3e0-c0c0-4fdd-9edb-c64b1327763f'/>
      </virtualport>
      <target dev='vnd59b03ce0'/>
      <model type='virtio'/>
      <boot order='3'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x10' function='0x0'/>
    </interface>
    <interface type='bridge'>
      <mac address='00:16:3e:59:09:2d'/>
      <source bridge='vxlansw-000003'/>
      <virtualport type='openvswitch'>
        <parameters interfaceid='f8a225e1-028f-4396-8107-879f5b77152c'/>
      </virtualport>
      <target dev='vnd59b03ce1'/>
      <model type='rtl8139'/>
      <alias name='net1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x11' function='0x0'/>
    </interface>
    <interface type='bridge'>
      <mac address='00:16:3e:97:5b:c0'/>
      <source bridge='vxlansw-000003'/>
      <virtualport type='openvswitch'>
        <parameters interfaceid='f688fbc6-c4e3-4348-9408-12dc903dab06'/>
      </virtualport>
      <target dev='vnd59b03ce2'/>
      <model type='virtio'/>
      <alias name='net2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x12' function='0x0'/>
    </interface>
    
    //串行端口
    <serial type='pty'>
      <source path='/dev/pts/14'/>
      <target port='0'/>
      <alias name='serial0'/>
    </serial>
    在每組指令中,最頂層的指令(parallel, serial, console, channel)描述設備怎樣出如今客戶端中,客戶端接口經過target配置。
The interface presented to the host is given in the type attribute of the top-level element. The host interface is configured by the source element


    <console type='pty' tty='/dev/pts/14'>
      <source path='/dev/pts/14'/>
      <target type='serial' port='0'/>
      <alias name='serial0'/>
    </console>
    <channel type='unix'>
      <source mode='bind' path='/var/lib/libvirt/qemu/channels/i-000039.com.inspur.ics.vmtools'/>
      <target type='virtio' name='com.inspur.ics.vmtools' state='disconnected'/>
      <alias name='channel0'/>
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
    </channel>
    <channel type='unix'>
      <source mode='bind' path='/var/lib/libvirt/qemu/channels/i-000039.com.inspur.ics.agent'/>
      <target type='virtio' name='org.qemu.guest_agent.0' state='disconnected'/>
      <alias name='channel1'/>
      <address type='virtio-serial' controller='0' bus='0' port='2'/>
    </channel>
    
    
    <input type='tablet' bus='usb'>
      <alias name='input0'/>
      <address type='usb' bus='0' port='1'/>
    </input>
    <input type='mouse' bus='ps2'>
      <alias name='input1'/>
    </input>
    <input type='keyboard' bus='ps2'>
      <alias name='input2'/>
    </input>
    輸入設備:
輸入設備容許使用圖形化界面和虛擬機交互,當有圖形化framebuffer的時候,輸入設備會被自動提供的。
<input type='mouse' bus='ps2'/>
input元素:input元素含有一個強制的屬性,type屬性的值能夠是mouse活tablet,前者使用想對運動,後者使用絕對運動。bus屬性指定一個明確的設備類型,值能夠是:xen、ps二、usb。

    
    <graphics type='vnc' port='5905' autoport='yes' listen='0.0.0.0' keymap='en-us' sharePolicy='force-shared'>
      <listen type='address' address='0.0.0.0'/>
    </graphics>
    graphics元素:graphics含有一個強制的屬性type,type的值能夠是:sdl、vnc、rdp、desktop。vnc則啓動vnc 服務,port屬性指定tcp端口,若是是-1,則表示自動分配,vnc的端口自動分配的話是從5900向上遞增。listen屬性提供一個IP地址給服 務器監聽,能夠單獨在listen元素中設置。passwd屬性提供一個vnc的密碼。keymap屬性提供一個keymap使用。
Rather than putting the address information used to set up the listening socket for graphics types vnc and spice in the <graphics> listen attribute, a separate subelement of <graphics>, called <listen> can be specified (see the examples above)since 0.9.4. <listen> accepts the following attributes:
listen元素:listen元素專門針對vnc和spice設置監聽端口等。它包含如下屬性:type、address、network。type的 值能夠是address或network。若是設置了type=address,那麼address屬性設置一個ip地址或者主機名來監聽。若是 type=network,則network屬性設置一個網絡名稱在libvirt‘s的網絡配置文件中。

字符設備提供同虛擬機進行交互的接口,Paravirtualized consoles, serial ports, parallel ports and channels 都是字符設備,它們使用相同的語法。
    
    
    <video>
      <model type='cirrus' vram='16384' heads='1' primary='yes'/>
      <alias name='video0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    video元素:是描述聲音設備的容器,爲了向後徹底兼容,若是沒有設置video可是有graphics在xml配置文件中,這時libvirt會按照 客戶端類型增長一個默認的video,。model元素有一個強制的type屬性,它的值能夠是:vga、cirrus、vmvga、xen、vbox、 qxl。例如一個客戶端類型爲kvm,那麼默認的type值是cirrus。
    
    
    
    <memballoon model='virtio'>
      <alias name='balloon0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </memballoon>
    <panic model='isa'>
      <address type='isa' iobase='0x505'/>
    </panic>
  </devices>
  
  
  <seclabel type='none' model='none'/>
  <seclabel type='dynamic' model='dac' relabel='yes'>
    <label>+0:+0</label>
    <imagelabel>+0:+0</imagelabel>
  </seclabel>
</domain>
相關文章
相關標籤/搜索