良许Linux教程网 干货合集 Centos8中创建LVM的精简逻辑卷具体方法

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

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

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精简逻辑卷
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精简逻辑卷
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精简逻辑卷
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精简逻辑卷
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精简逻辑卷
Centos8中创建LVM精简逻辑卷Centos8中创建LVM精简逻辑卷

总结

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

以上就是良许教程网为各位朋友分享的Linux系统相关内容。想要了解更多Linux相关知识记得关注公众号“良许Linux”,或扫描下方二维码进行关注,更多干货等着你 !

img
本文由 良许Linux教程网 发布,可自由转载、引用,但需署名作者且注明文章出处。如转载至微信公众号,请在文末添加作者公众号二维码。
良许

作者: 良许

良许,世界500强企业Linux开发工程师,公众号【良许Linux】的作者,全网拥有超30W粉丝。个人标签:创业者,CSDN学院讲师,副业达人,流量玩家,摄影爱好者。
上一篇
下一篇

发表评论

联系我们

联系我们

公众号:良许Linux

在线咨询: QQ交谈

邮箱: yychuyu@163.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部