KVM虚拟化笔记(十五)------kvm虚拟化存储池配置

1,创建基于文件夹的存储池(目录)

1
2
3
4
5
6
7
[[email protected] test]# mkdir -p /images/vmfs
[[email protected] test]# cd ..
[[email protected] images]# ll
total 12
drwxr-xr-x 2 root root 4096 Feb  2 14:41 iso
drwxr-xr-x 2 root root 4096 Feb  5 16:44 test
drwxr-xr-x 2 root root 4096 Feb  6 13:08 vmfs

2,定义存储池与目录

1
2
3
[[email protected] images]# virsh pool-define-as vmdisk --type dir --target /images/vmfs/
Pool vmdisk defined
[[email protected] images]#

3,创建已定义的存储池

1
2
[[email protected] images]# virsh pool-build vmdisk
Pool vmdisk built

4,查看已定义的存储池,存储池不**就无法使用。

[[email protected] images]# virsh pool-list --all

Name                 State      Autostart 

-----------------------------------------

default              active     yes       

vmdisk               inactive   no        

5,**并自动启动已定义的存储池。

1
2
3
4
5
6
7
8
9
[[email protected] images]# virsh pool-autostart vmdisk 
Pool vmdisk marked as autostarted
[[email protected] images]# virsh pool-start vmdisk
Pool vmdisk started
[[email protected] images]# virsh pool-list --all       
Name                 State      Autostart 
-----------------------------------------
default              active     yes       
vmdisk               active     yes

这里vmdisk存储池就已经创建好了,可以直接在这个存储池中创建虚拟磁盘文件了


6,在存储池中创建虚拟机存储卷

1
2
[[email protected] images]# virsh vol-create-as vmdisk hadoop5.qcow2 20G --format qcow2        
Vol hadoop5.qcow2 created

7,根据创建虚拟机存储卷安装虚拟机

1
2
3
4
5
[[email protected] images]# virt-install --name=qfmy  --ram 512 --vcpus=1 \
--disk path=/images/vmfs/lqb.qcow2,format=qcow2,size=7,bus=virtio \
--accelerate --cdrom /images/iso/CentOS-6.5-x86_64-minimal.iso -d --vnc --vncport=5902 \ 
--network network:default \
--noautoconsole

注意1:KVM存储池主要是体现一种管理方式,可以通过挂载存储目录,lvm逻辑卷的方式创建存储池,虚拟机存储卷创建完成后,剩下的操作与无存储卷的方式无任何区别了。

注意2:KVM存储池也要用于虚拟机迁移任务。



备注:存储池相关管理命令

 (1)在存储池中删除虚拟机存储卷

1
2
[[email protected] images]# virsh vol-delete --pool vmdisk lqb.qcow2      
Vol lqb.qcow2 deleted

 (2)取消**的存储池

1
2
[[email protected] images]# virsh pool-destroy vmdisk
Pool vmdisk destroyed

 (3)删除存储池定义的目录/images/vmfs

1
2
3
4
5
6
7
8
[[email protected] images]# virsh pool-delete vmdisk
Pool vmdisk deleted
[[email protected] images]# virsh pool-list --all   
Name                 State      Autostart 
-----------------------------------------
default              active     yes       
vmdisk               inactive   yes       
vmdisk02             inactive   no
1
2
3
4
5
6
7
8
 (4)取消定义存储池
[[email protected] images]# virsh pool-undefine vmdisk
Pool vmdisk has been undefined
[[email protected] images]# virsh pool-list --all     
Name                 State      Autostart 
-----------------------------------------
default              active     yes       
vmdisk02             inactive   no


KVM虚拟化笔记(十五)------kvm虚拟化存储池配置


至此,kvm存储池配置与管理的操作就完成了


本文转自 lqbyz 51CTO博客,原文链接:http://blog.51cto.com/liqingbiao/1741319