openstack学习(三)创建虚拟机

1 , 用图形管理界面创建虚拟机

#virt-manager    //打开图形管理界面

配置文件一般存放于/etc/libvirt/qemu

然后按照提示一步步安装即可,网络连接方式改为桥接

导出创建的虚拟机xml文件

root@cy-ubuntu:/home/cy# virt-manager  //打开图形管理
root@cy-ubuntu:/home/cy# virsh list --all  //查看虚拟机
 Id    Name                           State
----------------------------------------------------
 8     ubuntu-server                  running

root@cy-ubuntu:/home/cy# virsh destroy ubuntu-server   //关闭正在运行的虚拟机
Domain ubuntu-server destroyed

root@cy-ubuntu:/home/cy# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     ubuntu-server                  shut off

root@cy-ubuntu:/home/cy# virsh dumpxml ubuntu-server > /opt/vm/vmxml/ubuntu-server.xml   //导出配置文件
root@cy-ubuntu:/home/cy# grep 'source file=' /opt/vm/vmxml/ubuntu-server.xml       //找出系统安装的磁盘,为以后应用此系统准备
      <source file='/opt/vm/vmdev/ubuntu-15.10.raw'/>        

删除虚拟机:virsh undefine  虚拟机名称   //此时只是删除了管理系统中删除,文件磁盘还在;若从管理界面删除,则虚拟磁盘也将删除

2 , 命令方式安装

root@cy-ubuntu:/opt/vm/vmxml# vi winxp.xml    //自定义的配置文件
root@cy-ubuntu:/opt/vm/vmxml# virsh define winxp.xml   //导入配置文件
Domain winxp defined from winxp.xml

root@cy-ubuntu:/opt/vm/vmxml# virsh list --all     //已加入到管理系统中
 Id    Name                           State
----------------------------------------------------
 -     ubuntu-server                  shut off
 -     winxp                          shut off
root@cy-ubuntu:/opt/vm/vmxml# virsh start winxp   //运行虚拟机
Domain winxp started

root@cy-ubuntu:/opt/vm/vmxml# virsh vncdisplay winxp  //查看虚拟机的输出端口(port)
:0

root@cy-ubuntu:/opt/vm/vmxml# apt-get install vncviewer //安装查看器
查看的命令:vncviewer IP:port

3 , 如何大批量创建虚拟机

a,拷贝已有虚拟机安装磁盘。----------消耗大量io与容量,性价比不高

b,利用qcow2格式中‘backing_file= ‘来快速创建------占用资源少,速度快

原文地址:https://www.cnblogs.com/chen-yong/p/5326437.html