Centos8中创建LVM的精简逻辑卷具体方法

LVM的精简逻辑卷,这可以创建大于可用盘区的逻辑卷。精简池可以在需要时进行动态扩展,存储管理员可以过量使用物理存储,以节省成本地分配存储空间,下面讲解一下在Centos8中创建LVM的精简逻辑卷具体方法。

系统环境

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- 

上面已经创建好一个新的卷组了,名字为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

向这四个目录写入一些文件:

[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

我们可以注意到精简池利用率为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.

下面我们删掉刚才创建的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

看一下使用的情况: 下面我们向/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                                  

可以看到上面,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

可以看到[thin_pool_tmeta]已经变成8M了。

扩展精简池的大小

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

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

现在大小已变成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://shuyeidc.com/wp/219482.html<

(0)
运维的头像运维
上一篇2025-04-14 03:24
下一篇 2025-04-14 03:26

相关推荐

  • 个人主题怎么制作?

    制作个人主题是一个将个人风格、兴趣或专业领域转化为视觉化或结构化内容的过程,无论是用于个人博客、作品集、社交媒体账号还是品牌形象,核心都是围绕“个人特色”展开,以下从定位、内容规划、视觉设计、技术实现四个维度,详细拆解制作个人主题的完整流程,明确主题定位:找到个人特色的核心主题定位是所有工作的起点,需要先回答……

    2025-11-20
    0
  • 社群营销管理关键是什么?

    社群营销的核心在于通过建立有温度、有价值、有归属感的社群,实现用户留存、转化和品牌传播,其管理需贯穿“目标定位-内容运营-用户互动-数据驱动-风险控制”全流程,以下从五个维度展开详细说明:明确社群定位与目标社群管理的首要任务是精准定位,需明确社群的核心价值(如行业交流、产品使用指导、兴趣分享等)、目标用户画像……

    2025-11-20
    0
  • 香港公司网站备案需要什么材料?

    香港公司进行网站备案是一个涉及多部门协调、流程相对严谨的过程,尤其需兼顾中国内地与香港两地的监管要求,由于香港公司注册地与中国内地不同,其网站若主要服务内地用户或使用内地服务器,需根据服务器位置、网站内容性质等,选择对应的备案路径(如工信部ICP备案或公安备案),以下从备案主体资格、流程步骤、材料准备、注意事项……

    2025-11-20
    0
  • 如何企业上云推广

    企业上云已成为数字化转型的核心战略,但推广过程中需结合行业特性、企业痛点与市场需求,构建系统性、多维度的推广体系,以下从市场定位、策略设计、执行落地及效果优化四个维度,详细拆解企业上云推广的实践路径,精准定位:明确目标企业与核心价值企业上云并非“一刀切”的方案,需先锁定目标客户群体,提炼差异化价值主张,客户分层……

    2025-11-20
    0
  • PS设计搜索框的实用技巧有哪些?

    在PS中设计一个美观且功能性的搜索框需要结合创意构思、视觉设计和用户体验考量,以下从设计思路、制作步骤、细节优化及交互预览等方面详细说明,帮助打造符合需求的搜索框,设计前的规划明确使用场景:根据网站或APP的整体风格确定搜索框的调性,例如极简风适合细线条和纯色,科技感适合渐变和发光效果,电商类则可能需要突出搜索……

    2025-11-20
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注