LVM精简卷(Thinly-Provisioned Logical Volumes)如果被人偷偷的在生产中使用,紧急故障处理的时候,可以一下子给人干懵。并且在百度还不能搜索到完整可用的文档。LVM精简卷的存在给我的感觉并不合理,增加了排错成本和运维复杂度。这篇文章将完整的记录lvm精简卷的创建和扩容。
LVM的精简逻辑卷,这可以创建大于可用盘区的逻辑卷。精简池可以在需要时进行动态扩展,存储管理员可以过量使用物理存储,以节省成本地分配存储空间。在标准的逻辑卷中磁盘空间在创建时就会占用卷组的空间,但是在精简卷中只有在写入时才会占用存储池"thin pool LV"中的空间。
Thin术语讲解
ThinDataLV:thin数据卷
从卷组中创建的一个比较大的卷
在thin池中来储存thin卷的数据块
ThinMetaLV:thin 元数据卷
从卷组中创建的一个比较小的卷
在thin池来储存块数据的映射关系
ThinPoolLV :thin池卷,精简池
由 ThinDataLV 和 ThinMetaLV组成
包括ThinLVs 和 SnapLV
ThinLV:thin LV 精简卷
由 ThinPoolLV创建(刚开始创建时为空,不实际占有空间)
为了确保可以使用所有可用空间,LVM支持数据丢弃。这样可以重新使用以前由废弃文件或其他块范围使用的空间。
创建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
创建ThinPool
Create a thin pool with the lvcreate command.
Create a thin volume in the thin pool with the lvcreate command.
# 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
lVM精简卷thin pool的自动扩容
1.查看配置文件,默认情况下,自动扩展名设置为" 100 "
# grep
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%。
LVM精简卷thin volume手动扩容
将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.
作者来自石家庄,旅居北京10余年。现某保险公司高级运维工程师,欢迎关注v信公众号“实战侠”