zoukankan      html  css  js  c++  java
  • Centos8中创建LVM精简逻辑卷

    导读 安装系统时lvm标准卷和精简卷不同,lvm标准卷没有精简池(thin pool),精简卷是可以创建大于可用磁盘的逻辑卷。使用精简卷,你可以管理可用空间的存储池(称为精简池),可以在应用程序需要时将其分配给任意数量的设备。精简池可以在需要时进行动态扩展,以节省成本。

    创建LV时,将分配标准逻辑卷中的块,但是在精简配置的逻辑卷中,将在写入时分配它们。因此,精简配置的LV具有虚拟大小,并且可能比物理可用存储大得多。以后可以根据需要增加为精简配置的LV提供的物理存储量。标准LV中的块是在VG中分配的(在创建过程中),而精简LV中的块是从特殊的“瘦池LV”分配的(使用过程中)的。精简池LV包含物理存储块,而精简LV中的块只是精简池LV中的参考块。 必须先创建精简池LV,然后才能在其中创建精简LV。精简池LV是通过组合两个标准LV来创建的:一个大数据LV,它将保存精简LV的块;一个元数据LV,它将保存元数据。元数据跟踪哪些数据块属于每个精简LV。 精简LV的快照非常有效,因为共享了精简LV通用的数据块及其快照。快照可以是精简LV或其他精简快照。递归快照共有的块也在瘦池中共享。快照序列没有限制或降级。写入精简LV或快照LV时,它们会消耗精简池中的数据块。随着池中可用数据块的减少,可能需要提供更多可用块。这是通过使用VG的额外物理空间扩展精简池数据LV来完成的。从精简池中删除精简LV或快照也可以释放精简池中的块。但是,删除LV并不总是一种释放精简池中空间的有效方法,因为该数量仅限于不与池中其他LV共享的块数。精简池的增量块分配可能导致精简LV变得碎片化。标准LV通常通过在创建过程中一次分配所有块来避免此问题

    系统环境

    Centos8

    创建精简池

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

    [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精简逻辑卷

    总结

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

    尊重原创本文原创地址:https://www.linuxprobe.com/lvm-thin-pool.html

  • 相关阅读:
    JS判断是PC端还是移动端
    js对象转数组
    js获取当前域名、Url、相对路径和参数以及指定参数
    javascript返回上一页的三种写法
    js正则归纳总结
    higtcharts 生成图表个数问题
    js如何处理后台传递过来的Map
    jQuey实现鼠标滑过整行变色
    <display:column>常用属性解释
    <display:table>常用属性解释
  • 原文地址:https://www.cnblogs.com/wangchengyi/p/15693175.html
Copyright © 2011-2022 走看看