virsh命令详解 网络_virsh是什么[通俗易懂]

virsh命令详解 网络_virsh是什么[通俗易懂]virsh虚拟机管理_virsh

virsh命令详解

virsh 命令:

  • list [–all]:                                          列出虚拟机
  • nodeinfo:                                             查看真机信息
  • nodeinfo:                                             得到电脑详细配置名字
  • nodecpustats:                                     真机cpu 的状态
  • nodemenstats:                                    真机内存的详细信息
  • node-memory-tune:                            允许你设置node的内存参数
  • capablilities:                                        打印虚拟机的特点
  • freecell:                                               打印出虚拟I机中可用的内存

命令演示:

[root@desktop ~]# virsh list # 列出所有运行的虚拟机
 Id    Name                           State
----------------------------------------------------
 1     proxy                          running
 4     web1                           running
 5     web2                           running
 13    cache                          running

[root@desktop ~]# virsh list --all  # 列出所有虚拟机
 Id    Name                           State
----------------------------------------------------
 1     proxy                          running
 4     web1                           running
 5     web2                           running
 13    cache                          running
 -     client                         shut off
 -     db1                            shut off
 -     db2                            shut off
 -     dns                            shut off

[root@desktop vm]# virsh hostname  # 列出真机主机名
desktop

[root@desktop vm]# virsh sysinfo   # 列出真机的详细信息
<sysinfo type='smbios'>
  <bios>
    <entry name='vendor'>HP</entry>
    <entry name='version'>Q50 Ver. 01.06.04</entry>
    <entry name='date'>02/07/2020</entry>
    <entry name='release'>6.4</entry>
  </bios>
   ...
  </memory_device>
</sysinfo>

[root@desktop vm]# virsh nodecpustats  # 得到真机cpu状态
user:                565188290000000
system:              889250070000000
idle:              22823238820000000
iowait:               10113440000000

[root@desktop vm]# virsh nodememstats   # 得到真机内存状态
total  :              7778448 KiB
free   :               469008 KiB
buffers:                  136 KiB
cached :               357196 KiB

[root@desktop vm]# virsh node-memory-tune  # 允许你设置的node内存参数
Shared memory:
        shm_pages_to_scan 1250
        shm_sleep_millisecs 21
        shm_pages_shared 28710
        shm_pages_sharing 133337
        shm_pages_unshared 140701
        shm_pages_volatile 1451
        shm_full_scans  92316
        shm_merge_across_nodes 1

[root@desktop vm]# virsh capabilities  # 打印虚拟机的特点
<capabilities>

  <host>
    <uuid>39f13a7f-d328-0fb6-3508-5f1fea3d5774</uuid>
    <cpu>
      <arch>x86_64</arch>
      <model>Skylake-Client-IBRS</model>
      <vendor>Intel</vendor>
    ...
</capabilities>
[root@desktop vm]# virsh freecell  # 打印虚拟机中可用内存
Total: 192656 KiB

virsh DOMAIN命令:

  • start|shutdown|reboot <vm-name>:    虚拟机启动、停止、重启
  • destroy <vm-name>:                           强制停止虚拟机
  • define <vm-name>.xml:                      根据xml文件创建
  • undefine <vm-name>:                         根据虚拟机名称删除虚拟机
  • console <vm-name>:                           连接虚拟机的console
  • edit <vm-name> :                                修改虚拟机配置
  • autostart <vm-name>:                         设置虚拟机自启动
  • domiflist <vm-name>:                          查看虚拟机网卡信息
  • domblklist <vm-name>:                        查看虚拟机硬盘信息
  • dominfo <vm-name>:                           列出指定虚拟机的信息
  • suspend <vm-name>:                           挂起指定虚拟机
  • resume <vm-name>:                          恢复挂起的虚拟机
[root@desktop ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     proxy                          running
 4     web1                           running
 5     web2                           running
 16    cache                          running
 18    dns                            running
 -     client                         shut off
 -     db1                            shut off
 -     db2                            shut off

[root@desktop ~]# virsh shutdown dns # 关闭虚拟机dns
Domain dns is being shutdown

[root@desktop ~]# virsh start dns    # 启动虚拟机dns
Domain dns started

[root@desktop vm]# virsh dumpxml dns > dns.xml   # 导出dns虚拟机的配置文件
[root@desktop vm]# ls
dns.xml
[root@desktop vm]# virsh undefine dns            # 删除dns虚拟机
Domain dns has been undefined

[root@desktop vm]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     proxy                          running
 4     web1                           running
 5     web2                           running
 16    cache                          running
 -     client                         shut off
 -     db1                            shut off
 -     db2                            shut off

[root@desktop vm]# virsh define dns.xml           # 从xml配置文件生成一个虚拟机
Domain dns defined from dns.xml

[root@desktop vm]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     proxy                          running
 4     web1                           running
 5     web2                           running
 16    cache                          running
 -     client                         shut off
 -     db1                            shut off
 -     db2                            shut off
 -     dns                            shut off

[root@desktop vm]# virsh start dns
Domain dns started

[root@desktop vm]# virsh reboot dns               # 重启虚拟机dns
Domain dns is being rebooted

[root@desktop vm]# virsh autostart dns            # 设置虚拟机dns开机自启
Domain dns marked as autostarted

[root@desktop vm]# virsh autostart --disable dns  # 取消虚拟机dns开机自启
Domain dns unmarked as autostarted

[root@desktop vm]# virsh domiflist dns            # 显示虚拟机网卡接口
Interface  Type       Source     Model       MAC
-------------------------------------------------------

[root@desktop vm]# virsh domblklist dns            # 显示虚拟机磁盘文件
Target     Source
------------------------------------------------
vda        /opt/vm/dns.qcow2

[root@desktop vm]# virsh dominfo dns               # 显示虚拟机的信息
Id:             20
Name:           dns
UUID:           b8024ffe-9c00-4570-a802-72a94e6576ca
OS Type:        hvm
State:          running
CPU(s):         1
CPU time:       22.1s
Max memory:     2097152 KiB
Used memory:    2097152 KiB
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: selinux
Security DOI:   0
Security label: system_u:system_r:svirt_t:s0:c502,c596 (enforcing)

[root@desktop vm]# virsh suspend dns               # 挂起虚拟机
Domain dns suspended

[root@desktop vm]# virsh list
 Id    Name                           State
----------------------------------------------------
 1     proxy                          running
 4     web1                           running
 5     web2                           running
 16    cache                          running
 20    dns                            paused

[root@desktop vm]# virsh resume dns                # 继续运行挂起的虚拟机
Domain dns resumed

[root@desktop vm]# virsh desc dns                  # 显示虚拟机的描述信息
No description for domain: dns
 

  • domjobabort <vm-name>:                        获取虚拟机的当前任务
  • dojobinfo <vm-name>:                             显示虚拟机的任务
  • domstat <vm-name> :                              显示虚拟机的状态
  • domcontrol<vm-name>:                           返回虚拟机的状态ok or error
  • dumpxml<vm-name>:                               直接显示demo的xml文件配置
  • edit <vm-name>:                                      编辑主机的配置文件
  • cpu-stats <vm-name>:                             虚拟机的cpu状态
[root@desktop vm]# virsh domjobabort dns
error: Requested operation is not valid: no job is active on the domain

[root@desktop vm]# virsh domjobinfo dns
Job type:         None

[root@desktop vm]# virsh domstats dns
Domain: 'dns'
  state.state=1
  state.reason=5
  cpu.time=33212300555
  cpu.user=900000000
  cpu.system=4380000000
  balloon.current=2097152
  balloon.maximum=2097152
  balloon.swap_in=0
  balloon.swap_out=0
  balloon.major_fault=189
  balloon.minor_fault=161771
  balloon.unused=1879292
  balloon.available=2046976
  balloon.last-update=1647332025
  balloon.rss=492880
  vcpu.current=1
  vcpu.maximum=1
  vcpu.0.state=1
  vcpu.0.time=23010000000
  vcpu.0.wait=0
  net.count=0
  block.count=1
  block.0.name=vda
  block.0.path=/opt/vm/dns.qcow2
  block.0.rd.reqs=10188
  block.0.rd.bytes=281963008
  block.0.rd.times=1698863549
  block.0.wr.reqs=237
  block.0.wr.bytes=10442240
  block.0.wr.times=574631962
  block.0.fl.reqs=68
  block.0.fl.times=195155558
  block.0.allocation=31348801024
  block.0.capacity=42949672960
  block.0.physical=3388030976

[root@desktop vm]# virsh domcontrol dns
ok

[root@desktop vm]# virsh cpu-stats dns
CPU0:
        cpu_time             1.840709161 seconds
        vcpu_time            0.571028679 seconds
CPU1:
        cpu_time             2.275045726 seconds
        vcpu_time            0.665116430 seconds
CPU2:
        cpu_time             6.915661248 seconds
        vcpu_time            5.527787781 seconds
CPU3:
        cpu_time             3.793130275 seconds
        vcpu_time            2.515854323 seconds
CPU4:
        cpu_time             2.442409053 seconds
        vcpu_time            1.154978564 seconds
CPU5:
        cpu_time             4.330489085 seconds
        vcpu_time            3.044157700 seconds
CPU6:
        cpu_time             1.997121055 seconds
        vcpu_time            0.439759919 seconds
CPU7:
        cpu_time            10.725541636 seconds
        vcpu_time            9.225345458 seconds
Total:
        cpu_time            34.320107239 seconds
        user_time            0.900000000 seconds
        system_time          4.400000000 seconds
  • screenshot <vm-name>:                                  虚拟机截屏
  • setmen <vm-name> size:                                设置虚拟机的内存
  • setmaxmen <vm-name>                                  设置虚拟机的最大内存
  • memtune     <vm-name>                                 得到虚拟机分区的信息
  • blkiotune      <vm-name>                                 得到虚拟机的磁盘信息
  • setvcpus(<vm-name> count)                      设置虚拟机的虚拟cpu个数
  • dompmwakeup(<vm-name>)                           唤醒挂起的vm-name
  • ttyconsole <vm-name>                                    输出设备用的终端
  • vcpucount <vm-name>                                    得到cpu个数
  • vcpuinfo<vm-name>                                        得到cpu的信息
  • vncdisplay<vm-name>                                     显示虚拟机vnc连接信息
[root@desktop ~]# virsh memtune dns   # 得到虚拟机分区的信息
hard_limit     : unlimited
soft_limit     : unlimited
swap_hard_limit: unlimited

[root@desktop ~]# virsh blkiotune dns  # 得到虚拟机的磁盘信息
weight         : 500
device_weight  :
device_read_iops_sec:
device_write_iops_sec:
device_read_bytes_sec:
device_write_bytes_sec:

[root@desktop ~]# virsh ttyconsole dns   # 输出设备用的终端
/dev/pts/13

[root@desktop ~]# virsh vcpucount dns    # 获取虚拟机cpu数目
maximum      config         1
maximum      live           1
current      config         1
current      live           1

[root@desktop ~]# virsh vcpuinfo dns     # Huoqu虚拟机CPU信息
VCPU:           0
CPU:            1
State:          running
CPU time:       27.0s
CPU Affinity:   yyyyyyyy

[root@desktop ~]# virsh vncdisplay dns   #  显示虚拟机vnc连接信息
:4

[root@desktop ~]# virsh dumpxml proxy | grep mac  # 宿主机上获取虚拟机proxy的IP地址
    <partition>/machine</partition>
    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
      <mac address='52:54:00:47:14:ea'/>
      <mac address='52:54:00:85:73:e9'/>
[root@desktop ~]#
[root@desktop ~]#
[root@desktop ~]# arp -a | grep '52:54:00:47:14:ea'
? (192.168.3.3) at 52:54:00:47:14:ea [ether] on br5

virsh 虚拟网络管理:

  • net-autostart     <networkname>           自动启动网卡(default) 
  • net-define <file>                                    把配置加载到文件 
  • net-destory <networkname>                 关闭网卡 
  • net-dumpxml <networkname>               把网卡配置加载到文件 
  • net-edit <networkname>                       编辑网卡信息 
  • net-info  <networkname>                      网卡信息 
  • net-list                                                   显示网卡 
  • net-uuid <networkname>                      得到网卡的id 
  • net-name  <id>                                     得到网卡的名字 
  • net-start <networkname>                      开启网卡
[root@desktop vm]# virsh net-list --all     # 显示所有虚拟网络
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 default              active     yes           yes
 lab                  active     yes           yes
 office               active     yes           yes

[root@desktop vm]# virsh net-define lab2.xml  # 从配置文件生成一个虚拟网络
Network lab2 defined from lab2.xml

[root@desktop vm]# virsh net-list --all
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 default              active     yes           yes
 lab                  active     yes           yes
 lab2                 inactive   no            yes
 office               active     yes           yes

[root@desktop vm]# virsh net-dumpxml lab > lab.xml   # 把虚拟网络配置保存到文件
[root@desktop vm]# virsh net-info lab
Name:           lab
UUID:           ed7ac3a2-da2b-4511-bdcc-e385d029dbd9
Active:         yes
Persistent:     yes
Autostart:      yes
Bridge:         virbr2

[root@desktop vm]# virsh net-uuid lab    #  得到虚拟的uuid
ed7ac3a2-da2b-4511-bdcc-e385d029dbd9

[root@desktop vm]# virsh net-start lab2  # 启动虚拟网络
Network lab2 started

[root@desktop vm]# virsh net-list --all
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 default              active     yes           yes
 lab                  active     yes           yes
 lab2                 active     no            yes
 office               active     yes           yes

[root@desktop vm]# virsh net-destroy lab2   ¥ 停止指定的虚拟网络
Network lab2 destroyed

[root@desktop vm]# virsh net-list --all
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 default              active     yes           yes
 lab                  active     yes           yes
 lab2                 inactive   no            yes
 office               active     yes           yes

[root@desktop vm]# virsh net-undefine lab2  # 删除指定的虚拟网络
Network lab2 has been undefined

[root@desktop vm]# virsh net-list --all
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 default              active     yes           yes
 lab                  active     yes           yes
 office               active     yes           yes

设备命令:

  • attach-device (<vm-name> file)                        使用XML文件中设备定义在虚拟机中添加设备
  • attach-disk (<vm-name>  )                               添加磁盘文件
  • attach-interface (<vm-name> type source )      添加一个接口 
  • update-device (<vm-name> file)                       更新设备根据file
[root@desktop vm]# qemu-img create -f qcow2 test1.qcow2 1g # 创建一个1G磁盘的磁盘文件
Formatting 'test1.qcow2', fmt=qcow2 size=1073741824 encryption=off cluster_size=65536 lazy_refcounts=off
[root@desktop vm]# qemu-img create -f qcow2 test2.qcow2 1g #  # 创建一个1G磁盘的磁盘文件
Formatting 'test2.qcow2', fmt=qcow2 size=1073741824 encryption=off cluster_size=65536 lazy_refcounts=off

[root@desktop vm]# ls
dns.xml  installdisk.xml  lab2.xml  lab.xml  test1.qcow2  test2.qcow2

[root@desktop vm]# cat installdisk.xml  # 编辑一个xml文件
<disk type='file' device='disk'>
  <driver name='qemu' type='qcow2' cache='none'/>
  <source file='/root/vm/test1.qcow2'/>
  <target dev='vdb'/>
</disk>

[root@desktop ~]# virsh domblklist dns  # 查看虚拟机的磁盘文件
Target     Source
------------------------------------------------
vda        /opt/vm/dns.qcow2

[root@desktop vm]# virsh attach-device --domain dns installdisk.xml  # 使用XML文件中的设备定义在虚拟机中添加设备
Device attached successfully

[root@desktop vm]# virsh domblklist dns
Target     Source
------------------------------------------------
vda        /opt/vm/dns.qcow2
vdb        /root/vm/test1.qcow2

[root@desktop vm]# virsh attach-disk --domain dns --source /root/vm/test2.qcow2 --target vdc  --subdriver qcow2 --config --live  # 虚拟机添加磁盘文件
Disk attached successfully

[root@desktop vm]# virsh domblklist dns
Target     Source
------------------------------------------------
vda        /opt/vm/dns.qcow2
vdb        /root/vm/test1.qcow2
vdc        /root/vm/test2.qcow2

[root@desktop vm]# virsh detach-disk dns vdc  # 从虚拟机删除磁盘
Disk detached successfully

[root@desktop vm]# virsh detach-disk dns vdb
Disk detached successfully

[root@desktop vm]# virsh domblklist dns
Target     Source
------------------------------------------------
vda        /opt/vm/dns.qcow2

[root@desktop vm]# virsh domiflist dns
Interface  Type       Source     Model       MAC
-------------------------------------------------------

[root@desktop vm]# virsh attach-interface dns --type network --source default --model virtio  # 添加网卡,连接虚拟网络
Interface attached successfully

[root@desktop vm]# virsh domiflist dns
Interface  Type       Source     Model       MAC
-------------------------------------------------------
vnet5      network    default    virtio      52:54:00:4d:69:d7

接口命令:

  • iface-define(file)                         从文件里面定义一个接口 
  • iface-dumpxml (lo)                     显示接口的信息 
  • iface-edit(lo)                              编辑接口 
  • iface-list                                         列出所有的接口 
  • iface-name (mac)                      根据mac得到名字 
  • iface-mac     (lo)                             根据名字得到mac 
  • iface-start  (lo)                           开启接口 
  • iface-unbriged                                解绑定网桥 
  • iface-undefine(lo)                      不定义配置文件 
  • iface-begin(lo)                           创建一个现有的接口设置 
  • iface-commit                                  提交所有的改变有效,并且让接口工作 
  • iface-rollbak                                   接口回滚
[root@desktop vm]# virsh iface-list --all      # 列出所有网卡 Name                 State      MAC Address--------------------------------------------------- br5                  active     00:0e:c6:82:4c:a0 eno1                 active     84:a9:3e:82:23:37 enp1s0f0             inactive   6c:b3:11:40:f1:46 enp1s0f1             inactive   6c:b3:11:40:f1:47 lo                   active     00:00:00:00:00:00[root@desktop vm]# virsh iface-dumpxml eno1   # 输出指定网卡信息<interface type='ethernet' name='eno1'>  <protocol family='ipv4'>    <ip address='192.168.50.228' prefix='24'/>  </protocol>  <protocol family='ipv6'>    <ip address='fe80::5669:5b18:2f36:2137' prefix='64'/>  </protocol>  <link speed='1000' state='up'/>  <mac address='84:a9:3e:82:23:37'/></interface>[root@desktop vm]# virsh iface-mac eno1       # 根据网卡名获取MAC地址84:a9:3e:82:23:37[root@desktop vm]# virsh iface-name 84:a9:3e:82:23:37  # 根据MAC地址获取网卡名eno1

存储池命令:

  • pool-auto (pool)                 标记池自动启动 
  • pool-build(pool)                  建造一个池 
  • pool-create(file)                 根据文件创建池 
  • pool-define(file)                 定义但是不开启 
  • pool-destory(pool)             销毁池,以后能恢复
  • pool-delete(pool)               删除池,以后不能恢复 
  • pool-dumpxml(pool)          查看池的定义文件 
  • pool-edit(pool)                  编辑池的定义文件 
  • pool-info                               池的信息 
  • pool-list                                 显示池列表 
  • pool-name(id)                   根据id得到name 
  • pool-start(poop)                开启池 
  • pool-uuid (pool)                返回一个池的uuid
[root@desktop vm]# virsh pool-list --all  # 列出所有池
 Name                 State      Autostart
-------------------------------------------
 bl02u2_test          active     yes
 default              active     yes
 Downloads            active     yes
 images               active     yes
 images-1             active     yes
 opt                  active     yes
 root                 active     yes
 vm                   active     yes

[root@desktop vm]# virsh pool-info vm   # 列出池vm的信息
Name:           vm
UUID:           6820e7d5-3210-496e-8573-5a19907b034e
State:          running
Persistent:     yes
Autostart:      yes
Capacity:       325.81 GiB
Allocation:     90.34 GiB
Available:      235.46 GiB

[root@desktop vm]# virsh pool-uuid vm  # 获取池vm的uuid
6820e7d5-3210-496e-8573-5a19907b034e

[root@desktop vm]# virsh pool-dumpxml vm  # 查看池的定义文件
<pool type='dir'>
  <name>vm</name>
  <uuid>6820e7d5-3210-496e-8573-5a19907b034e</uuid>
  <capacity unit='bytes'>349831188480</capacity>
  <allocation unit='bytes'>97005137920</allocation>
  <available unit='bytes'>252826050560</available>
  <source>
  </source>
  <target>
    <path>/opt/vm</path>
    <permissions>
      <mode>0755</mode>
      <owner>0</owner>
      <group>0</group>
      <label>unconfined_u:object_r:usr_t:s0</label>
    </permissions>
  </target>
</pool>

[root@desktop vm]# virsh pool-dumpxml images-1 > images-1.xml # 将池信息保存到xml文件中
[root@desktop vm]# virsh pool-destroy images-1                # 停止一个池
Pool images-1 destroyed
[root@desktop vm]# virsh pool-list --all
 Name                 State      Autostart
-------------------------------------------
 bl02u2_test          active     yes
 default              active     yes
 Downloads            active     yes
 images               active     yes
 images-1             inactive   yes
 opt                  active     yes
 root                 active     yes
 vm                   active     yes

[root@desktop vm]# virsh pool-delete images-1  # 删除一个池
Pool images-1 deleted

[root@desktop vm]# virsh pool-define images-1.xml  # 从定义文件生成一个池
Pool images-1 defined from images-1.xml

[root@desktop vm]# virsh pool-start images-1   # 启动一个池
Pool images-1 started

[root@desktop vm]# virsh pool-list
 Name                 State      Autostart
-------------------------------------------
 bl02u2_test          active     yes
 default              active     yes
 Downloads            active     yes
 images               active     yes
 images-1             active     no
 opt                  active     yes
 root                 active     yes
 vm                   active     yes

[root@desktop vm]# virsh pool-autostart  images-1   # 标记指定池自动启动
Pool images-1 marked as autostarted

[root@desktop vm]# virsh pool-list
 Name                 State      Autostart
-------------------------------------------
 bl02u2_test          active     yes
 default              active     yes
 Downloads            active     yes
 images               active     yes
 images-1             active     yes
 opt                  active     yes
 root                 active     yes
 vm                   active     yes

卷命令:

  • vol-delete(pool)               卷的删除 
  • vol-upload(pool)              卷的加载 
  • vol-list(pool)                    列出卷 
  • vol-info(default)              卷的信息 
  • vol-name(path)               得到卷的名字
[root@desktop vm]# virsh vol-list vm   # 查看指定池中的卷
 Name                 Path
------------------------------------------------------------------------------
 @1@p                 /opt/vm/@1@p
 cache.qcow2          /opt/vm/cache.qcow2
 centos2.raw          /opt/vm/centos2.raw
 client.qcow2         /opt/vm/client.qcow2
 db1.qcow2            /opt/vm/db1.qcow2
 db2.qcow2            /opt/vm/db2.qcow2
 disk1.qcow2          /opt/vm/disk1.qcow2
 disk2.qcow2          /opt/vm/disk2.qcow2
 disk3.qcow2          /opt/vm/disk3.qcow2
 disk4.qcow2          /opt/vm/disk4.qcow2
 disk5.qcow2          /opt/vm/disk5.qcow2
 disk6.qcow2          /opt/vm/disk6.qcow2
 disk7.qcow2          /opt/vm/disk7.qcow2
 disk8.qcow2          /opt/vm/disk8.qcow2
 dns.qcow2            /opt/vm/dns.qcow2
 dsik9.qcow2          /opt/vm/dsik9.qcow2
 nfs.qcow2            /opt/vm/nfs.qcow2
 proxy.qcow2          /opt/vm/proxy.qcow2
 Server.qcow2         /opt/vm/Server.qcow2
 test1.qcow2          /opt/vm/test1.qcow2
 test2.qcow2          /opt/vm/test2.qcow2
 upload.txt           /opt/vm/upload.txt
 web01.qcow2          /opt/vm/web01.qcow2
 web02.qcow2          /opt/vm/web02.qcow2
 web03.qcow2          /opt/vm/web03.qcow2
 web04.qcow2          /opt/vm/web04.qcow2
 web1.qcow2           /opt/vm/web1.qcow2
 web2.qcow2           /opt/vm/web2.qcow2

[root@desktop vm]# virsh vol-info test1.qcow2 vm  # 查看存储池vm中的卷test1.qcow的信息
Name:           test1.qcow2
Type:           file
Capacity:       1.00 GiB
Allocation:     196.00 KiB

[root@desktop vm]# virsh vol-clone test1.qcow2 test1back.qcow2 vm # 在存储池中克隆卷test1.qcow2为卷test1back.qcow2

Vol test1back.qcow2 cloned from test1.qcow2

[root@desktop vm]# virsh vol-delete test1back.qcow2 vm  # 删除存储池中卷test1back.qcow2
Vol test1back.qcow2 deleted

[root@desktop vm]# virsh vol-dumpxml test1.qcow2 vm > test1.xml # 保存存储池中存储卷test1.qcow2的配置到test1.xml
[root@desktop vm]# virsh vol-delete test1.qcow2 vm
Vol test1.qcow2 deleted

[root@desktop vm]# virsh vol-create vm test1.xml  # 用配置文件test1.xml在存储池中生成一个卷
Vol test1.qcow2 created from test1.xml

快照管理:

  •   snapshot-create                                 使用 XML 生成快照
  •   snapshot-create-as                            使用一组参数生成快照
  •   snapshot-current                                获取或者设定当前快照
  •   snapshot-delete                                  删除域快照
  •   snapshot-dumpxml                             为域快照转储 XML
  •   snapshot-edit                                      编辑快照 XML
  •   snapshot-info                                     快照信息
  •   snapshot-list                                      为域列出快照
  •   snapshot-parent                                 获取快照的上级快照名称
  •   snapshot-revert                                  从快照恢复
[root@desktop ~]# virsh snapshot-list dns   # 列出虚拟机dns的快照
 Name                 Creation Time             State
------------------------------------------------------------

[root@desktop ~]# virsh snapshot-create-as --name dns-v1 --domain dns  # 为虚拟机生成快照dns-v1
Domain snapshot dns-v1 created
[root@desktop ~]# virsh snapshot-list dns
 Name                 Creation Time             State
------------------------------------------------------------
 dns-v1               2022-03-16 09:52:22 +0800 running

[root@desktop ~]# virsh snapshot-revert --domain dns --snapshotname dns-v1  # 从快照恢复

[root@desktop ~]# virsh snapshot-current --domain dns  # 获取当前快照
<domainsnapshot>
  <name>dns-v1</name>
  <state>running</state>
  <creationTime>1647395542</creationTime>
  <memory snapshot='internal'/>
  <disks>
    <disk name='vda' snapshot='internal'/>
  </disks>
...
</domainsnapshot>

[root@desktop ~]# virsh snapshot-info --domain dns --snapshotname dns-v1  # 输出指定的快照信息
Name:           dns-v1
Domain:         dns
Current:        yes
State:          running
Location:       internal
Parent:         -
Children:       0
Descendants:    0
Metadata:       yes

[root@desktop ~]# virsh snapshot-delete --domain dns --snapshotname dns-v1 # 删除快照
Domain snapshot dns-v1 deleted

[root@desktop ~]# virsh snapshot-list dns
 Name                 Creation Time             State
------------------------------------------------------------

今天的文章virsh命令详解 网络_virsh是什么[通俗易懂]分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/78620.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注