通过virt工具安装管理KVM虚拟机

简介:
1.virt-install 命令安装虚拟机
[root@hyperStor images]# virt-install --name rhcexam --ram 1024  --vcpus 1 --description=rhce --cdrom /var/lib/libvirt/isos/rhel-server-6.2-32.iso --os-type=linux --os-variant=rhel6 --disk path=/var/lib/libvirt/images/rhcexam.img,size=20,format=qcow2 --network bridge=br0 --graphics vnc,listen=192.168.3.30,password=123456,port=5910
命令参数:
--name             虚拟机的名称
--ram               内存大小
--vcpus             CPU数目
--description      虚拟机描述
--cdrom            指定cdrom的镜像文件或者设备名
--os-type           操作系统类型
--os-variant      操作系统版本
--disk               磁盘属性:path路径,size 大小,format 存储类型
--network         指定网络设备,bridge为桥接设备
--graphic          指定图形化类别,此处为vnc,后面接属性:listen 监听IP,passsword 连接密码,port 监听端口
[root@hyperStor images]# virt-install  --name rhcsa --ram 1024 --vcpus 1  --import --disk path=rhcsa.img --network bridge=br0 --graphics vnc,listen=192.168.3.30,password=123,port=5901 //导入已经存在的虚拟机文件
2.virt-viewer  用于连接正在运行的虚拟机
[root@hyperStor ~]# virsh  list --all
Id Name                 State
----------------------------------
 5 node1                running
 6 node2                running
12 rhcexam            running
[root@hyperStor ~]# virt-viewer  12  //连接ID为12的rhcexam虚拟机,virt-viewer后接rhcexam也可以
3.virsh 命令管理虚拟机
[root@hyperStor ~]#  virsh list  //列出所有运行的虚拟机
[root@hyperStor ~]#  virsh list --all //列出所有虚拟机,包括未运行的
[root@hyperStor ~]#  virsh  shutdown  id|name    //正常关闭虚拟机
[root@hyperStor ~]#  virsh  destroy id|name     //强制关闭虚拟机
[root@hyperStor ~]#  virsh  undefine id|name   //从虚拟机列表中删除虚拟机【不删除文件】
[root@hyperStor ~]#   virsh start id|name  //启动虚拟机
[root@hyperStor ~]#  virsh  suspend  id|name //挂起虚拟机
[root@hyperStor ~]#  virsh  resume    id|name  //恢复虚拟机
[root@hyperStor ~]#  virsh  reboot id|name     //重启虚拟机
[root@hyperStor images]# virsh  autostart 16  //将id为16的虚拟机设置为自动启动【随着物理机启动】
Domain 16 marked as autostarted
[root@hyperStor ~]# virsh   vol-clone  /var/lib/libvirt/images/rhcexam.img  rhcexam-clone.img  //克隆镜像文件
Vol rhcexam-clone.img cloned from rhcexam.img
红色字体路径必须指定,后面的名称不用指定路径,默认跟原始镜像一个路径下
4. qemu-img 工具
给虚拟机做快照
[root@hyperStor ~]# qemu-img  snapshot -c rhce-sp1 /var/lib/libvirt/images/rhcexam.img //创建镜像
[root@hyperStor ~]# qemu-img  snapshot -l /var/lib/libvirt/images/rhcexam.img   //列出镜像快照
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1         rhce-sp1                  0 2013-03-22 10:26:06   00:00:00.000
[root@hyperStor ~]# qemu-img  snapshot -a rhce-sp1 /var/lib/libvirt/images/rhcexam.img //恢复快照
[root@hyperStor ~]# qemu-img  snapshot -d rhce-sp1 /var/lib/libvirt/images/rhcexam.img //删除快照









本文转自 暗黑魔君 51CTO博客,原文链接:http://blog.51cto.com/clovemfong/1197577,如需转载请自行联系原作者
目录
相关文章
|
1月前
|
存储 运维 API
云计算中的虚拟机管理
云计算中的虚拟机管理
33 0
|
1月前
|
数据安全/隐私保护 虚拟化 Windows
如何在 VM 虚拟机中安装 Windows Server 2012 操作系统保姆级教程(附链接)
如何在 VM 虚拟机中安装 Windows Server 2012 操作系统保姆级教程(附链接)
77 0
|
1月前
|
数据安全/隐私保护 虚拟化 Windows
如何在 VM 虚拟机中安装 Windows 7 操作系统保姆级教程(附链接)
如何在 VM 虚拟机中安装 Windows 7 操作系统保姆级教程(附链接)
92 0
如何在 VM 虚拟机中安装 Windows 7 操作系统保姆级教程(附链接)
|
1月前
|
数据安全/隐私保护 虚拟化 Windows
如何在 VM 虚拟机中安装 Windows XP 操作系统保姆级教程(附链接)
如何在 VM 虚拟机中安装 Windows XP 操作系统保姆级教程(附链接)
119 0
|
1月前
|
Linux 网络安全 数据安全/隐私保护
如何在 VM 虚拟机中安装 CentOS Linux 9 操作系统保姆级教程(附链接)
如何在 VM 虚拟机中安装 CentOS Linux 9 操作系统保姆级教程(附链接)
168 0
|
1月前
|
安全 Linux 网络安全
如何在 VM 虚拟机中安装 Red Hat Enterprise Linux 9.3 操作系统保姆级教程(附链接)
如何在 VM 虚拟机中安装 Red Hat Enterprise Linux 9.3 操作系统保姆级教程(附链接)
90 0
|
2天前
|
运维 Linux KVM
KVM详解(六)——KVM虚拟机快照
KVM详解(六)——KVM虚拟机快照
4 0
|
2天前
|
运维 Linux KVM
KVM详解(五)——KVM虚拟机镜像格式
KVM详解(五)——KVM虚拟机镜像格式
5 0
|
8天前
|
Linux KVM 数据库
虚拟机数据恢复—误删除KVM虚拟机的数据恢复案例
虚拟化数据恢复环境&故障: KVM是Kernel-based Virtual Machine的简称,是一个开源的系统虚拟化模块,自Linux2.6.20版本之后集成在Linux的各个主要发行版本中。KVM使用Linux自身的调度器进行管理。 本案例中的服务器操作系统为Linux,文件系统为EXT4。操作系统上的部署的几台KVM虚拟机被删除,每台KVM虚拟机包含一个qcow2格式的磁盘文件和一个raw格式的磁盘文件,用户需要恢复的数据是raw格式的磁盘文件。这几台被误删除的虚拟机存放的是数据库,程序代码等数据。
|
8天前
|
Ubuntu 数据安全/隐私保护
在UBUNTU虚拟机上安装R软件包
在UBUNTU虚拟机上安装R软件包
12 0