WebVirtMgr的日常配置:添加宿主機,創建虛擬機,磁盤擴容,快照等
具體操作記錄如下:
一、創建虛擬機
1、創建存儲池
點擊創建的宿主機,進入虛擬機部署界面
點擊“存儲池”按鈕,創建存儲池(即創建磁盤鏡像存放的位置)
創建存儲池時,首先要在宿主機上創建一個目錄,然后在”路徑“設置欄中添加該目錄
例:# mkdir -p /home/kvm/kvmstorage
[把提前下載好的centos鏡像拷貝到上面創建的存儲池目錄/home/kvm/kvmstorage下;這里可以放不同版本的系統鏡像(windows也可以),以便在下面安裝過程中選擇不同鏡像安裝系統]
輸入名稱和路徑
2、添加磁盤鏡像
選擇KVM001
注意:
下面“Metadata”前的小方框一定不能勾選(默認是勾選的,要去掉!)
這里添加的“鏡像”就是所創建虛擬機的硬盤空間(我測試環境給了150G)
虛擬機所占用的空間就是這個“鏡像”所在的宿主機下路徑所在的分區空間(也就是/home/kvm/kvmstorage/,即宿主機的home分區)
創建完成后如下:
3、宿主機網卡的橋接模式設置
注意下面的“設備”一項要填寫橋接的物理網卡(即br0對應的那個網卡,這里填的是宿主機之前的內網卡enp2s0)
網關地址也一定要填寫正確,不然虛擬機和宿主機同網段機器則會網絡不通。(如下這一步其實就是創建橋接的網卡配置,也可以在服務器上手動創建)
我在服務器上已經手動創建完橋接網絡,所以和上面的配置是一樣的,如下:
4、創建網絡池
選擇橋接模式
配置如下:
成功添加br0
5、創建虛機
點擊“Custom Instance”
添加虛擬機配置
6、虛機掛載ISO鏡像
點擊連接
下面選擇系統安裝時使用的鏡像,這個鏡像是上面放到默認/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
7、啟動虛機
點擊“啟動”按鈕后,打開虛機電源。
點擊控制台按鈕,進入操作系統安裝界面
進入centos7安裝界面
按步驟進行安裝centos7系統
配置網絡並能正常上網,如下圖
二、webvirtmgr虛機磁盤擴容
kvm虛擬機磁盤空間擴展與xen虛擬機磁盤空間擴展思路一致。原因在於xen/kvm默認的虛擬機磁盤格式為raw,所以方式可以通用。
qcow2磁盤格式擴展思路如下
(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