4-2 KVM 虚拟机和快照

[root@xuegod1 images]# ls

centos7-68.qcow2  CentOS-7.6-x86_64-DVD-1810.iso

[root@xuegod1 images]# ll -h

总用量 15G

-rw-------. 1 qemu qemu  11G 6月  7 20:27 centos7-68.qcow2

-rw-r--r--. 1 qemu qemu 4.3G 6月  7 19:25 CentOS-7.6-x86_64-DVD-1810.iso

[root@xuegod1 images]# df -h

文件系统        容量  已用  可用 已用% 挂载点

/dev/sda3        10G  6.4G  3.7G  64% /

devtmpfs        2.9G    0  2.9G    0% /dev

tmpfs          3.0G    0  3.0G    0% /dev/shm

tmpfs          3.0G  13M  2.9G    1% /run

tmpfs          3.0G    0  3.0G    0% /sys/fs/cgroup

/dev/sda1      197M  143M  55M  73% /boot

tmpfs          595M  56K  595M    1% /run/user/0

/dev/sr0        4.3G  4.3G    0  100% /mnt

/dev/sdb1        20G  15G  5.7G  72% /var/lib/libvirt/images

克隆之前要关闭 

[root@xuegod1 images]# virsh shutdown centos7-68

域 centos7-68 被关闭

virt-clone -o centos7-68 -n xuegod1-kvm2 -f /var/lib/libvirt/images/xuegod1-kvm2.img

2.1.3  一台KVM  虚拟机有两部分组成,虚拟机配置文件和镜像img

[root@xuegod1 ~]# cd /etc/libvirt/

[root@xuegod1 libvirt]# ls

libvirt-admin.conf  libvirtd.conf  nwfilter  qemu.conf        secrets  virtlockd.conf

libvirt.conf        lxc.conf      qemu      qemu-lockd.conf  storage  virtlogd.conf

[root@xuegod1 libvirt]# cd qemu/ 

[root@xuegod1 qemu]# ls

centos7-68.xml  networks


进入新克隆的机器是用

ip  addr show   查看ip和mac  地址,系统中没有ifconfig 

注意 :发现虚拟机中的mac  地址已经和克隆的MAC地址一样,可以直接上网,不用删除

2.2   虚拟机常用的景象格式:raw   ,cow ,qcow,qcow2,vmdk 

raw:  老牌的景象格式,用一个字来说就是裸,



2.3  KVM  虚拟机快照功能使用方法

方法1: 使用lvm快照,如果分区是lvm,可以利用,lvm  进行KVM的快照备份

方法2   使用qcow2   格式的镜像创建快照


查看类型

[root@xuegod1 images]# qemu-img info centos7-68.qcow2

image: centos7-68.qcow2

file format: qcow2

virtual size: 10G (10737418240 bytes)

disk size: 10G

cluster_size: 65536

Format specific information:

    compat: 1.1

    lazy refcounts: true

qcow2   直接创建快照

对centos7-68   虚拟机创建快照

语法 :  virsh   snapshot-create   虚拟机的名字

例如创建一个快照

virsh  start   centos7-68   开机

[root@xuegod1 images]# virsh snapshot-create centos7-68     

已生成域快照 1591599054

注意: 创建快照时,关机创建快照比较快,开机创建快照需要把内容的内容写到磁盘上,记录虚拟机这一时刻

给虚拟机创建名字

virsh  snapshot-create-as    KVM   虚拟机名字

  查看虚拟机名字

root@xuegod1 images]# virsh snapshot-create-as  centos7-68 httpd

已生成域快照 httpd

查看快照名字

[root@xuegod1 images]# virsh snapshot-list centos7-68

名称               生成时间              状态

------------------------------------------------------------

1591599054           2020-06-08 14:50:54 +0800 running

httpd                2020-06-08 14:57:41 +0800 running

同样也可以使用中文

查看当前的快照

    virsh snapshot-current centos7-68    

[root@xuegod1 images]# virsh    snapshot-current centos7-68

<domainsnapshot>

  <name>httpd</name>

  <state>running</state>

查看快照的位置

[root@xuegod1 images]# ls  /var/lib/libvirt/qemu/snapshot/centos7-68/

1591599054.xml  httpd.xml

快照的配置文件

互动:腾讯云,阿里元快照功能要收费不

[root@xuegod1 images]# qemu-img  info  centos7-68.qcow2

image: centos7-68.qcow2

file format: qcow2

3 )查看当前的虚拟机状态

[root@xuegod1 images]# virsh domstate  centos7-68

running

4  )  恢复虚拟机主体

[root@xuegod1 images]# virsh snapshot-revert  centos7-68 httpd

5 )[root@xuegod1 images]# virsh snapshot-current centos7-68 

<domainsnapshot>

  <name>httpd</name>

  <state>running</state>

  <parent>

6  )删除  快照

[root@xuegod1 images]# virsh snapshot-delete centos7-68  1591599054

已删除域快照 1591599054

2.4   virsh  常用命令

//  virsh  list         // 查看已经打开虚拟机列表

//  virsh list --adll    //  查看虚拟机列表

//   virsh  version    //  查看virsh   半杯

//     virsh   start   centos7-68       //  启动虚拟机

//   virsh   shutdown  centos7-68      关机

//  virsh   dumpxml    node1  >   node1.xml       /  导出配置文件

[root@xuegod1 images]# virsh dumpxml centos7-68 > centos7-68.xml

[root@xuegod1 images]# ls

centos7-68.qcow2  centos7-68.qcow2.xml  centos7-68.xml

virsh console    centos7-68      控制台管理

转换格式 

[root@xuegod1 images]# qemu-img convert -f qcow2 -O raw ./centos7-68.qcow2 ./centos7-68.raw




©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。