云原生技术之KVM虚拟机组成文件

举报
tea_year 发表于 2025/08/11 17:39:02 2025/08/11
【摘要】 学习目标能够使用virsh命令查看虚拟机能够找到虚拟机配置文件所在位置能够找到虚拟机磁盘文件所在位置虚拟机(guest,vm,domain,instance) = 磁盘文件image(Linux or Windows) + 配置文件(虚拟机名,2 VCPU,512M...)1.KVM虚拟机查看方法[root@localhost ~]# virsh list --all Id    Name ...

学习目标

能够使用virsh命令查看虚拟机

能够找到虚拟机配置文件所在位置

能够找到虚拟机磁盘文件所在位置

虚拟机(guest,vm,domain,instance) = 磁盘文件image(Linux or Windows) + 配置文件(虚拟机名,2 VCPU,512M...)


1.KVM虚拟机查看方法

[root@localhost ~]# virsh list --all
Id    Name                           State
----------------------------------------------------
4     centos7.6-2                    running
5     centos7.0.1                    running


2.虚拟机配置文件XML

查看虚拟机配置文件
[root@localhost ~]# ls /etc/libvirt/qemu
centos7.6-1.xml
[root@localhost ~]# cat /etc/libvirt/qemu/centos7.6-1.xml
...
<vcpu placement='static' current='1'>2</vcpu> 这是CPU现在是1核,可扩展到2....
...

更改虚拟机配置文件,更改完必须重启虚拟机才可生效.相当于修改centos7.6-1.xml
[root@localhost ~]# virsh edit 虚拟机名称
[root@localhost ~]# virsh dumpxml 虚拟机名称 > new_smartgo_01 #备份


3.设定vm自动运行

查看虚拟机列表,会显示虚拟机名称
[root@localhost ~]# virsh list

查看虚拟机是否开机自启.centos7.6-1 虚拟机名称
[root@hd1 ~]# virsh dominfo centos7.6-1
Id:             1
名称:       centos7.6-1
UUID:           93cbad81-0bce-4900-a555-9316a98e3290
OS 类型:    hvm
状态:       running
CPU          1
CPU 时间:   218.4s
最大内存: 4096000 KiB
使用的内存: 2048000 KiB
持久:      
自动启动: 禁用       =============自启信息!
管理的保存:
安全性模式: none
安全性 DOI 0

设置开机自启
[root@localhost ~]# virsh autostart centos7.6-1

设置开机自启后,会在/etc/libvirt/qemu下多一个目录autostart
[root@localhost ~]# cd /etc/libvirt/qemu/
[root@localhost ~]# ls
autostart  centos7.6-1.xml  networks

目录中会多个配置文件centos7.6-1 .xml
[root@localhost ~]# ll /etc/libvirt/qemu/autostart/centos7.6-1.xml


4.网络配置文件XML

[root@localhost ~]# ls /etc/libvirt/qemu/networks/
[root@localhost ~]# ls /etc/libvirt/qemu/networks/autostart/


5.存储池配置文件XML

存储池用来存虚拟机的磁盘镜像
[root@localhost ~]# ls /etc/libvirt/storage/
[root@localhost ~]# ls /etc/libvirt/storage/autostart/


6.镜像文件(磁盘文件)

虚拟机磁盘文件,这个路径不同于之前的路径
[root@localhost ~]# ls /var/lib/libvirt/images
centos7.6-1.qcow2


【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。