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,如需转载请自行联系原作者