大家好,今天分享centos7部署kvm

首先,我们要了解一下kvm

KVM 自 Linux 2.6.20 版本后就直接整合到 Linux 内核,它依托 CPU 虚拟化指令集(如

Intel-VT、AMD-V)实现高性能的虚拟化支持。由于与 Linux 内核高度整合,因此在性能、

安全性、兼容性、稳定性上都有很好的表现。

这是它的结构图

在这里插入图片描述
也许这个图不太好懂,我简而言之

在我们宿主机上按了一个VMware 虚拟机, 在VMware虚拟机上安装了centos7系统,在centos7上安装kvm虚拟化的软件
就是这个样子

我们来演示一下

  1. 关闭虚拟机
    在这里插入图片描述

打开相关选项

在这里插入图片描述

打开虚拟机centos7

连接xshell

在这里插入图片描述
测试网络,现在就是没问题的,因为我们要使用网络

[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (180.101.49.11) 56(84) bytes of data.
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=1 ttl=128 time=11.6 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=2 ttl=128 time=11.1 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=3 ttl=128 time=9.69 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=4 ttl=128 time=10.3 ms

安装 GNOME 桌面环境

[root@localhost ~]# yum groupinstall -y "GNOME Desktop"    //安装 GNOME 桌面环境

安装KVM 模块

[root@localhost ~]# yum -y install qemu-kvm   //安装KVM 模块

安装KVM 调试工具

[root@localhost ~]# yum -y install qemu-kvm-tools

构建虚拟机的命令行工具

[root@localhost ~]# yum -y install virt-install

qemu 组件,创建磁盘、启动虚拟机等

yum -y install qemu-img    //默认已经有了

yum -y install bridge-utils     //  网络支持工具,默认已经有了
yum -y install libvirt      //安装虚拟机管理工具
yum -y install virt-manager

输入这条命令,只要有输出,就是支持虚拟化

[root@localhost ~]# cat /proc/cpuinfo | grep vmx

flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec ibpb ibrs stibp arat spec_ctrl intel_stibp arch_capabilities

检查 KVM 模块是否安装:

[root@localhost ~]# lsmod | grep kvm
kvm_intel             174841  0 
kvm                   578518  1 kvm_intel
irqbypass              13503  1 kvm

将 系 统 的 默 认 运 行 target 更 改 为
graphical.targe。

[root@localhost ~]# ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target

开启 libvirtd 服务,以开启相关支持。

[root@localhost ~]# systemctl start libvirtd
[root@localhost ~]# systemctl enable libvirtd
[root@localhost ~]# virt-manager

在这里插入图片描述
http://mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-Minimal-2009.iso

进入这个目录

[root@localhost images]# pwd
/var/lib/libvirt/images

在这个目录当中上传一个centos7镜像,这个比较小

[root@localhost images]# ll
总用量 996352
-rw-r--r--. 1 root root 1020264448 624 16:52 CentOS-7-x86_64-Minimal-2009.iso
[root@localhost images]# 

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

然后,点击“开始安装”
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

重启就可以了

在这里插入图片描述

我们已经进入到字符界面了

在这里插入图片描述

使用管理员用户登录

在这里插入图片描述

发现迷你版的镜像没有ifcofig命令
在这里插入图片描述

yum -y install net-tools

在这里插入图片描述

在这里插入图片描述
[root@localhost ~]# virsh -h //查看命令帮助

virsh [options]... [<command_string>]
virsh [options]... <command> [args...]

  options:
    -c | --connect=URI      hypervisor connection URI
    -d | --debug=NUM        debug level [0-4]
    -e | --escape <char>    set escape sequence for console
    -h | --help             this help
    -k | --keepalive-interval=NUM
                            keepalive interval in seconds, 0 for disable
    -K | --keepalive-count=NUM
                            number of possible missed keepalive messages
    -l | --log=FILE         output logging to file
    -q | --quiet            quiet mode
    -r | --readonly         connect readonly
    -t | --timing           print timing information
    -v                      short version
    -V                      long version
         --version[=TYPE]   version, TYPE is short or long (default short)
  commands (non interactive mode):

 Domain Management (help keyword 'domain')
    attach-device                  从一个XML文件附加装置
    attach-disk                    附加磁盘设备
    attach-interface               获得网络界面
    autostart                      自动开始一个域
    blkdeviotune                   设定或者查询块设备 I/O 调节参数。
    blkiotune                      获取或者数值 blkio 参数
    blockcommit                    启动块提交操作。
    blockcopy                      启动块复制操作。
    blockjob                       管理活跃块操作
    blockpull                      使用其后端映像填充磁盘。
    blockresize                    创新定义域块设备大小
    change-media                   更改 CD 介质或者软盘驱动器
    console                        连接到客户会话
    cpu-stats                      显示域 cpu 统计数据
    create                         从一个 XML 文件创建一个域
    define                         从一个 XML 文件定义(但不开始)一个域
    desc                           显示或者设定域描述或者标题
    destroy                        销毁(停止)域
    detach-device                  从一个 XML 文件分离设备
    detach-device-alias            detach device from an alias
    detach-disk                    分离磁盘设备
    detach-interface               分离网络界面
    domdisplay                     域显示连接 URI
    domfsfreeze                    Freeze domain's mounted filesystems.
    domfsthaw                      Thaw domain's mounted filesystems.
    domfsinfo                      Get information of domain's mounted filesystems.
    domfstrim                      在域挂载的文件系统中调用 fstrim。
    domhostname                    输出域主机名
    domid                          把一个域名或 UUID 转换为域 id
    domif-setlink                  设定虚拟接口的链接状态
    domiftune                      获取/设定虚拟接口参数
    domjobabort                    忽略活跃域任务
    domjobinfo                     域任务信息
    domname                        将域 id 或 UUID 转换为域名
    domrename                      rename a domain
    dompmsuspend                   使用电源管理功能挂起域
    dompmwakeup                    从 pmsuspended 状态唤醒域
    domuuid                        把一个域名或 id 转换为域 UUID
    domxml-from-native             将原始配置转换为域 XML
    domxml-to-native               将域 XML 转换为原始配置
    dump                           把一个域的内核 dump 到一个文件中以方便分析
    dumpxml                        XML 中的域信息
    edit                           编辑某个域的 XML 配置
    event                          Domain Events
    inject-nmi                     在虚拟机中输入 NMI
    iothreadinfo                   view domain IOThreads
    iothreadpin                    control domain IOThread affinity
    iothreadadd                    add an IOThread to the guest domain
    iothreaddel                    delete an IOThread from the guest domain
    send-key                       向虚拟机发送序列号
    send-process-signal            向进程发送信号
    lxc-enter-namespace            LXC 虚拟机进入名称空间
    managedsave                    管理域状态的保存
    managedsave-remove             删除域的管理保存
    managedsave-edit               edit XML for a domain's managed save state file
    managedsave-dumpxml            Domain information of managed save state file in XML
    managedsave-define             redefine the XML for a domain's managed save state file
    memtune                        获取或者数值内存参数
    perf                           Get or set perf event
    metadata                       show or set domain's custom XML metadata
    migrate                        将域迁移到另一个主机中
    migrate-setmaxdowntime         设定最大可耐受故障时间
    migrate-getmaxdowntime         get maximum tolerable downtime
    migrate-compcache              获取/设定压缩缓存大小
    migrate-setspeed               设定迁移带宽的最大值
    migrate-getspeed               获取最长迁移带宽
    migrate-postcopy               Switch running migration from pre-copy to post-copy
    numatune                       获取或者数值 numa 参数
    qemu-attach                    QEMU 附加
    qemu-monitor-command           QEMU 监控程序命令
    qemu-monitor-event             QEMU Monitor Events
    qemu-agent-command             QEMU 虚拟机代理命令
    reboot                         重新启动一个域
    reset                          重新设定域
    restore                        从一个存在一个文件中的状态恢复一个域
    resume                         重新恢复一个域
    save                           把一个域的状态保存到一个文件
    save-image-define              为域的保存状态文件重新定义 XML
    save-image-dumpxml             在 XML 中保存状态域信息
    save-image-edit                为域保存状态文件编辑 XML
    schedinfo                      显示/设置日程安排变量
    screenshot                     提取当前域控制台快照并保存到文件中
    set-lifecycle-action           change lifecycle actions
    set-user-password              set the user password inside the domain
    setmaxmem                      改变最大内存限制值
    setmem                         改变内存的分配
    setvcpus                       改变虚拟 CPU 的号
    shutdown                       关闭一个域
    start                          开始一个(以前定义的)非活跃的域
    suspend                        挂起一个域
    ttyconsole                     tty 控制台
    undefine                       取消定义一个域
    update-device                  从 XML 文件中关系设备
    vcpucount                      域 vcpu 计数
    vcpuinfo                       详细的域 vcpu 信息
    vcpupin                        控制或者查询域 vcpu 亲和性
    emulatorpin                    控制火车查询域模拟器亲和性
    vncdisplay                     vnc 显示
    guestvcpus                     query or modify state of vcpu in the guest (via agent)
    setvcpu                        attach/detach vcpu or groups of threads
    domblkthreshold                set the threshold for block-threshold event for a given block device or it's backing chain element

 Domain Monitoring (help keyword 'monitor')
    domblkerror                    在块设备中显示错误
    domblkinfo                     域块设备大小信息
    domblklist                     列出所有域块
    domblkstat                     获得域设备块状态
    domcontrol                     域控制接口状态
    domif-getlink                  获取虚拟接口链接状态
    domifaddr                      Get network interfaces' addresses for a running domain
    domiflist                      列出所有域虚拟接口
    domifstat                      获得域网络接口状态
    dominfo                        域信息
    dommemstat                     获取域的内存统计
    domstate                       域状态
    domstats                       get statistics about one or multiple domains
    domtime                        domain time
    list                           列出域

 Host and Hypervisor (help keyword 'host')
    allocpages                     Manipulate pages pool size
    capabilities                   性能
    cpu-baseline                   计算基线 CPU
    cpu-compare                    使用 XML 文件中描述的 CPU 与主机 CPU 进行对比
    cpu-models                     CPU models
    domcapabilities                domain capabilities
    freecell                       NUMA可用内存
    freepages                      NUMA free pages
    hostname                       打印管理程序主机名
    hypervisor-cpu-baseline        compute baseline CPU usable by a specific hypervisor
    hypervisor-cpu-compare         compare a CPU with the CPU created by a hypervisor on the host
    maxvcpus                       连接 vcpu 最大值
    node-memory-tune               获取或者设定节点内存参数
    nodecpumap                     节点 cpu 映射
    nodecpustats                   输出节点的 cpu 状统计数据。
    nodeinfo                       节点信息
    nodememstats                   输出节点的内存状统计数据。
    nodesuspend                    在给定时间段挂起主机节点
    sysinfo                        输出 hypervisor sysinfo
    uri                            打印管理程序典型的URI
    version                        显示版本

 Interface (help keyword 'interface')
    iface-begin                    生成当前接口设置快照,可在今后用于提交 (iface-commit) 或者恢复 (iface-rollback)
    iface-bridge                   生成桥接设备并为其附加一个现有网络设备
    iface-commit                   提交 iface-begin 后的更改并释放恢复点
    iface-define                   define an inactive persistent physical host interface or modify an existing persistent one from an XML file
    iface-destroy                  删除物理主机接口(启用它请执行 "if-down")
    iface-dumpxml                  XML 中的接口信息
    iface-edit                     为物理主机界面编辑 XML 配置
    iface-list                     物理主机接口列表
    iface-mac                      将接口名称转换为接口 MAC 地址
    iface-name                     将接口 MAC 地址转换为接口名称
    iface-rollback                 恢复到之前保存的使用 iface-begin 生成的更改
    iface-start                    启动物理主机接口(启用它请执行 "if-up")
    iface-unbridge                 分离其辅助设备后取消定义桥接设备
    iface-undefine                 取消定义物理主机接口(从配置中删除)

 Network Filter (help keyword 'filter')
    nwfilter-define                使用 XML 文件定义或者更新网络过滤器
    nwfilter-dumpxml               XML 中的网络过滤器信息
    nwfilter-edit                  为网络过滤器编辑 XML 配置
    nwfilter-list                  列出网络过滤器
    nwfilter-undefine              取消定义网络过滤器
    nwfilter-binding-create        create a network filter binding from an XML file
    nwfilter-binding-delete        delete a network filter binding
    nwfilter-binding-dumpxml       XML 中的网络过滤器信息
    nwfilter-binding-list          list network filter bindings

 Networking (help keyword 'network')
    net-autostart                  自动开始网络
    net-create                     从一个 XML 文件创建一个网络
    net-define                     define an inactive persistent virtual network or modify an existing persistent one from an XML file
    net-destroy                    销毁(停止)网络
    net-dhcp-leases                print lease info for a given network
    net-dumpxml                    XML 中的网络信息
    net-edit                       为网络编辑 XML 配置
    net-event                      Network Events
    net-info                       网络信息
    net-list                       列出网络
    net-name                       把一个网络UUID 转换为网络名
    net-start                      开始一个(以前定义的)不活跃的网络
    net-undefine                   undefine a persistent network
    net-update                     更新现有网络配置的部分
    net-uuid                       把一个网络名转换为网络UUID

 Node Device (help keyword 'nodedev')
    nodedev-create                 根据节点中的 XML 文件定义生成设备
    nodedev-destroy                销毁(停止)节点中的设备
    nodedev-detach                 将节点设备与其设备驱动程序分离
    nodedev-dumpxml                XML 中的节点设备详情
    nodedev-list                   这台主机中中的枚举设备
    nodedev-reattach               重新将节点设备附加到他的设备驱动程序中
    nodedev-reset                  重置节点设备
    nodedev-event                  Node Device Events

 Secret (help keyword 'secret')
    secret-define                  定义或者修改 XML 中的 secret
    secret-dumpxml                 XML 中的 secret 属性
    secret-event                   Secret Events
    secret-get-value               secret 值输出
    secret-list                    列出 secret
    secret-set-value               设定 secret 值
    secret-undefine                取消定义 secret

 Snapshot (help keyword 'snapshot')
    snapshot-create                使用 XML 生成快照
    snapshot-create-as             使用一组参数生成快照
    snapshot-current               获取或者设定当前快照
    snapshot-delete                删除域快照
    snapshot-dumpxml               为域快照转储 XML
    snapshot-edit                  编辑快照 XML
    snapshot-info                  快照信息
    snapshot-list                  为域列出快照
    snapshot-parent                获取快照的上级快照名称
    snapshot-revert                将域转换为快照

 Storage Pool (help keyword 'pool')
    find-storage-pool-sources-as   找到潜在存储池源
    find-storage-pool-sources      发现潜在存储池源
    pool-autostart                 自动启动某个池
    pool-build                     建立池
    pool-create-as                 从一组变量中创建一个池
    pool-create                    从一个 XML 文件中创建一个池
    pool-define-as                 在一组变量中定义池
    pool-define                    define an inactive persistent storage pool or modify an existing persistent one from an XML file
    pool-delete                    删除池
    pool-destroy                   销毁(删除)池
    pool-dumpxml                   XML 中的池信息
    pool-edit                      为存储池编辑 XML 配置
    pool-info                      存储池信息
    pool-list                      列出池
    pool-name                      将池 UUID 转换为池名称
    pool-refresh                   刷新池
    pool-start                     启动一个(以前定义的)非活跃的池
    pool-undefine                  取消定义一个不活跃的池
    pool-uuid                      把一个池名称转换为池 UUID
    pool-event                     Storage Pool Events

 Storage Volume (help keyword 'volume')
    vol-clone                      克隆卷。
    vol-create-as                  从一组变量中创建卷
    vol-create                     从一个 XML 文件创建一个卷
    vol-create-from                生成卷,使用另一个卷作为输入。
    vol-delete                     删除卷
    vol-download                   将卷内容下载到文件中
    vol-dumpxml                    XML 中的卷信息
    vol-info                       存储卷信息
    vol-key                        为给定密钥或者路径返回卷密钥
    vol-list                       列出卷
    vol-name                       为给定密钥或者路径返回卷名
    vol-path                       为给定密钥或者路径返回卷路径
    vol-pool                       为给定密钥或者路径返回存储池
    vol-resize                     创新定义卷大小
    vol-upload                     将文件内容上传到卷中
    vol-wipe                       擦除卷

 Virsh itself (help keyword 'virsh')
    cd                             更改当前目录
    echo                           echo 参数
    exit                           退出这个非交互式终端
    help                           打印帮助
    pwd                            输出当前目录
    quit                           退出这个非交互式终端
    connect                        连接(重新连接)到 hypervisor


  (指定 help <group> 获取组中命令的详情)

  (使用 --help <command> 来获得这个命令的详细信息)

查看 KVM 的配置文件存放目录

[root@localhost ~]# ll /etc/libvirt/qemu/
总用量 8
-rw-------. 1 root root 4631 630 16:11 centos7.0.xml
drwx------. 3 root root   42 428 2021 networks
[root@localhost ~]# 

查看虚拟机状态

[root@localhost ~]# virsh list --all
 Id    名称                         状态
----------------------------------------------------
 4     centos7.0                      running

[root@localhost ~]# 

centos7.0 就是我们刚才安装的虚拟机

关闭虚拟机

[root@localhost ~]# virsh shutdown centos7.0 
域 centos7.0 被关闭

开启虚拟机

[root@localhost ~]# virsh start centos7.0 
域 centos7.0 已开始

强制关闭

[root@localhost ~]# virsh  destroy  centos7.0 

这个时候,我们再看一下状态:

[root@localhost ~]# virsh list --all
 Id    名称                         状态
----------------------------------------------------
 -     centos7.0                      关闭

通过配置文件启动虚拟机系统

[root@localhost ~]# virsh create /etc/libvirt/qemu/centos7.0.xml 
域 centos7.0 被创建(从 /etc/libvirt/qemu/centos7.0.xml)

看状态

[root@localhost ~]# virsh list --all
 Id    名称                         状态
----------------------------------------------------
 6     centos7.0                      running

挂起虚拟机

[root@localhost ~]# virsh  suspend centos7.0 
域 centos7.0 被挂起

看一下状态

[root@localhost ~]# virsh list --all
 Id    名称                         状态
----------------------------------------------------
 6     centos7.0                      暂停

[root@localhost ~]# 

配置虚拟机实例伴随宿主机自动启动

[root@localhost ~]# virsh autostart centos7.0 
域 centos7.0标记为自动开始

恢复虚拟机

[root@localhost ~]# virsh resume centos7.0 

导出虚拟机配置
把centos7.0 的配置放到centos7.1 里面

[root@localhost ~]# virsh dumpxml centos7.0 > /etc/libvirt/qemu/centos7.1

看现在的配置文件

[root@localhost ~]# ls /etc/libvirt/qemu/
autostart  centos7.0.xml  centos7.1  networks

删除虚拟机

[root@localhost ~]# virsh undefine centos7.0 
域 centos7.0 已经被取消定义

这是的centos7.0 的配置文件已经没有了

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

现在没有运行的虚拟机

[root@localhost ~]# virsh  list --all
 Id    名称                         状态
----------------------------------------------------

[root@localhost ~]# 

进入到配置文件目录

[root@localhost ~]# cd /etc/libvirt/qemu/

进行配置文件的重命名

[root@localhost qemu]# mv centos7.1  centos7.0

重新定义

[root@localhost qemu]# virsh define centos7.0 
定义域 centos7.0(从 centos7.0[root@localhost qemu]# 

看现在的状态

[root@localhost qemu]# virsh list  --all
 Id    名称                         状态
----------------------------------------------------
 -     centos7.0                      关闭

[root@localhost qemu]# 

修改虚拟机配置信息(用来修改系统内存大小、磁盘文件等信息)
直接通过 vim 命令修改:

[root@localhost qemu]# vim centos7.0

或者这样也可以

[root@localhost qemu]# virsh  edit  centos7.0 

相当于编辑上面的配置文件

安装一下这个东西

[root@localhost ~]# yum install  libguestfs-tools -y

var/lib/libvirt/images/: 这是我们放镜像的地方

大家在做的时候看自己的情况

查看当前磁盘格式

[root@localhost ~]# qemu-img info /var/lib/libvirt/images/centos7.0.qcow2 
image: /var/lib/libvirt/images/centos7.0.qcow2
file format: qcow2
virtual size: 5.0G (5368709120 bytes)
disk size: 5.0G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true
[root@localhost ~]# 

这个也装一下

[root@localhost ~]# yum -y install libguestfs-tools-c
[root@localhost ~]# virt-cat -a /var/lib/libvirt/images/centos7.0.qcow2 /etc/sysconfig/grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

在宿主机上查看kvm虚拟机centos7.0 的dns地址

root@localhost ~]# virt-edit -a /var/lib/libvirt/images/centos7.0.qcow2  /etc/resolv.conf 

# Generated by NetworkManager

查看虚拟机状态

[root@localhost ~]# virt-df -h centos7.0
文件系统                            大小 已用空间 可用空间 使用百分比%
centos7.0:/dev/sda1                      1014M       105M       909M   11%
centos7.0:/dev/centos/root                3.5G       1.3G       2.2G   39%
[root@localhost ~]# 

看状态

[root@localhost ~]# virsh list --all
 Id    名称                         状态
----------------------------------------------------
 -     centos7.0                      关闭

[root@localhost ~]# 

克隆一个机器

[root@localhost ~]# virt-clone -o centos7.0 -n centos7.1 -f /var/lib/libvirt/images/centos7.1.qcow2 
正在分配 'centos7.1.qcow2'                                | 5.0 GB  00:00:24     

成功克隆 'centos7.1'

再看一下状态,发现有centos7.1

[root@localhost ~]# virsh list --all
 Id    名称                         状态
----------------------------------------------------
 -     centos7.0                      关闭
 -     centos7.1                      关闭

开启这个图centos7.1

[root@localhost ~]# virsh start  centos7.1
域 centos7.1 已开始

生成快照(理解成VMware的快照)

[root@localhost ~]# virsh snapshot-create centos7.0
已生成域快照 1656584049
[root@localhost ~]# 

查看虚拟机快照的版本信息

[root@localhost ~]# virsh  snapshot-current centos7.0
<domainsnapshot>
  <name>1656584049</name>
  <state>shutoff</state>
  <creationTime>1656584049</creationTime>
  <memory snapshot='no'/>
  <disks>
    <disk name='vda' snapshot='internal'/>
    <disk name='hda' snapshot='no'/>
  </disks>
  <domain type='kvm'>
    <name>centos7.0</name>
    <uuid>8f9cd4d6-a1d1-4296-bf6e-379682af6b05</uuid>
    <memory unit='KiB'>1048576</memory>
    <currentMemory unit='KiB'>1048576</currentMemory>
    <vcpu placement='static'>1</vcpu>
    <resource>
      <partition>/machine</partition>
    </resource>
    <os>
      <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
    </os>
    <features>
      <acpi/>
      <apic/>
    </features>
    <cpu mode='custom' match='exact' check='full'>
      <model fallback='forbid'>Broadwell-IBRS</model>
      <feature policy='disable' name='md-clear'/>
      <feature policy='disable' name='ssbd'/>
      <feature policy='disable' name='hle'/>
      <feature policy='disable' name='rtm'/>
      <feature policy='require' name='spec-ctrl'/>
      <feature policy='require' name='hypervisor'/>
      <feature policy='require' name='xsaveopt'/>
    </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='qcow2'/>
        <source file='/var/lib/libvirt/images/centos7.0.qcow2'/>
        <target dev='vda' bus='virtio'/>
        <boot order='1'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
      </disk>
      <disk type='file' device='cdrom'>
        <driver name='qemu' type='raw'/>
        <target dev='hda' bus='ide'/>
        <readonly/>
        <boot order='2'/>
        <address type='drive' controller='0' bus='0' target='0' unit='0'/>
      </disk>
      <controller type='usb' index='0' model='ich9-ehci1'>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>
      </controller>
      <controller type='usb' index='0' model='ich9-uhci1'>
        <master startport='0'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0' multifunction='on'/>
      </controller>
      <controller type='usb' index='0' model='ich9-uhci2'>
        <master startport='2'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>
      </controller>
      <controller type='usb' index='0' model='ich9-uhci3'>
        <master startport='4'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>
      </controller>
      <controller type='ide' index='0'>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
      </controller>
      <controller type='virtio-serial' index='0'>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
      </controller>
      <controller type='pci' index='0' model='pci-root'/>
      <interface type='network'>
        <mac address='52:54:00:8d:e0:b0'/>
        <source network='default'/>
        <model type='virtio'/>
        <boot order='3'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
      </interface>
      <serial type='pty'>
        <target type='isa-serial' port='0'>
          <model name='isa-serial'/>
        </target>
      </serial>
      <console type='pty'>
        <target type='serial' port='0'/>
      </console>
      <channel type='unix'>
        <target type='virtio' name='org.qemu.guest_agent.0'/>
        <address type='virtio-serial' controller='0' bus='0' port='1'/>
      </channel>
      <channel type='spicevmc'>
        <target type='virtio' name='com.redhat.spice.0'/>
        <address type='virtio-serial' controller='0' bus='0' port='2'/>
      </channel>
      <input type='tablet' bus='usb'>
        <address type='usb' bus='0' port='1'/>
      </input>
      <input type='mouse' bus='ps2'/>
      <input type='keyboard' bus='ps2'/>
      <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'>
        <listen type='address' address='127.0.0.1'/>
      </graphics>
      <sound model='ich6'>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
      </sound>
      <video>
        <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
      </video>
      <redirdev bus='usb' type='spicevmc'>
        <address type='usb' bus='0' port='2'/>
      </redirdev>
      <redirdev bus='usb' type='spicevmc'>
        <address type='usb' bus='0' port='3'/>
      </redirdev>
      <memballoon model='virtio'>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
      </memballoon>
    </devices>
    <seclabel type='dynamic' model='selinux' relabel='yes'/>
    <seclabel type='dynamic' model='dac' relabel='yes'/>
  </domain>
</domainsnapshot>

查看快照时间

[root@localhost ~]# virsh snapshot-list centos7.0
 名称               生成时间              状态
------------------------------------------------------------
 1656584049           2022-06-30 18:14:09 +0800 shutoff

[root@localhost ~]# 

创建新的快照

[root@localhost ~]# virsh snapshot-create centos7.0
已生成域快照 1656584521

查看快照时间

[root@localhost ~]# virsh snapshot-list centos7.0
 名称               生成时间              状态
------------------------------------------------------------
 1656584049           2022-06-30 18:14:09 +0800 shutoff
 1656584521           2022-06-30 18:22:01 +0800 shutoff

切换原先的状态

[root@localhost ~]# virsh  snapshot-revert centos7.0 1656584049 

看信息

[root@localhost ~]# virsh  snapshot-current centos7.0
<domainsnapshot>
  <name>1656584049</name>
  <state>shutoff</state>
  <creationTime>1656584049</creationTime>
  <memory snapshot='no'/>
  <disks>
[root@localhost ~]# virsh snapshot-delete centos7.0 1656584049  
已删除域快照 1656584049

好了,有关于centos7安装部署kvm 以及kvm的基本操作就到这里了,谢谢大家

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐