设为首页 收藏本站
查看: 1145|回复: 0

[经验分享] libvirt笔记(未完待续)

[复制链接]

尚未签到

发表于 2017-6-24 22:44:58 | 显示全部楼层 |阅读模式
  参考源地址:http://libvirt.org/formatdomain.html
  http://blog.csdn.net/qq250941970/article/details/6022094
  libvirt是管理KVM的工具,通过libvirt可以管理配置虚拟机。而虚拟机的配置主要都是通过libvirt的xml文件来实现的,因此xml是十分重要的。

Domain XML format
  从官网文档中,我们可以发现xml文件具有一定的格式。
  1、Element and attribute overview(元素和属性概述
  根元素是所有虚拟机的域。它有两个属性,第一个属性是指定Hypervisor的类型,如”Xen”,“KVM”,“qemu”,“lxc”和“kqemu”。第二个属性是id,运行的guest Domain 的ID,已停用的guest Domain有没有ID值。



<domain type='xen' id='3'>
<name>xp</name>
<uuid>4dea22b31d52d8f32516782e98ab3fa0</uuid>
<description>Some human readable description</description>
  2、Operating system booting(操作系统的启动
  BIOS bootloader



<os>
<type>hvm</type>
<loader readonly='yes' type='rom'>/usr/lib/xen/boot/hvmloader</loader>
<nvram template='/usr/share/OVMF/OVMF_VARS.fd'>/var/lib/libvirt/nvram/guest_VARS.fd</nvram>
<boot dev='hd'/>
<boot dev='cdrom'/>
<bootmenu enable='yes' timeout='3000'/>
<smbios mode='sysinfo'/>
<bios useserial='yes' rebootTimeout='0'/>
</os>
  type 表示全虚拟化还是半虚拟化,hvm表示全虚拟化
  loader 全虚拟化才需要的,表示全虚拟化的守护进程所在位置
  boot 启动设备列表,如"fd"表示从文件启动, "hd"从硬盘启动, "cdrom"从光驱启动 和 "network"从网络启动,同时启动次序也可以由此顺序决定。
  bootmenu 当虚拟机启动时是否启用引导菜单,默认时表示使用引导菜单
  Host bootloader
   半虚拟化的虚拟机启动一般使用这个,在主机使用一个伪引导来为guest Domain提供一个界面选择启动的内核。下面是个xen下半虚拟化的启动范例



<bootloader>/usr/bin/pygrub</bootloader>
<bootloader_args>--append single</bootloader_args>
  Bootloader给出主机操作系统引导程序的完整路径,运行这个引导程序,选择启动的内核,这个会因使用的Hypervisor不同而不同。
  bootloader_args该元素的可选bootloader_args允许命令行参数传递到bootloader
  Direct kernel boot(内核直接启动)



  <os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
<kernel>/root/f8-i386-vmlinuz</kernel>
<initrd>/root/f8-i386-initrd</initrd>
<cmdline>console=ttyS0 ks=http://example.com/f8-i386/os/</cmdline>
</os>
  3、CPU Allocation(cpu资源)



<domain>
...
<vcpu placement='static' cpuset="1-4,^3,6" current="1">2</vcpu>
...
</domain>
  所谓cpuset,就是在用户空间中操作cgroup文件系统来执行进程与cpu和进程与内存结点之间的绑定,在cpu调优中一般会用到(稍后再写)
  4、基本资源



<memory>524288</memory>
<currentMemory>524288</currentMemory>
<memoryBacking>
<hugepages/>
</memoryBacking>
<memtune>
<hard_limit>1048576</hard_limit>
<soft_limit>131072</soft_limit>
<swap_hard_limit>2097152</swap_hard_limit>
<min_guarantee>65536</min_guarantee>
</memtune>
<vcpu cpuset="1-4,^3,6" current="1">2</vcpu>


<cpu match='exact'>
<model>core2duo</model>
<vendor>Intel</vendor>
<topology sockets='1' cores='2' threads='1'/>
<feature policy='disable' name='lahf_lm'/>
</cpu>
  这里可以看到各种资源的配置。内存大小、页面大小、memtune内存设定。cpu的model等等
  5、 Lifecycle control(操作控制)



<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
  用户请求不同动作时,对domain的执行也不同。
  6、 Devices(外设)



<devices>
<disk type='file' snapshot='external'>
<driver name="tap" type="aio" cache="default"/>
<source file='/var/lib/xen/images/fv0' startupPolicy='optional'>
<seclabel relabel='no'/>
</source>
<target dev='hda' bus='ide'/>
<iotune>
<total_bytes_sec>10000000</total_bytes_sec>
<read_iops_sec>400000</read_iops_sec>
<write_iops_sec>100000</write_iops_sec>
</iotune>
<boot order='2'/>
<encryption type='...'>
...
</encryption>
<shareable/>
<serial>
...
</serial>
</disk>
...
<disk type='network'>
<driver name="qemu" type="raw" io="threads" ioeventfd="on" event_idx="off"/>
<source protocol="sheepdog" name="image_name">
<host name="hostname" port="7000"/>
</source>
<target dev="hdb" bus="ide"/>
<boot order='1'/>
<transient/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<disk type='network'>
<driver name="qemu" type="raw"/>
<source protocol="rbd" name="image_name2">
<host name="hostname" port="7000"/>
<snapshot name="snapname"/>
<config file="/path/to/file"/>
</source>
<target dev="hdc" bus="ide"/>
<auth username='myuser'>
<secret type='ceph' usage='mypassid'/>
</auth>
</disk>
<disk type='block' device='cdrom'>
<driver name='qemu' type='raw'/>
<target dev='hdd' bus='ide' tray='open'/>
<readonly/>
</disk>
<disk type='network' device='cdrom'>
<driver name='qemu' type='raw'/>
<source protocol="http" name="url_path">
<host name="hostname" port="80"/>
</source>
<target dev='hde' bus='ide' tray='open'/>
<readonly/>
</disk>
<disk type='network' device='cdrom'>
<driver name='qemu' type='raw'/>
<source protocol="https" name="url_path">
<host name="hostname" port="443"/>
</source>
<target dev='hdf' bus='ide' tray='open'/>
<readonly/>
</disk>
<disk type='network' device='cdrom'>
<driver name='qemu' type='raw'/>
<source protocol="ftp" name="url_path">
<host name="hostname" port="21"/>
</source>
<target dev='hdg' bus='ide' tray='open'/>
<readonly/>
</disk>
<disk type='network' device='cdrom'>
<driver name='qemu' type='raw'/>
<source protocol="ftps" name="url_path">
<host name="hostname" port="990"/>
</source>
<target dev='hdh' bus='ide' tray='open'/>
<readonly/>
</disk>
<disk type='network' device='cdrom'>
<driver name='qemu' type='raw'/>
<source protocol="tftp" name="url_path">
<host name="hostname" port="69"/>
</source>
<target dev='hdi' bus='ide' tray='open'/>
<readonly/>
</disk>
<disk type='block' device='lun'>
<driver name='qemu' type='raw'/>
<source dev='/dev/sda'/>
<target dev='sda' bus='scsi'/>
<address type='drive' controller='0' bus='0' target='3' unit='0'/>
</disk>
<disk type='block' device='disk'>
<driver name='qemu' type='raw'/>
<source dev='/dev/sda'/>
<geometry cyls='16383' heads='16' secs='63' trans='lba'/>
<blockio logical_block_size='512' physical_block_size='4096'/>
<target dev='hdj' bus='ide'/>
</disk>
<disk type='volume' device='disk'>
<driver name='qemu' type='raw'/>
<source pool='blk-pool0' volume='blk-pool0-vol0'/>
<target dev='hdk' bus='ide'/>
</disk>
<disk type='network' device='disk'>
<driver name='qemu' type='raw'/>
<source protocol='iscsi' name='iqn.2013-07.com.example:iscsi-nopool/2'>
<host name='example.com' port='3260'/>
</source>
<auth username='myuser'>
<secret type='iscsi' usage='libvirtiscsi'/>
</auth>
<target dev='vda' bus='virtio'/>
</disk>
<disk type='network' device='lun'>
<driver name='qemu' type='raw'/>
<source protocol='iscsi' name='iqn.2013-07.com.example:iscsi-nopool/1'>
<host name='example.com' port='3260'/>
</source>
<auth username='myuser'>
<secret type='iscsi' usage='libvirtiscsi'/>
</auth>
<target dev='sdb' bus='scsi'/>
</disk>
<disk type='volume' device='disk'>
<driver name='qemu' type='raw'/>
<source pool='iscsi-pool' volume='unit:0:0:1' mode='host'/>
<auth username='myuser'>
<secret type='iscsi' usage='libvirtiscsi'/>
</auth>
<target dev='vdb' bus='virtio'/>
</disk>
<disk type='volume' device='disk'>
<driver name='qemu' type='raw'/>
<source pool='iscsi-pool' volume='unit:0:0:2' mode='direct'/>
<auth username='myuser'>
<secret type='iscsi' usage='libvirtiscsi'/>
</auth>
<target dev='vdc' bus='virtio'/>
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/domain.qcow'/>
<backingStore type='file'>
<format type='qcow2'/>
<source file='/var/lib/libvirt/images/snapshot.qcow'/>
<backingStore type='block'>
<format type='raw'/>
<source dev='/dev/mapper/base'/>
<backingStore/>
</backingStore>
</backingStore>
<target dev='vdd' bus='virtio'/>
</disk>
</devices>
  Encryption如果存在,指定如何给存储卷加密,查看存储加密页面更多信息
         Serial  这个在全虚拟化中比较重要,如果用文件存储,不加下面一段代码,虚拟机无法运行,下面代码是指出硬盘为串口
  <serial type='pty'>
        <source path='/dev/pts/3'/>
        <target port='0'/>
   </serial>



<devices>
<controller type='usb' index='0' model='ich9-ehci1'>
<address type='pci' domain='0' bus='0' slot='4' function='7'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci1'>
<master startport='0'/>
<address type='pci' domain='0' bus='0' slot='4' function='0' multifunction='on'/>
</controller>
...
</devices>
  USB设备的xml描述格式如上所示。
  官网关于USB重定向的描述:

Redirected devices
  USB device redirection through a character device is supported since after 0.9.5 (KVM only):



<devices>
<redirdev bus='usb' type='tcp'>
<source mode='connect' host='localhost' service='4000'/>
<boot order='1'/>
</redirdev>
<redirfilter>
<usbdev class='0x08' vendor='0x1234' product='0xbeef' version='2.56' allow='yes'/> //0x08指大容量存储设备,文件系统。此处指只有大容量存储设备才能访问虚拟机
<usbdev allow='no'/> //其他USB设备不行
</redirfilter>
</devices>
  USB常用设备类别和ID:
  http://wenku.baidu.com/link?url=66ymV2VeFOTlFCAEVG2iU0yZ3TM5zzWOzs2ICDUNdfK_ZIbg0CKNxgVCS1j-UMfoWSzQ954WsPPx8tfl9vbJz-Tm8nbizgdLNvaEKoteItS
  除此之外,还有网络设备,视频声卡

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-387737-1-1.html 上篇帖子: 看 nova-scheduler 如何选择计算节点 下篇帖子: OpenStack overview 笔记
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表