本篇内容介绍了“Centos8中怎么创建LVM的精简逻辑卷”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

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

系统环境

Centos8

创建精简池

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

[root@localhost~]#pvcreate/dev/sdaPhysicalvolume"/dev/sda"successfullycreated.[root@localhost~]#vgcreatevg_thin/dev/sdaVolumegroup"vg_thin"successfullycreated[root@localhost~]#vgsVG#PV#LV#SNAttrVSizeVFreecl120wz--n-

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

[root@localhost~]#lvcreate-L1G-Tvg_thin/thin_poolThinpoolvolumewithchunksize64.00KiBcanaddressatmost15.81TiBofdata.Logicalvolume"thin_pool"created.[root@localhost~]#lvsLVVGAttrLSizePoolOriginData%Meta%MoveLogCpy%SyncConvertrootcl-wi-ao----15.00gswapcl-wi-ao----2.00gthin_poolvg_thintwi-a-tz--1.00g0.0010.94

创建精简卷

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

[root@localhost~]#lvcreate-V200M-Tvg_thin/thin_pool-ntp_lv_user1Logicalvolume"tp_lv_user1"created.[root@localhost~]#lvcreate-V200M-Tvg_thin/thin_pool-ntp_lv_user2Logicalvolume"tp_lv_user2"created.[root@localhost~]#lvcreate-V200M-Tvg_thin/thin_pool-ntp_lv_user3Logicalvolume"tp_lv_user3"created.[root@localhost~]#lvcreate-V200M-Tvg_thin/thin_pool-ntp_lv_user4Logicalvolume"tp_lv_user4"created.

格式化并挂载精简卷

将上面创建的四个精简卷格式化为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~]#ddif=/dev/zeroof=/mnt/user1/test.imgbs=1Mcount=100[root@localhost~]#ddif=/dev/zeroof=/mnt/user2/test.imgbs=1Mcount=100[root@localhost~]#ddif=/dev/zeroof=/mnt/user3/test.imgbs=1Mcount=100[root@localhost~]#ddif=/dev/zeroof=/mnt/user4/test.imgbs=1Mcount=100

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

[root@localhost~]#lvs

我们可以注意到精简池利用率为41.41%

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

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

[root@localhost~]#lvcreate-V200M-Tvg_thin/thin_pool-ntp_lv_user5Logicalvolume"tp_lv_user5"created.[root@localhost~]#lvcreate-V200M-Tvg_thin/thin_pool-ntp_lv_user6WARNING:Sumofallthinvolumesizes(1.17GiB)exceedsthesizeofthinpoolvg_thin/thin_pool(1.00GiB).WARNING:Youhavenotturnedonprotectionagainstthinpoolsrunningoutofspace.WARNING:Setactivation/thin_pool_autoextend_thresholdbelow100totriggerautomaticextensionofthinpoolsbeforetheygetfull.Logicalvolume"tp_lv_user6"created.

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

[root@localhost~]#lvremove-f/dev/vg_thin/tp_lv_user5Logicalvolume"tp_lv_user5"successfullyremoved[root@localhost~]#lvremove-f/dev/vg_thin/tp_lv_user6Logicalvolume"tp_lv_user6"successfullyremoved

编辑/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-V200M-Tvg_thin/thin_pool-ntp_lv_user5Logicalvolume"tp_lv_user5"created.[root@localhost~]#lvcreate-V200M-Tvg_thin/thin_pool-ntp_lv_user6Logicalvolume"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~]#lvsLVVGAttrLSizePoolOriginData%Meta%MoveLogCpy%SyncConvertrootcl-wi-ao----15.00gswapcl-wi-ao----2.00gthin_poolvg_thintwi-aotz--1.20g75.9422.66tp_lv_user1vg_thinVwi-aotz--200.00mthin_pool77.97tp_lv_user2vg_thinVwi-aotz--200.00mthin_pool77.97tp_lv_user3vg_thinVwi-aotz--200.00mthin_pool77.97tp_lv_user4vg_thinVwi-aotz--200.00mthin_pool77.97tp_lv_user5vg_thinVwi-aotz--200.00mthin_pool77.97tp_lv_user6vg_thinVwi-aotz--200.00mthin_pool77.97

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

如何扩展精简池

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

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

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

[root@localhost~]#lvs-aLVVGAttrLSizePoolOriginData%Meta%MoveLogCpy%SyncConvertrootcl-wi-ao----15.00gswapcl-wi-ao----2.00g[lvol0_pmspare]vg_thinewi-------4.00mthin_poolvg_thintwi-aotz--1.20g75.9422.66[thin_pool_tdata]vg_thinTwi-ao----1.20g[thin_pool_tmeta]vg_thinewi-ao----4.00mtp_lv_user1vg_thinVwi-aotz--200.00mthin_pool77.97tp_lv_user2vg_thinVwi-aotz--200.00mthin_pool77.97tp_lv_user3vg_thinVwi-aotz--200.00mthin_pool77.97tp_lv_user4vg_thinVwi-aotz--200.00mthin_pool77.97tp_lv_user5vg_thinVwi-aotz--200.00mthin_pool77.97tp_lv_user6vg_thinVwi-aotz--200.00mthin_pool77.97

扩展精简池metadata的大小

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

[root@localhost~]#lvextend--poolmetadatasize+4Mvg_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

删除精简卷、精简池

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

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

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

[root@localhost~]#lvs-aLVVGAttrLSizePoolOriginData%Meta%MoveLogCpy%SyncConvertrootcl-wi-ao----15.00gswapcl-wi-ao----2.00g

“Centos8中怎么创建LVM的精简逻辑卷”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!