LVM精简卷(Thinly-Provisioned Logical Volumes)

可能LVM大家都比较熟悉,那么精简卷又是干什么的呢?相比于普通LVM有什么优势,又会带来哪些新的问题?带着这些我们来一探究竟:

工作原理

在创建Thin“瘦”卷时,预分配一个虚拟的逻辑卷容量大小,而只是在实际写入数据时才分配物理空间给这个卷。这样我们可以轻易的创建出总逻辑容量超出物理磁盘空间的多个“精简卷”,而无须为将来可能达到的数据量提前“买单”。在应用产生的数据确实需要增加驱动器时,我们也可以灵活地在线调整卷的大小。

带来的问题:

当每个卷已使用的容量总和超过阵列的物理容量时,将无法再写入数据,并导致应用出错。
于是设置空间预警的功能就相当重要,比如在物理空间占用达到85%时向管理员发出通知,
或者设定自动增长策略,当达到指定阀值,比如85%时,卷自动增长10G。

Thin provisioned

Thin Provisioned的最大特点在于可以对存储资源进行按需动态分配,即对存储进行了虚拟化管理。
例如,某位用户向服务器管理员请求分配10TB的资源。虽然可能确实需要10TB的物理存储容量,但根据当前使用情况,分配2TB就已足够。
因此,系统管理员准备2TB的物理存储,并给服务器分配10TB的虚拟卷。服务器即可基于仅占虚拟卷容量1/5的现有物理磁盘池开始运行。
这样的“始于小”方案能够实现更高效地利用存储容量。

  • 组成

在标准的逻辑卷中磁盘空间在创建时就会占用卷组的空间,但是在瘦(thin)卷中只有在写入时才会占用存储池"thin pool LV"中的空间。
一个 thin逻辑卷创建前必须创建 thin pool LV,一个 thin pool LV由两部分组成:
一个大的data LV(数据卷)用来储存数据块,和一个metadate LV(元数据卷)。metadata中记录了thin卷中每个块数据的所属关系。
(说简单点就是metadata中储存索引,data中储存真实数据,当你访问数据时,先通过索引再访问数据,因为你每次首先访问的不是真实数据,
所有就像C语言中链表一样,理论上储存的数据可以无限大,并且动态可调)。

术语介绍

ThinDataLV:thin数据卷。从卷组中创建的一个比较大的卷,在thin池中来储存thin卷的数据块。
ThinMetaLV: thin 元数据卷。从卷组中创建的一个比较小的卷,在thin池来储存块数据的映射关系。
ThinPoolLV :thin池卷,精简池。 由 ThinDataLV 和 ThinMetaLV组成,包括ThinLVs 和 SnapLV。
ThinLV:thin LV 精简卷。由 ThinPoolLV创建(刚开始创建时为空,不实际占有空间)。

创建thin pool

在测试的服务器上新增了一块10G的磁盘,将这个磁盘创建为一个thinpool和2个5G的逻辑卷。它看起来应该这样做。

  • 创建pv
# pvcreate /dev/sdc
Physical volume "/dev/sdc" successfully created.
  • 创建vg
# vgcreate data /dev/sdc
Volume group "data" successfully created
  • 创建thin pool
# lvcreate -l +100%free --thinpool data_pool data
Thin pool volume with chunk size 64.00 KiB can address at most 15.81 TiB of data.
Logical volume "data_pool" created.
  • 创建精简卷thin volume
# lvcreate -V 5G --thin -n thin_lv_data01 data/data_pool
Logical volume "thin_lv_data01" created.
# lvcreate -V 5G --thin -n thin_lv_data02 data/data_pool
WARNING: Sum of all thin volume sizes (10.00 GiB) exceeds the size of thin pool data/data_pool and the size of whole volume group (<10.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_lv_data02" created.
  • 创建完成查看效果
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
data_pool data twi-aotz-- 9.97g 0.00 0.68
thin_lv_data01 data Vwi-a-tz-- 5.00g data_pool 0.00
thin_lv_data02 data Vwi-a-tz-- 5.00g data_pool 0.00
root rhel -wi-ao---- 149.50g
swap00 swapvg -wi-ao---- <8.00g

thin pool自动扩容

1.查看配置文件/etc/lvm/lvm.conf,默认情况下,自动扩展名设置为100

thin_pool_autoextend_threshold /etc/lvm/lvm.conf

#Configuration option activation/thin_pool_autoextend_threshold.

#thin_pool_autoextend_threshold = 70

thin_pool_autoextend_threshold = 100

#设置为100将禁用自动扩展,默认设置表明该功能已被禁用。activation /
thin_pool_autoextend_threshold表明当精简池的使用率超过此百分比时会自动扩展。

2.启用自动扩展,请同时更改"
thin_pool_autoextend_percent “和” thin_pool_autoextend_threshold "设置:

thin_pool_autoextend_threshold = 70
thin_pool_autoextend_percent = 20

这意味着,只要池使用率超过70%,它就会再扩展20%。

手动扩容

将pv扩容5G,扩容完如下:

# pvs
/dev/sdc data lvm2 a-- <15.00g 5.00g
#vgs
VG #PV #LV #SN Attr VSize VFree
data 1 3 0 wz--n- <15.00g 5.00g
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
data_pool data twi-aotz-- 9.97g 0.00 0.68
thin_lv_data01 data Vwi-a-tz-- 5.00g data_pool 0.00
thin_lv_data02 data Vwi-a-tz-- 5.00g data_pool 0.00
root rhel -wi-ao---- 149.50g
swap00 swapvg -wi-ao---- <8.00g
# lvextend -L +2G data/data_pool(实验环境,手动扩容thin pool)
Size of logical volume data/data_pool_tdata changed from 9.97 GiB (2553 extents) to 11.97 GiB (3065 extents).
Logical volume data/data_pool_tdata successfully resized.
# lvextend -L +2G data/thin_lv_data01(手动扩容thin volume)
WARNING: Sum of all thin volume sizes (12.00 GiB) exceeds the size of thin pool data/data_pool and the amount of free space in volume group (3.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.
Size of logical volume data/thin_lv_data01 changed from 5.00 GiB (1280 extents) to 7.00 GiB (1792 extents).
Logical volume data/thin_lv_data01 successfully resized.

以上内容整理自网络:

猜你喜欢

转载自blog.csdn.net/IndexMan/article/details/120267326