准备虚拟机磁盘文件
dnf install -y qemu-img
virsh pool-define-as vmPool --type dir --target /data/kvm/images/
virsh pool-build vmPool
virsh pool-start vmPool
virsh pool-autostart vmPool
virsh vol-create-as --pool vmPool --name master0.img --capacity 200G --allocation 1G --format qcow2
virsh vol-create-as --pool vmPool --name master1.img --capacity 200G --allocation 1G --format qcow2
virsh vol-create-as --pool vmPool --name master2.img --capacity 200G --allocation 1G --format qcow2
virsh vol-create-as --pool vmPool --name node1.img --capacity 300G --allocation 1G --format qcow2
virsh vol-create-as --pool vmPool --name node2.img --capacity 300G --allocation 1G --format qcow2
virsh vol-create-as --pool vmPool --name node3.img --capacity 300G --allocation 1G --format qcow2
virsh list 查看运行的虚拟机
virsh list --all 查看所有的虚拟机,关闭和运行的
virsh domstate 虚机名 #显示虚机状态
virsh nodeinfo 虚机名 #显示虚机信息
virsh console 虚机名 #连接虚拟机,按 ctrl+] 组合键退出virsh console
virsh shutdown 虚机名 #关闭虚拟机
virsh start 虚机名 #开启虚拟机
virsh destroy 虚机名 #强制立即关机
virsh suspend 虚拟名 #挂起虚机
virsh resume 虚机名 #恢复虚机
virsh define 虚机名 #创建虚机,不启动
virsh undefine 虚拟名 #取消创建虚机
virsh edit 虚机名 #编辑虚机的kvm配置
virsh save 虚机名 backup1 #把虚拟机的状态保存到backup1
virsh domblklist 虚机名 #显示虚拟机硬盘列表
virsh domiflist 虚机名 #显示虚拟机网络信息
virsh pool-list --all #查看存储池
virsh restore backup1 #恢复虚拟机的状态
virsh autostart 虚机名 #随宿主机开启动,上述命令将创建/etc/libvirt/qemu/autostart/目录,目录内容为开机自启动的系统软链接
virsh autostart --disable 虚机名 #关闭随宿主机开启动
virsh create /etc/libvirt/qemu/虚拟名.xml 通过配置文件启动虚拟机
查看存储卷列表
virsh vol-list vmPool
删除存储卷
virsh vol-delete tuoketuo.img vmPool