作者介绍:简历上没有一个精通的运维工程师。请点击上方的蓝色《运维小路》关注我,下面的思维导图也是预计更新的内容和当前进度(不定时更新)。
虚拟化,简单来说就是把一台服务器/PC电脑,虚拟成多台独立的虚拟机,每台虚拟机之间相互隔离,每个虚拟机都有自己独立的操作系统,磁盘,网络资源。虚拟化是一个很庞大的系统,我的介绍主要是帮助你入门,让你了解基本技术原理,具备搭建操作虚拟化的能力。由于涉及到内容较多,这里的目录就只是以简单分类介绍和说明,不再针对单个小节进行目录列出,主要涉及的分类包括以下几个方面:
1.虚拟化介绍
2.kvm基本使用(本小节属于)
3.kvm进阶使用
4.kvm技术原理
5.vmware介绍&使用
6.小结
我们通过virsh list可以看到虚拟机的名字和状态,但是我们并不能看到这个虚拟机详细信息,虽然我们可以使用virsh dominfo查看部分详细信息,可是这个命令显示的结果毕竟是有限的,所以我们需要更详细的了解虚拟机的信息则需要通过其他方式。
默认我们每创建一个虚拟机,就会生成一个对应名字.xml 的文件,默认路径是在 /etc/libvirt/qemu/
,当然通过ps命令也能看到部分参数。
这个xml文件就可以理解是就是这个虚拟机的元数据,这里的部分信息是我们创建虚拟机里面注入的参数,比如cpu,内存,硬盘,名字等。部分参数则是系统自动生成的,比如键盘鼠标支持等。
我们如果修改了xml文件需要使用define命令来让他生效。下面我们就来讲讲这个xml文件。下面的xml解释就是一个真实的虚拟机的xml文件。
<domain type='kvm'>
<name>MyVM</name>
<uuid>c47e19d5-b25c-4581-8a95-fcb1cb02fd04</uuid>
<memory unit='KiB'>524288</memory>
<currentMemory unit='KiB'>524288</currentMemory>
<vcpu placement='static'>1</vcpu>
##这里上面注意定义资源大小,名字等信息,是创建的时候输入的参数,可修改
<os>
<type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
</features>
<cpu mode='custom' match='exact' check='partial'>
<model fallback='allow'>Broadwell-noTSX-IBRS</model>
<feature policy='require' name='md-clear'/>
<feature policy='require' name='spec-ctrl'/>
<feature policy='require' name='ssbd'/>
</cpu>
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
</clock>
##这上面的信息是系统自动生成的,一般不要去修改
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
##这里定义了虚拟机某些行为会触发的动作
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
##定义了对于虚拟机的挂起状态的开关
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/data/image_file.img'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<target dev='hdb' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
##上面部分内容定义了磁盘内容,包括光盘ios和系统盘所对于的img
##如果还有多块磁盘,则这里也会显示,也可以通过这里添加磁盘定义,来实现添加磁盘的功能。
<controller type='usb' index='0' model='ich9-ehci1'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x7'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci1'>
<master startport='0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0' multifunction='on'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci2'>
<master startport='2'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x1'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci3'>
<master startport='4'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<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:8c:ed:f9'/>
<source bridge='virbr0'/>
<model type='rtl8139'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
##定义了网卡配置,如果修改网络连接,可以在这里重新调整,
##比如修改mac,修改桥接网卡。
<serial type='pty'>
<target type='isa-serial' port='0'>
<model name='isa-serial'/>
</target>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
#定义了终端的一些操作说明
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes'>
<listen type='address'/>
##定义了vnc的信息
##如果要修改端口或者修改监听地址,需要在这里修改。
</graphics>
<video>
<model type='cirrus' vram='16384' heads='1' primary='yes'/>
<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>
其实这个xml文件还是比较简单,我们传递进去的参数,也可以根据实际情况进行调整和修改。
在kvm里面并没有一个类似数据库的地方来存储这些详细,都是以xml方式进行存储的。在实际公有云及私有云里面,一般都会有专门的数据库来存储这些信息,从而实现迁移等操作。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有