1.创建基于文件夹的存储池(目录)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@node1 ~]
# mkdir -p /data/vmfs
[root@node1 ~]
#
[root@node1 ~]
# ll /data/
total 12
drwxr-xr-x 2 root root 4096 Nov 22 09:59 iso
drwxr-xr-x 2 root root 4096 Nov 28 09:04 kvm
drwxr-xr-x 2 root root 4096 Nov 28 09:02 vmfs
[root@node1 ~]
#
[root@node1 ~]
# ll /data/kvm/
total 11436976
-rw-r--r-- 1 root root 393216 Nov 22 17:06 CentOS6.5-01_add.qcow2
-rwxr-xr-x 1 root root 7516192768 Nov 22 15:08 CentOS6.5-01.img
-rw-r--r-- 1 root root 2318139904 Nov 27 17:08 CentOS6.5-01.qcow2
-rwxr-xr-x 1 root root 10737418240 Nov 22 14:40 Ser08R2-01.img
[root@node1 ~]
#
|
2.定义存储池与其目录
1
2
3
4
|
[root@node1 ~]
# virsh pool-define-as vmdisk --type dir --target /data/vmfs
Pool vmdisk defined
[root@node1 ~]
#
|
3.创建已定义的存储池
(1)创建已定义的存储池
1
2
3
4
|
[root@node1 ~]
# virsh pool-build vmdisk
Pool vmdisk built
[root@node1 ~]
#
|
(2)查看已定义的存储池,存储池不激活无法使用。
1
2
3
4
5
6
7
|
[root@node1 ~]
# virsh pool-list --all
Name State Autostart
-----------------------------------------
default active
yes
vmdisk inactive no
[root@node1 ~]
#
|
1
2
3
4
5
6
7
8
|
[root@node1 ~]
# virsh pool-info vmdisk
Name: vmdisk
UUID: bbd57b00-ad6f-91a2-76a4-059042387903
State: inactive
Persistent:
yes
Autostart: no
[root@node1 ~]
#
|
4.激活并自动启动已定义的存储池
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
[root@node1 ~]
# virsh pool-autostart vmdisk
Pool vmdisk marked as autostarted
[root@node1 ~]
# virsh pool-list --all
Name State Autostart
-----------------------------------------
default active
yes
vmdisk inactive
yes
[root@node1 ~]
#
[root@node1 ~]
# virsh pool-start vmdisk
Pool vmdisk started
[root@node1 ~]
# virsh pool-list --all
Name State Autostart
-----------------------------------------
default active
yes
vmdisk active
yes
[root@node1 ~]
#
|
这里vmdisk存储池就已经创建好了,可以直接在这个存储池中创建虚拟磁盘文件了。
5.在存储池中创建虚拟机存储卷
(1)在存储池中创建虚拟机存储卷
1
2
3
4
5
6
7
|
[root@node1 ~]
# virsh vol-create-as vmdisk CentOS6.5-02.qcow2 20G --format qcow2
Vol CentOS6.5-02.qcow2 created
[root@node1 ~]
# ll /data/vmfs/
total 196
-rw------- 1 root root 197120 Nov 28 09:10 CentOS6.5-02.qcow2
[root@node1 ~]
#
|
(2)根据创建的虚拟机存储卷安装虚拟机
1
2
|
[root@node1 ~]
# virt-install --name=CentOS6.5-02 --os-variant=RHEL6 --ram 1024 --vcpus=1 --disk path=/data/vmfs/CentOS6.5-02.qcow2,format=qcow2,size=20,bus=virtio --accelerate --cdrom /data/iso/CentOS-6.5-x86_64-bin-DVD1.iso --vnc --vn
cport=5910 --vnclisten=0.0.0.0 --network bridge=br0,model=virtio --noautoconsole
|
注1:KVM存储池主要是体现一种管理方式,可以通过挂载存储目录,lvm逻辑卷的方式创建存储池,虚拟机存储卷创建完成后,剩下的操作与无存储卷的方式无任何区别了。
注2:KVM存储池也要用于虚拟机迁移任务。
6.存储池相关管理命令
(1)在存储池中删除虚拟机存储卷
1
2
3
4
5
6
|
[root@node1 ~]
# virsh vol-delete --pool vmdisk CentOS6.5-02.qcow2
Vol CentOS6.5-02.qcow2 deleted
[root@node1 ~]
# ll /data/vmfs/
total 0
[root@node1 ~]
#
|
(2)取消激活存储池
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[root@node1 ~]
# virsh pool-list --all
Name State Autostart
-----------------------------------------
default active
yes
vmdisk active
yes
[root@node1 ~]
# virsh pool-destroy vmdisk
Pool vmdisk destroyed
[root@node1 ~]
# virsh pool-list --all
Name State Autostart
-----------------------------------------
default active
yes
vmdisk inactive
yes
[root@node1 ~]
#
|
(3)删除存储池定义的目录/data/vmfs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[root@node1 ~]
# virsh pool-delete vmdisk
Pool vmdisk deleted
[root@node1 ~]
# virsh pool-list --all
Name State Autostart
-----------------------------------------
default active
yes
vmdisk inactive
yes
[root@node1 ~]
# ll /data/
total 8
drwxr-xr-x 2 root root 4096 Nov 22 09:59 iso
drwxr-xr-x 2 root root 4096 Nov 28 09:04 kvm
[root@node1 ~]
#
|
(4)取消定义存储池
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@node1 ~]
# virsh pool-list --all
Name State Autostart
-----------------------------------------
default active
yes
vmdisk inactive
yes
[root@node1 ~]
# virsh pool-undefine vmdisk
Pool vmdisk has been undefined
[root@node1 ~]
# virsh pool-list --all
Name State Autostart
-----------------------------------------
default active
yes
[root@node1 ~]
#
|
到此kvm存储池配置与管理操作完毕。
本文转自 dengaosky 51CTO博客,原文链接:http://blog.51cto.com/dengaosky/2044957,如需转载请自行联系原作者