Chinaunix首页 | 论坛 | 博客
  • 博客访问: 937055
  • 博文数量: 481
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 5078
  • 用 户 组: 普通用户
  • 注册时间: 2018-03-07 14:48
个人简介

分享工作和学习中的点点滴滴,包括前端、后端、运维、产品等各个方面,欢迎您来关注订阅!

文章分类

全部博文(481)

文章存档

2023年(26)

2022年(97)

2021年(119)

2020年(153)

2019年(70)

2018年(16)

我的朋友

分类: LINUX

2022-04-26 23:32:28

精简卷是可以创建大于可用磁盘的逻辑卷。使用精简卷,你可以管理可用空间的存储池(称为精简池),可以在应用程序需要时将其分配给任意数量的设备。精简池可以在需要时进行动态扩展,以节省成本。
系统环境

8

创建精简池

下面我们添加一块硬盘。创建物理卷,然后创建卷组:

[root@localhost ~]# pvcreate /dev/sda
  Physical volume "/dev/sda" successfully created.
[root@localhost ~]# vgcreate vg_thin /dev/sda
  Volume group "vg_thin" successfully created
[root@localhost ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree  
  cl        1   2   0 wz--n- <19.00g  <2.00g
  vg_thin   1   0   0 wz--n- <20.00g <20.00g

Centos8中创建LVM精简逻辑卷Centos8中创建LVM精简逻辑卷
上面已经创建好一个新的卷组了,名字为vg_thin。然后在现有卷组的中创建一个精简池:

[root@localhost ~]# lvcreate -L 1G -T vg_thin/thin_pool
  Thin pool volume with chunk size 64.00 KiB can address at most 15.81 TiB of data.
  Logical volume "thin_pool" created.
[root@localhost ~]# lvs
  LV        VG      Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root      cl      -wi-ao---- 15.00g                                                    
  swap      cl      -wi-ao----  2.00g                                                    
  thin_pool vg_thin twi-a-tz--  1.00g             0.00   10.94         

Centos8中创建LVM精简逻辑卷Centos8中创建LVM精简逻辑卷

创建精简卷

创建精简池之后,我们就可以从精简池中创建精简卷。在本实验中创建四个精简卷,每个精简卷的大小为200 MB。

[root@localhost ~]# lvcreate -V 200M -T vg_thin/thin_pool -n tp_lv_user1
  Logical volume "tp_lv_user1" created.
[root@localhost ~]# lvcreate -V 200M -T vg_thin/thin_pool -n tp_lv_user2
  Logical volume "tp_lv_user2" created.
[root@localhost ~]# lvcreate -V 200M -T vg_thin/thin_pool -n tp_lv_user3
  Logical volume "tp_lv_user3" created.
[root@localhost ~]# lvcreate -V 200M -T vg_thin/thin_pool -n tp_lv_user4
  Logical volume "tp_lv_user4" created.

Centos8中创建LVM精简逻辑卷Centos8中创建LVM精简逻辑卷

格式化并挂载精简卷

将上面创建的四个精简卷格式化为xfs格式:

[root@localhost ~]# mkfs.xfs /dev/vg_thin/tp_lv_user1 
[root@localhost ~]# mkfs.xfs /dev/vg_thin/tp_lv_user2
[root@localhost ~]# mkfs.xfs /dev/vg_thin/tp_lv_user3 
[root@localhost ~]# mkfs.xfs /dev/vg_thin/tp_lv_user4 

创建挂载点,并挂载:

[root@localhost ~]# mkdir -p /mnt/user{1..4}
[root@localhost ~]# mount /dev/vg_thin/tp_lv_user1 /mnt/user1
[root@localhost ~]# mount /dev/vg_thin/tp_lv_user2 /mnt/user2
[root@localhost ~]# mount /dev/vg_thin/tp_lv_user3 /mnt/user3
[root@localhost ~]# mount /dev/vg_thin/tp_lv_user4 /mnt/user4

Centos8中创建LVM精简逻辑卷Centos8中创建LVM精简逻辑卷
向这四个目录写入一些文件:

[root@localhost ~]# dd if=/dev/zero of=/mnt/user1/test.img bs=1M count=100
[root@localhost ~]# dd if=/dev/zero of=/mnt/user2/test.img bs=1M count=100
[root@localhost ~]# dd if=/dev/zero of=/mnt/user3/test.img bs=1M count=100
[root@localhost ~]# dd if=/dev/zero of=/mnt/user4/test.img bs=1M count=100

然后运行下面查看以下使用空间:

[root@localhost ~]# lvs

Centos8中创建LVM精简逻辑卷Centos8中创建LVM精简逻辑卷
我们可以注意到精简池利用率为41.41%

开启防止精简池空间耗尽的保护

再创建两个200 MB的精简卷。可以发现创建这两个精简卷会超过所设置的精简池的大小,虽然可以创建成功,但这样做会有更大的风险,并提示一些超额的警告。

[root@localhost ~]# lvcreate -V 200M -T vg_thin/thin_pool -n tp_lv_user5
  Logical volume "tp_lv_user5" created.
[root@localhost ~]# lvcreate -V 200M -T vg_thin/thin_pool -n tp_lv_user6
  WARNING: Sum of all thin volume sizes (1.17 GiB) exceeds the size of thin pool vg_thin/thin_pool (1.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 "tp_lv_user6" created.

Centos8中创建LVM精简逻辑卷Centos8中创建LVM精简逻辑卷
下面我们删掉刚才创建的tp_lv_user5和tp_lv_user6,在lvm.conf配置文件中开启超额保护,并重新创建这两个精简卷:

[root@localhost ~]# lvremove -f /dev/vg_thin/tp_lv_user5
  Logical volume "tp_lv_user5" successfully removed
[root@localhost ~]# lvremove -f /dev/vg_thin/tp_lv_user6
  Logical volume "tp_lv_user6" successfully removed

编辑/etc/lvm/lvm.conf配置文件,将下两个参数的值修改一下:

# 当精简池的使用率超过此百分比时,将自动扩展该池,将其更改为100将禁用自动扩展。可接受的最小值是50。
        thin_pool_autoextend_threshold = 80
# 通过自动扩展精简池,会增加这个百分比的额外空间。添加到精简池的额外空间量是其当前大小的百分比。
        thin_pool_autoextend_percent = 20

下面创建tp_lv_user5和tp_lv_user6两个精简卷:

[root@localhost ~]# lvcreate -V 200M -T vg_thin/thin_pool -n tp_lv_user5
  Logical volume "tp_lv_user5" created.
[root@localhost ~]# lvcreate -V 200M -T vg_thin/thin_pool -n tp_lv_user6
  Logical volume "tp_lv_user6" created.
[root@localhost ~]# mkfs.xfs /dev/vg_thin/tp_lv_user5 
[root@localhost ~]# mkfs.xfs /dev/vg_thin/tp_lv_user6
[root@localhost ~]# mkdir -p /mnt/user{5..6}
[root@localhost ~]# mount /dev/vg_thin/tp_lv_user5 /mnt/user5
[root@localhost ~]# mount /dev/vg_thin/tp_lv_user6 /mnt/user6

看一下使用的情况:
Centos8中创建LVM精简逻辑卷Centos8中创建LVM精简逻辑卷
下面我们向/mnt/user5和/mnt/user6填充内容,直到thin_pool精简池的使用率超过80%,我们可以看到精简池的容量扩容了。

[root@localhost ~]# lvs
  LV          VG      Attr       LSize   Pool      Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root        cl      -wi-ao----  15.00g                                                         
  swap        cl      -wi-ao----   2.00g                                                         
  thin_pool   vg_thin twi-aotz--   1.20g                  75.94  22.66                           
  tp_lv_user1 vg_thin Vwi-aotz-- 200.00m thin_pool        77.97                                  
  tp_lv_user2 vg_thin Vwi-aotz-- 200.00m thin_pool        77.97                                  
  tp_lv_user3 vg_thin Vwi-aotz-- 200.00m thin_pool        77.97                                  
  tp_lv_user4 vg_thin Vwi-aotz-- 200.00m thin_pool        77.97                                  
  tp_lv_user5 vg_thin Vwi-aotz-- 200.00m thin_pool        77.97                                  
  tp_lv_user6 vg_thin Vwi-aotz-- 200.00m thin_pool        77.97                                  

Centos8中创建LVM精简逻辑卷Centos8中创建LVM精简逻辑卷
可以看到上面,thin_pool精简池的容量提升了200M,这就说明当精简池的使用率超过80%时,提升20%的容量。

如何扩展精简池

扩展精简池时,我们需要遵循两个步骤:

  • 1. 扩展精简池的元数据
  • 2. 然后再扩展精简池。

要扩展精简池,我们不应该立即继续扩展精简池。首先,通过运行lvs -a查看现有元数据使用的大小情况。

[root@localhost ~]# lvs -a
  LV                VG      Attr       LSize   Pool      Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root              cl      -wi-ao----  15.00g                                                         
  swap              cl      -wi-ao----   2.00g                                                         
  [lvol0_pmspare]   vg_thin ewi-------   4.00m                                                         
  thin_pool         vg_thin twi-aotz--   1.20g                  75.94  22.66                           
  [thin_pool_tdata] vg_thin Twi-ao----   1.20g                                                         
  [thin_pool_tmeta] vg_thin ewi-ao----   4.00m                                                         
  tp_lv_user1       vg_thin Vwi-aotz-- 200.00m thin_pool        77.97                                  
  tp_lv_user2       vg_thin Vwi-aotz-- 200.00m thin_pool        77.97                                  
  tp_lv_user3       vg_thin Vwi-aotz-- 200.00m thin_pool        77.97                                  
  tp_lv_user4       vg_thin Vwi-aotz-- 200.00m thin_pool        77.97                                  
  tp_lv_user5       vg_thin Vwi-aotz-- 200.00m thin_pool        77.97                                  
  tp_lv_user6       vg_thin Vwi-aotz-- 200.00m thin_pool        77.97                    

Centos8中创建LVM精简逻辑卷Centos8中创建LVM精简逻辑卷

扩展精简池metadata的大小

元数据的当前大小仅为4 MB。让我们在当前大小的基础上添加4MB。

[root@localhost ~]# lvextend --poolmetadatasize +4M vg_thin/thin_pool

Centos8中创建LVM精简逻辑卷Centos8中创建LVM精简逻辑卷
可以看到[thin_pool_tmeta]已经变成8M了。

扩展精简池的大小

完成扩展元数据后,开始将精简池扩展到所需的大小。将精简池扩容量再添加1G容量。

[root@localhost ~]# lvextend -L +1G /dev/vg_thin/thin_pool 

Centos8中创建LVM精简逻辑卷Centos8中创建LVM精简逻辑卷
现在大小已变成2.2G了。

扩展精简卷

扩展精简卷和扩展精简池类似:

[root@localhost ~]# lvextend -L +200M /dev/vg_thin/tp_lv_user1 

Centos8中创建LVM精简逻辑卷Centos8中创建LVM精简逻辑卷

删除精简卷、精简池

要删除精简池,首先需要卸载所有文件系统,然后删除所有精简卷,最后删除精简池。

# 卸载分区
[root@localhost ~]# umount /mnt/user{1..6}
# 删除精简卷
[root@localhost ~]# lvremove -y /dev/vg_thin/tp_lv_user[1-6]
  Logical volume "tp_lv_user1" successfully removed
  Logical volume "tp_lv_user2" successfully removed
  Logical volume "tp_lv_user3" successfully removed
  Logical volume "tp_lv_user4" successfully removed
  Logical volume "tp_lv_user5" successfully removed
  Logical volume "tp_lv_user6" successfully removed
# 删除精简池
[root@localhost ~]# lvremove -y /dev/vg_thin/thin_pool
  Logical volume "thin_pool" successfully removed

使用lvs 查看以下,是否已经删除干净:

[root@localhost ~]# lvs -a
  LV   VG Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root cl -wi-ao---- 15.00g                                                    
  swap cl -wi-ao----  2.00g                

Centos8中创建LVM精简逻辑卷Centos8中创建LVM精简逻辑卷

总结

精简卷是可以创建大于可用磁盘的逻辑卷。使用精简卷,你可以管理可用空间的存储池(称为精简池),可以在应用程序需要时将其分配给任意数量的设备。精简池可以在需要时进行动态扩展,以节省成本。

本文原创地址:编辑:逄增宝,审核员:逄增宝

阅读(359) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~