WebVirtMgr的平常配置:添加宿主机,建立虚拟机,磁盘扩容,快照等
具体操做记录以下:html
点击建立的宿主机,进入虚拟机部署界面web
点击“存储池”按钮,建立存储池(即建立磁盘镜像存放的位置)windows
建立存储池时,首先要在宿主机上建立一个目录,而后在”路径“设置栏中添加该目录centos
例:# mkdir -p /home/kvm/kvmstorage服务器
[把提早下载好的centos镜像拷贝到上面建立的存储池目录/home/kvm/kvmstorage下;这里能够放不一样版本的系统镜像(windows也能够),以便在下面安装过程当中选择不一样镜像安装系统]网络
输入名称和路径ide
选择KVM001测试
注意:
下面“Metadata”前的小方框必定不能勾选(默认是勾选的,要去掉!)ui
这里添加的“镜像”就是所建立虚拟机的硬盘空间(我测试环境给了150G)centos7
虚拟机所占用的空间就是这个“镜像”所在的宿主机下路径所在的分区空间(也就是/home/kvm/kvmstorage/,即宿主机的home分区)
建立完成后以下:
注意下面的“设备”一项要填写桥接的物理网卡(即br0对应的那个网卡,这里填的是宿主机以前的内网卡enp2s0)
网关地址也必定要填写正确,否则虚拟机和宿主机同网段机器则会网络不通。(以下这一步其实就是建立桥接的网卡配置,也能够在服务器上手动建立)
我在服务器上已经手动建立完桥接网络,因此和上面的配置是同样的,以下:
选择桥接模式
配置以下:
成功添加br0
点击“Custom Instance”
添加虚拟机配置
点击链接
下面选择系统安装时使用的镜像,这个镜像是上面放到默认/var/lib/libvirt/images/目录下的,若是下载了各类镜像版本放到里面,那么就能够在这里选择你想安装的版本了!
# ls /var/lib/libvirt/images/
[root@localhost ~]# ls /var/lib/libvirt/images/ CentOS-7-x86_64-DVD-1511.iso win2008R2.qcow2 cn_windows_server_2008_r2_standard_enterprise_datacenter_and_web_with_sp1_vl_build_x64_dvd_617396.iso
点击“启动”按钮后,打开虚机电源。
点击控制台按钮,进入操做系统安装界面
进入centos7安装界面
按步骤进行安装centos7系统
配置网络并能正常上网,以下图
kvm虚拟机磁盘空间扩展与xen虚拟机磁盘空间扩展思路一致。缘由在于xen/kvm默认的虚拟机磁盘格式为raw,因此方式能够通用。
(1) 能够采用raw磁盘格式磁盘的扩展方式一致的方式进行。
(2) qcow2格式磁盘,直接经过qemu-img 直接扩展qcow2磁盘, 新添加一块raw格式的磁盘加入到KVM虚拟机,而后经过虚拟机系统lvm逻辑卷管理方式进行管理,扩展磁盘空间。
下面将开始经过qcow2格式添加磁盘。
1 关闭虚机
2 对虚机的xml文件的disk域添加以下代码:
场景一:新增一块磁盘
添加以下代码
<disk type='file' device='disk'> <driver name='qemu' type='qcow2' cache='none'/> ---添加改行代码找到新增磁盘格式 <source file='/home/kvm/teststorage/entd01.img'/> --指定新增磁盘路径 <target dev='vda' bus='virtio'/> --指定磁盘设备名称,和传输总线类型 </disk>
场景二:新增多块磁盘
已新增两块盘为例:
添加以下代码
<disk type='file' device='disk'> <driver name='qemu' type='qcow2' cache='none'/> <source file='/home/kvm/teststorage/entd01.img'/> <target dev='vda' bus='virtio'/> </disk> <disk type='file' device='disk'> <driver name='qemu' type='qcow2' cache='none'/> <source file='/home/kvm/vm/waq02-clone.qcow2'/> <target dev='vdb' bus='virtio'/> </disk>
方法一:直接扩展qcow2磁盘(纵向扩容)
查看磁盘格式信息
# qemu-img info /var/lib/libvirt/images/win2008R2.qcow2
[root@localhost ~]# qemu-img info /var/lib/libvirt/images/win2008R2.qcow2 image: /var/lib/libvirt/images/win2008R2.qcow2 file format: qcow2 virtual size: 150G (161061273600 bytes) disk size: 150G cluster_size: 65536 Format specific information: compat: 1.1 lazy refcounts: true
给镜像增长100G容量
# qemu-img resize /var/lib/libvirt/images/win2008R2.qcow2 +100G
此方法并非当即分配存储空间
[root@localhost ~]# qemu-img resize /var/lib/libvirt/images/win2008R2.qcow2 +100G Image resized. [root@localhost ~]# qemu-img info /var/lib/libvirt/images/win2008R2.qcow2 image: /var/lib/libvirt/images/win2008R2.qcow2 file format: qcow2 virtual size: 250G (268435456000 bytes) disk size: 150G cluster_size: 65536 Format specific information: compat: 1.1 lazy refcounts: true
开启虚拟机查看是否添加成功
方法二:添加一块qcow2磁盘(横向扩容)
建立虚拟硬盘
# qemu-img create -f qcow2 win2008R2_disk1.qcow2 100G
[root@localhost ~]# cd /var/lib/libvirt/images/ [root@localhost images]# [root@localhost images]# ls CentOS-7-x86_64-DVD-1511.iso win2008R2.qcow2 cn_windows_server_2008_r2_standard_enterprise_datacenter_and_web_with_sp1_vl_build_x64_dvd_617396.iso [root@localhost images]# [root@localhost images]# qemu-img create -f qcow2 win2008R2_disk1.qcow2 100G Formatting 'win2008R2_disk1.qcow2', fmt=qcow2 size=107374182400 encryption=off cluster_size=65536 lazy_refcounts=off [root@localhost images]# [root@localhost images]# ls CentOS-7-x86_64-DVD-1511.iso win2008R2_disk1.qcow2 cn_windows_server_2008_r2_standard_enterprise_datacenter_and_web_with_sp1_vl_build_x64_dvd_617396.iso win2008R2.qcow2 [root@localhost images]# [root@localhost images]# du -sh win2008R2_disk1.qcow2 196K win2008R2_disk1.qcow2
添加一块qcow2磁盘信息加入配置文件
<disk type='file' device='disk'> <driver name='qemu' type='qcow2' cache='none'/> <source file='/data/test01_add.qcow2'/> <target dev='hdb' bus='ide'/> </disk>
参考博客:
https://www.cnblogs.com/kevingrace/p/5739009.html
KVM虚拟机扩展磁盘空间
https://www.cnblogs.com/pigdragon/p/9506556.html