Openstack使用LVM作为后端存储

LVM作为libvirt存储池

创建VG

1
2
# pvcreate /dev/sdc1
# vgcreate libvirt /dev/sdc1

libvirt中添加VG作为storage pool

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# vi /etc/libvirt/storage/LVM.xml
<pool type='logical'>
<name>LVM</name>
<source>
<name>libvirt</name>
<format type='lvm2'/>
</source>
<target>
<path>/dev/libvirt</path>
</target>
</pool>
# virsh pool-define /etc/libvirt/storage/LVM.xml
# virsh pool-start LVM
# virsh pool-list
Name State Autostart
-------------------------------------------
default active yes
LVM active no

从存储池中创建卷

1
2
3
4
5
6
7
8
9
# virsh vol-create-as --pool LVM --name vol1 --capacity 1G
Vol vol1 created
# virsh vol-list LVM
Name Path
------------------------------------------------------------------------------
vol1 /dev/libvirt/vol1
# lvs libvirt
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
vol1 libvirt -wi-a----- 1.00g

LVM的thin provisioning特性

thin provision是在 kernel3.2 中引入的。它主要有以下一些特点:

  1. 允许多个虚拟设备存储在相同的数据卷中,从而达到共享数据,节省空间的目的;
  2. 支持任意深度的快照,通过一个单独的数据避免了性能随快照深度的增加而降低。
  3. 支持元数据存储到单独的设备上。

创建VG

1
2
# pvcreate /dev/sdc2
# vgcreate lvm-thin /dev/sdc2

创建thin pool

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#  vgdisplay lvm-thin
--- Volume group ---
VG Name lvm-thin
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 14
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size <50.00 GiB
PE Size 4.00 MiB
Total PE 12799
Alloc PE / Size 0 / 0
Free PE / Size 12799 / <50.00 GiB
VG UUID jIh9s0-3ndB-o2SR-dBL0-s2Xt-6tzz-2otwAM
# lvcreate -l 12799 -n lvm-thin-pool -T lvm-thin
Thin pool volume with chunk size 64.00 KiB can address at most 15.81 TiB of data.
Logical volume "lv_thinpool" created.
# lvs lvm-thin
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lvm-thin-pool lvm-thin twi-a-tz-- <49.61g 0.00 0.44
# lsblk /dev/sdc2
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdc2 8:34 0 50G 0 part
├─lvm--thin-lvm--thin--pool_tmeta 253:3 0 52M 0 lvm
│ └─lvm--thin-lvm--thin--pool 253:5 0 49.6G 0 lvm
└─lvm--thin-lvm--thin--pool_tdata 253:4 0 49.6G 0 lvm
└─lvm--thin-lvm--thin--pool 253:5 0 49.6G 0 lvm

创建thin lv

虽然thin pool只有<50G,却可以创建100G的逻辑卷。thin_pool_autoextend_threshold参数默认为100,需要设置为<100,以便在thin pool达到阈值时自动扩展(前提是对应的卷组有剩余空间)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# lvcreate -V 1G -n thin_vol1 -T lvm-thin/lvm-thin-pool
Logical volume "thin_vol1" created.
# lvcreate -V 100G -n thin_vol2 -T lvm-thin/lvm-thin-pool
WARNING: Sum of all thin volume sizes (101.00 GiB) exceeds the size of thin pool lvm-thin/lvm-thin-pool and the size of whole volume group (<50.00 GiB).
WARNING: You have not turned on protection against thin pools running out of space.
WARNING: Set activation/thin_pool_autoextend_threshold below 100 to trigger automatic extension of thin pools before they get full.
Logical volume "thin_vol2" created.

# lsblk /dev/sdc2
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdc2 8:34 0 50G 0 part
├─lvm--thin-lvm--thin--pool_tmeta 253:3 0 52M 0 lvm
│ └─lvm--thin-lvm--thin--pool-tpool 253:5 0 49.6G 0 lvm
│ ├─lvm--thin-lvm--thin--pool 253:6 0 49.6G 0 lvm
│ ├─lvm--thin-thin_vol1 253:7 0 1G 0 lvm
│ └─lvm--thin-thin_vol2 253:8 0 100G 0 lvm
└─lvm--thin-lvm--thin--pool_tdata 253:4 0 49.6G 0 lvm
└─lvm--thin-lvm--thin--pool-tpool 253:5 0 49.6G 0 lvm
├─lvm--thin-lvm--thin--pool 253:6 0 49.6G 0 lvm
├─lvm--thin-thin_vol1 253:7 0 1G 0 lvm
└─lvm--thin-thin_vol2 253:8 0 100G 0 lvm
# dmsetup ls|grep thin
lvm--thin-lvm--thin--pool (253:6)
lvm--thin-lvm--thin--pool-tpool (253:5)
lvm--thin-lvm--thin--pool_tdata (253:4)
lvm--thin-lvm--thin--pool_tmeta (253:3)
lvm--thin-thin_vol2 (253:8)
lvm--thin-thin_vol1 (253:7)

cinder中使用LVM

  • 使用LVM操作逻辑卷(lvm-thin)
  • 使用iscsi协议向计算节点提供卷

1
2
3
4
5
6
7
8
[DEFAULT]
enabled_backends = lvm-1
[lvm-1]
volume_group = cinder-volumes
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_backend_name = lvm-1
iscsi_helper = tgtadm
iscsi_protocol = iscsi
1
2
3
4
5
# openstack volume create --size 1 test

2018-09-29 04:13:58.260 31 INFO cinder.volume.flows.manager.create_volume [req-69ebb3ca-a4a4-45ef-9250-31beaa1c31f1 2b88338508204edd9de064394325c133 cc247822dd644a70a7b48b2920cbf314 - default default] Volume 369e4de8-58aa-4f21-913b-eb9407329695: being created as raw with specification: {'status': u'creating', 'volume_size': 1, 'volume_name': u'volume-369e4de8-58aa-4f21-913b-eb9407329695'}
2018-09-29 04:13:58.261 31 DEBUG oslo_concurrency.processutils [req-69ebb3ca-a4a4-45ef-9250-31beaa1c31f1 2b88338508204edd9de064394325c133 cc247822dd644a70a7b48b2920cbf314 - default default] Running cmd (subprocess): sudo cinder-rootwrap /etc/cinder/rootwrap.conf env LC_ALL=C lvcreate -T -V 1g -n volume-369e4de8-58aa-4f21-913b-eb9407329695 cinder-volumes/cinder-volumes-pool execute /usr/lib/python2.7/site-packages/oslo_concurrency/processutils.py:367
2018-09-29 04:13:58.785 31 DEBUG oslo_concurrency.processutils [req-69ebb3ca-a4a4-45ef-9250-31beaa1c31f1 2b88338508204edd9de064394325c133 cc247822dd644a70a7b48b2920cbf314 - default default] CMD "sudo cinder-rootwrap /etc/cinder/rootwrap.conf env LC_ALL=C lvcreate -T -V 1g -n volume-369e4de8-58aa-4f21-913b-eb9407329695 cinder-volumes/cinder-volumes-pool" returned: 0 in 0.524s execute /usr/lib/python2.7/site-packages/oslo_concurrency/processutils.py:404
坚持原创技术分享,您的支持将鼓励我继续创作!
0%