关于linux:Centos8中创建LVM精简逻辑卷

6次阅读

共计 6532 个字符,预计需要花费 17 分钟才能阅读完成。

精简卷是能够创立大于可用磁盘的逻辑卷。应用精简卷,你能够治理可用空间的存储池(称为精简池),能够在应用程序须要时将其调配给任意数量的设施。精简池能够在须要时进行动静扩大,以节省成本。
零碎环境
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 两个精简卷:
www.pcpop.com/doc/4/4517/4517127.shtml
mb.it168.com/a2016/1014/2975/000002975988.shtml
news.163.com/17/0612/12/CMNU7FP500018AOP.html

[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/lv… 编辑:逄增宝,审核员:逄增宝

正文完
 0