[转帖]LVM条带化

lvm,条带 · 浏览次数 : 0

小编点评

Sure, here's a summary of the content you provided: **LV Creation**: * `lvextend -L+1G /dev/myvg/homevol` extends a logical volume by 1 GB. * `lvextend -l +100%FREE /dev/myvg/testlv` extends a logical volume to fill all available space. **Striped Volume**: * For striped logical volumes, additional physical volumes must be added to the group to create a stripe. * The maximum size of the stripe is equal to the available space in the underlying physical volumes. **Extending Logical Volume Size**: * Use `lvextend` with the `-l` option to specify the desired size of the logical volume. * Use the `-i` option to specify a percentage of the volume group or the amount of free space to extend. **Adding Physical Volumes**: * Use `vgextend` to extend the logical volume with more physical volumes. * The available space is determined by the underlying physical volumes. **Note**: * By default, file system resizing tools resize the file system to match the size of the underlying logical volume. * Adding space to the logical volume only affects the specified stripe if the volume is striped.

正文

一、条带化的概念

一般以LVM管理的存储,一个vg中可能会有很多pv,同样的,一个lv可能跨越多块pv,为了使硬盘存储速度加快,就会用到条带化的技术,即把连续的数据分成大小相同的数据块,然后依次存储在各个pv上。类似于RAID0,使存储速度加快。但并不会使数据像RAID0一样危险容易丢失,因为在正式使用中,不会像此时做测试一样没有任何保障地将多块硬盘做成一个vg,而是普遍连接的后台存储,在划分LUN之前,已经在物理硬盘上做好RAID5或RAID1,在RAID5或RAID1的基础上再划分出多块LUN,即系统上的pv,即使pv所在硬盘损坏,但有底层的硬RAID冗余,并不会丢失数据。
条带单元大小:即条带化的LV中,每一个条带单元的大小,对应于I/O中数据块的大小。对于Oracle来讲,db_block_size即设定的数据块大小。而db_file_multiblock_read_count就一次读取时最多并行的数据块的个数,db_block_size和db_file_multiblock_read_count相乘即一次总的I/O大小。这个大小不能超过操作系统的最大I/O (max_io_size)值。在ORACLE应用中,lv条带的大小一般设置为两倍或两倍以上的Oracle块大小,因为假如设置成与Oracle数据块相同大小,无法保证Oracle数据块的边界正好与条带单元的边界对应,如果不对应的话,就会出现大量的一个I/O由两个条带单元,来处理的情况。
条带大小的原则:对于高并发并且IO请求小的情况下,一块物理硬盘处理多个I/O请求,低并发但I/O请求较大时,可能需要多块硬盘处理一个I/O请求。原则上的要求是一次I/O请求能被一次性处理完成。
大概的条带化的概念就是这样。

二、条带化lv的创建

先看本机中的VG情况,只有一个vg00,物理硬盘个数是从/dev/sdd到/dev/sdi一共6块。

[root@dbabc.net ~]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "vg00" using metadata type lvm2

将每块硬盘做为一个PV,先全部执行完成。为了一会做lvextend的测试,先用前三块硬盘创建vg01

[root@dbabc.net ~]# pvcreate /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh /dev/sdi
  Physical volume "/dev/sdd" successfully created
  Physical volume "/dev/sde" successfully created
  Physical volume "/dev/sdf" successfully created
  Physical volume "/dev/sdg" successfully created
  Physical volume "/dev/sdh" successfully created
  Physical volume "/dev/sdi" successfully created
[root@dbabc.net ~]# vgcreate /dev/vg01 /dev/sdd /dev/sde /dev/sdf
  Volume group "vg01" successfully created
[root@dbabc.net ~]# vgdisplay vg01
  --- Volume group ---
  VG Name               vg01
  System ID
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               5.99 GB
  PE Size               4.00 MB
  Total PE              1533
  Alloc PE / Size       0 / 0
  Free  PE / Size       1533 / 5.99 GB
  VG UUID               W6EwVP-YIva-iCqr-KuZf-B3jt-4cA3-4XcSv4

再创建条带化的lv,下面用到的lvextend的参数如下:
-i:此处写lv用到的pv的数量,不能超过所在vg的pv数量,一般设置与vg的pv个数相同
-I:条带单元大小,单位Kb
-L:lv的大小,默认为Mb,可带单位G,M,K
-l:小写L,分配给lv的LE个数,对应于VG中的PE,在上条vgdisplay的输出中可看到VG中一共有1533个PE。
-n:自定义lv的名字,默认从lvol0开始往下排。
为了下面测试条带化下的lvextend,所以将此vg的所有空间都给这个lv,即1533个LE,一共5.99G的可用空间。

[root@dbabc.net ~]# lvcreate -i 3 -I 64 -l 1533 -n stripe_lv vg01
  Logical volume "stripe_lv" created
[root@dbabc.net ~]# lvdisplay /dev/vg01/stripe_lv
  --- Logical volume ---
  LV Name                /dev/vg01/stripe_lv
  VG Name                vg01
  LV UUID                TyF4aW-gegH-Vmxi-hWUl-a7t7-Vw5V-B64Eik
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                5.99 GB
  Current LE             1533
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     768
  Block device           253:4

执行格式化和挂载

[root@dbabc.net ~]# mkfs.ext3 /dev/vg01/stripe_lv
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
784896 inodes, 1569792 blocks
78489 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1610612736
48 block groups
32768 blocks per group, 32768 fragments per group
16352 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@dbabc.net ~]# mkdir /stripe
[root@dbabc.net ~]# mount /dev/vg01/stripe_lv /stripe/
[root@dbabc.net ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg00-lv_root 6.0G 398M 5.3G 7% /
/dev/mapper/vg00-lv_usr 6.8G 1.7G 4.8G 26% /usr
/dev/mapper/vg00-lv_data 93M 5.6M 83M 7% /data
/dev/sdc1 988M 24M 914M 3% /boot
/dev/mapper/vg01-stripe_lv 5.9G 141M 5.5G 3% /stripe

三、条带化lv的扩展

然后测试给此条带化的lv扩容,先vgextend,再lvextend.
条带化的lv扩展需要新增pv的时候,有个重要条件,增加的pv数量必须与lv现有的pv数量相同或成倍数关系。想想RAID0的原理就知道了,抽象地说,数据分成大小相同的数据块,然后依次存储在每块硬盘,如果要扩大,必然要每块硬盘都相应扩大。此处先只增加一块硬盘看是否可以。

[root@dbabc.net ~]# vgextend /dev/vg01 /dev/sdg
  Volume group "vg01" successfully extended

增加硬盘后,可以看到vg size变大为7.98G,并且PE数量变为2044,pv数量变为4个。

[root@dbabc.net ~]# vgdisplay /dev/vg01
  --- Volume group ---
  VG Name               vg01
  System ID
  Format                lvm2
  Metadata Areas        4
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                4
  Act PV                4
  VG Size               7.98 GB
  PE Size               4.00 MB
  Total PE              2044
  Alloc PE / Size       1533 / 5.99 GB
  Free  PE / Size       511 / 2.00 GB
  VG UUID               W6EwVP-YIva-iCqr-KuZf-B3jt-4cA3-4XcSv4

因为有2G的可用空间,此处试着增加100M,但是结果是失败的,提示不够用。

[root@dbabc.net ~]# lvextend -L+100 /dev/vg01/stripe_lv
  Using stripesize of last segment 64.00 KB
  Rounding size (1558 extents) down to stripe boundary size for segment (1557 extents)
  Extending logical volume stripe_lv to 6.08 GB
  Insufficient suitable allocatable extents for logical volume stripe_lv: 24 more required

然后再以LE的方式增加,一共有511个可用的PE,即最大应该可增加511个LE,此处只增加10个仍然失败,提示需要额外的9个。

[root@dbabc.net ~]# lvextend -l+10 /dev/vg01/stripe_lv
  Using stripesize of last segment 64.00 KB
  Rounding size (1543 extents) down to stripe boundary size for segment (1542 extents)
  Extending logical volume stripe_lv to 6.02 GB
  Insufficient suitable allocatable extents for logical volume stripe_lv: 9 more required

看起来增加1个应该可以,每次执行也都提示成功。但是每次都提示增加到1534个LE。

[root@dbabc.net ~]# lvextend -l+1 /dev/vg01/stripe_lv
  Using stripesize of last segment 64.00 KB
  Rounding size (1534 extents) down to stripe boundary size for segment (1533 extents)
  Extending logical volume stripe_lv to 5.99 GB
  Logical volume stripe_lv successfully resized
[root@dbabc.net ~]# lvextend -l+1 /dev/vg01/stripe_lv
  Using stripesize of last segment 64.00 KB
  Rounding size (1534 extents) down to stripe boundary size for segment (1533 extents)
  Extending logical volume stripe_lv to 5.99 GB
  Logical volume stripe_lv successfully resized

然后以lvdisplay查看,LE的数量仍为1533,并未增加。至于为何会显示增加1个成功,就不晓得了~~~但从结果知道,其实并没有增加

[root@dbabc.net ~]# lvdisplay /dev/vg01/stripe_lv
  --- Logical volume ---
  LV Name                /dev/vg01/stripe_lv
  VG Name                vg01
  LV UUID                TyF4aW-gegH-Vmxi-hWUl-a7t7-Vw5V-B64Eik
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                5.99 GB
  Current LE             1533
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     768
  Block device           253:4

再把剩余的另外2个pv加上,就一共增加了3个pv,正好与vg01的原pv数量相同,成倍数关系。此时vg01的pv个数变成了6个,是原来的2倍。

[root@dbabc.net ~]# vgextend /dev/vg01 /dev/sdh /dev/sdi
  Volume group "vg01" successfully extended
[root@dbabc.net ~]# vgdisplay /dev/vg01
  --- Volume group ---
  VG Name               vg01
  System ID
  Format                lvm2
  Metadata Areas        6
  Metadata Sequence No  7
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                6
  Act PV                6
  VG Size               11.98 GB
  PE Size               4.00 MB
  Total PE              3066
  Alloc PE / Size       1788 / 6.98 GB
  Free  PE / Size       1278 / 4.99 GB
  VG UUID               W6EwVP-YIva-iCqr-KuZf-B3jt-4cA3-4XcSv4

再用lvextend扩展空间,分别从LE和SIZE的角度扩展,均提示成功。

[root@dbabc.net ~]# lvextend -L+1024 /dev/vg01/stripe_lv
  Using stripesize of last segment 64.00 KB
  Rounding size (1789 extents) down to stripe boundary size for segment (1788 extents)
  Extending logical volume stripe_lv to 6.98 GB
  Logical volume stripe_lv successfully resized
[root@dbabc.net ~]# resize2fs /dev/vg01/stripe_lv
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/vg01/stripe_lv is mounted on /stripe; on-line resizing required
Performing an on-line resize of /dev/vg01/stripe_lv to 1830912 (4k) blocks.
The filesystem on /dev/vg01/stripe_lv is now 1830912 blocks long.
[root@dbabc.net ~]# lvdisplay /dev/vg01/stripe_lv
  --- Logical volume ---
  LV Name                /dev/vg01/stripe_lv
  VG Name                vg01
  LV UUID                TyF4aW-gegH-Vmxi-hWUl-a7t7-Vw5V-B64Eik
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                6.98 GB
  Current LE             1788
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     768
  Block device           253:4
[root@dbabc.net ~]# lvextend -l+1278 /dev/vg01/stripe_lv
  Using stripesize of last segment 64.00 KB
  Extending logical volume stripe_lv to 11.98 GB
  Logical volume stripe_lv successfully resized
[root@dbabc.net ~]# resize2fs /dev/vg01/stripe_lv
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/vg01/stripe_lv is mounted on /stripe; on-line resizing required
Performing an on-line resize of /dev/vg01/stripe_lv to 3139584 (4k) blocks.
The filesystem on /dev/vg01/stripe_lv is now 3139584 blocks long.
[root@dbabc.net ~]# lvdisplay /dev/vg01/stripe_lv
  --- Logical volume ---
  LV Name                /dev/vg01/stripe_lv
  VG Name                vg01
  LV UUID                TyF4aW-gegH-Vmxi-hWUl-a7t7-Vw5V-B64Eik
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                11.98 GB
  Current LE             3066
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     768
  Block device           253:4

查看大小

[root@dbabc.net ~]# df -h
Filesystem                    Size   Used Avail Use% Mounted on
/dev/mapper/vg00-lv_root      6.0G  398M  5.3G   7% /
/dev/mapper/vg00-lv_usr       6.8G  1.7G  4.8G  26% /usr
/dev/mapper/vg00-lv_data       93M  5.6M   83M   7% /data
/dev/sdc1                    988M    24M  914M   3% /boot
/dev/mapper/vg01-stripe_lv 12.0G  141M  11.6G   97% /stripe

 

无觅相关文章插件,快速提升流量

 

4.4.12. Growing Logical Volumes

To increase the size of a logical volume, use the  lvextend command.
When you extend the logical volume, you can indicate how much you want to extend the volume, or how large you want it to be after you extend it.
The following command extends the logical volume  /dev/myvg/homevol to 12 gigabytes.
# lvextend -L12G /dev/myvg/homevol 
lvextend -- extending logical volume "/dev/myvg/homevol" to 12 GB
lvextend -- doing automatic backup of volume group "myvg"
lvextend -- logical volume "/dev/myvg/homevol" successfully extended
The following command adds another gigabyte to the logical volume  /dev/myvg/homevol.
# lvextend -L+1G /dev/myvg/homevol
lvextend -- extending logical volume "/dev/myvg/homevol" to 13 GB
lvextend -- doing automatic backup of volume group "myvg"
lvextend -- logical volume "/dev/myvg/homevol" successfully extended
As with the  lvcreate command, you can use the  -l argument of the  lvextend command to specify the number of extents by which to increase the size of the logical volume. You can also use this argument to specify a percentage of the volume group, or a percentage of the remaining free space in the volume group. The following command extends the logical volume called  testlv to fill all of the unallocated space in the volume group  myvg.
[root@tng3-1 ~]# lvextend -l +100%FREE /dev/myvg/testlv
  Extending logical volume testlv to 68.59 GB
  Logical volume testlv successfully resized
After you have extended the logical volume it is necessary to increase the file system size to match.
By default, most file system resizing tools will increase the size of the file system to be the size of the underlying logical volume so you do not need to worry about specifying the same size for each of the two commands.

4.4.12.1. Extending a Striped Volume

In order to increase the size of a striped logical volume, there must be enough free space on the underlying physical volumes that make up the volume group to support the stripe. For example, if you have a two-way stripe that that uses up an entire volume group, adding a single physical volume to the volume group will not enable you to extend the stripe. Instead, you must add at least two physical volumes to the volume group.
For example, consider a volume group  vg that consists of two underlying physical volumes, as displayed with the following  vgs command.
# vgs
  VG   #PV #LV #SN Attr   VSize   VFree
  vg     2   0   0 wz--n- 271.31G 271.31G
You can create a stripe using the entire amount of space in the volume group.
# lvcreate -n stripe1 -L 271.31G -i 2 vg
  Using default stripesize 64.00 KB
  Rounding up size to full physical extent 271.31 GB
  Logical volume "stripe1" created
# lvs -a -o +devices
  LV      VG   Attr   LSize   Origin Snap%  Move Log Copy%  Devices
  stripe1 vg   -wi-a- 271.31G                               /dev/sda1(0),/dev/sdb1(0)
Note that the volume group now has no more free space.
# vgs
  VG   #PV #LV #SN Attr   VSize   VFree
  vg     2   1   0 wz--n- 271.31G    0
The following command adds another physical volume to the volume group, which then has 135G of additional space.
# vgextend vg /dev/sdc1
  Volume group "vg" successfully extended
# vgs
  VG   #PV #LV #SN Attr   VSize   VFree
  vg     3   1   0 wz--n- 406.97G 135.66G
At this point you cannot extend the striped logical volume to the full size of the volume group, because two underlying devices are needed in order to stripe the data.
# lvextend vg/stripe1 -L 406G
  Using stripesize of last segment 64.00 KB
  Extending logical volume stripe1 to 406.00 GB
  Insufficient suitable allocatable extents for logical volume stripe1: 34480 
more required
To extend the striped logical volume, add another physical volume and then extend the logical volume. In this example, having added two physical volumes to the volume group we can extend the logical volume to the full size of the volume group.
# vgextend vg /dev/sdd1
  Volume group "vg" successfully extended
# vgs
  VG   #PV #LV #SN Attr   VSize   VFree
  vg     4   1   0 wz--n- 542.62G 271.31G
# lvextend vg/stripe1 -L 542G
  Using stripesize of last segment 64.00 KB
  Extending logical volume stripe1 to 542.00 GB
  Logical volume stripe1 successfully resized
If you do not have enough underlying physical devices to extend the striped logical volume, it is possible to extend the volume anyway if it does not matter that the extension is not striped, which may result in uneven performance. When adding space to the logical volume, the default operation is to use the same striping parameters of the last segment of the existing logical volume, but you can override those parameters. The following example extends the existing striped logical volume to use the remaining free space after the initial lvextend command fails.
# lvextend vg/stripe1 -L 406G
  Using stripesize of last segment 64.00 KB
  Extending logical volume stripe1 to 406.00 GB
  Insufficient suitable allocatable extents for logical volume stripe1: 34480 
more required
# lvextend -i1 -l+100%FREE vg/stripe1
文章知识点与官方知识档案匹配,可进一步学习相关知识
CS入门技能树Linux入门初识Linux23889 人正在系统学习中

与[转帖]LVM条带化相似的内容:

[转帖]LVM条带化

一、条带化的概念 一般以LVM管理的存储,一个vg中可能会有很多pv,同样的,一个lv可能跨越多块pv,为了使硬盘存储速度加快,就会用到条带化的技术,即把连续的数据分成大小相同的数据块,然后依次存储在各个pv上。类似于RAID0,使存储速度加快。但并不会使数据像RAID0一样危险容易丢失,因为在正式

[转帖]创建lvm

https://www.jianshu.com/p/bf6b92d73b9b 一.环境介绍 服务器中有sda,sdb,sdc,sdd,sde,sdf六块硬盘,其中sda作为系统盘已经安装了系统,需要将其他5块盘建成lvm 二.创建lvm流程 1.针对5块磁盘进行分区(以sdb为例) fdisk /d

[转帖]一张图让你学会LVM

http://blog.itpub.net/69955379/viewspace-2901403/ Linux操作系统 作者:大雄45 时间:2022-11-18 01:13:44 292 0 导读 随着科技的进步,人们不知不觉的就进入了大数据的时代,数据的不断增加我们发现我们的磁盘越来越不够用了,

[转帖]磁盘读速度巨慢使用arcconf工具调整后的二次优化

情况叙述:lvm文件系统出现损坏,格式为xfs,磁盘修复失败后该节点需要重新格式化处理,格式化后重新划分pv,vg,lv,做完之后应用反应读写的速度达不到应用使用的要求,与正常的相比速度不稳定 现象:time和dd测试速度后发现写的速度为10-20MB/s 解决1:yy3:~ # chmod +x

[转帖]Linux磁盘二次格式化后写入速度巨慢之解决方案

https://blog.csdn.net/hellfu/article/details/109127640 磁盘sdc格式化做成lvm后,写入速度不稳定,大多数在5M/s一下。 echo 512 >/sys/block/sdc/queue/nr_requests 本来cat /sys/block/

[转帖]ssd/san/sas/磁盘/光纤/RAID性能比较

https://plantegg.github.io/2022/01/25/ssd_san%E5%92%8Csas%E7%A3%81%E7%9B%98%E6%80%A7%E8%83%BD%E6%AF%94%E8%BE%83/ 本文汇总HDD、SSD、SAN、LVM、软RAID等一些性能数据 性能比较

[转帖]从VMware ESXI主机在线扩容到虚拟机磁盘扩容

一、需求 虚拟机磁盘空间不足,需要扩容,ESXI主机未接存储,且虚拟机磁盘模式均为“厚置备延迟置零”,主机仅剩余16GB存储空间,无法满足扩容需求,需要为ESXI主机的磁盘组进行扩容。 操作过程:插入物理磁盘–>配置磁盘RAID–>ESXI存储扩容–>虚拟机添加硬盘–>linux lvm扩容。 整个

[转帖]

Linux ubuntu20.04 网络配置(图文教程) 因为我是刚装好的最小系统,所以很多东西都没有,在开始配置之前需要做下准备 环境准备 系统:ubuntu20.04网卡:双网卡 网卡一:供连接互联网使用网卡二:供连接内网使用(看情况,如果一张网卡足够,没必要做第二张网卡) 工具: net-to

[转帖]

https://cloud.tencent.com/developer/article/2168105?areaSource=104001.13&traceId=zcVNsKTUApF9rNJSkcCbB 前言 Redis作为高性能的内存数据库,在大数据量的情况下也会遇到性能瓶颈,日常开发中只有时刻

[转帖]ISV 、OSV、 SIG 概念

ISV 、OSV、 SIG 概念 2022-10-14 12:29530原创大杂烩 本文链接:https://www.cndba.cn/dave/article/108699 1. ISV: Independent Software Vendors “独立软件开发商”,特指专门从事软件的开发、生产、