一、条带化的概念
一般以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块。
[[email protected] ~]# vgscan Reading all physical volumes. This may take a while... Found volume group "vg00" using metadata type lvm2
将每块硬盘做为一个PV,先全部执行完成。为了一会做lvextend的测试,先用前三块硬盘创建vg01
[[email protected] ~]# 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 [[email protected] ~]# vgcreate /dev/vg01 /dev/sdd /dev/sde /dev/sdf Volume group "vg01" successfully created [[email protected] ~]# 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的可用空间。
[[email protected] ~]# lvcreate -i 3 -I 64 -l 1533 -n stripe_lv vg01 Logical volume "stripe_lv" created [[email protected] ~]# 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
执行格式化和挂载
[[email protected] ~]# 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. [[email protected] ~]# mkdir /stripe [[email protected] ~]# mount /dev/vg01/stripe_lv /stripe/ [[email protected] ~]# 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的原理就知道了,抽象地说,数据分成大小相同的数据块,然后依次存储在每块硬盘,如果要扩大,必然要每块硬盘都相应扩大。此处先只增加一块硬盘看是否可以。
[[email protected] ~]# vgextend /dev/vg01 /dev/sdg Volume group "vg01" successfully extended
增加硬盘后,可以看到vg size变大为7.98G,并且PE数量变为2044,pv数量变为4个。
[[email protected] ~]# 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,但是结果是失败的,提示不够用。
[[email protected] ~]# 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个。
[[email protected] ~]# 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。
[[email protected] ~]# 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 [[email protected] ~]# 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个成功,就不晓得了~~~但从结果知道,其实并没有增加
[[email protected] ~]# 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倍。
[[email protected] ~]# vgextend /dev/vg01 /dev/sdh /dev/sdi Volume group "vg01" successfully extended [[email protected] ~]# 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的角度扩展,均提示成功。
[[email protected] ~]# 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 [[email protected] ~]# 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. [[email protected] ~]# 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 [[email protected] ~]# 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 [[email protected] ~]# 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. [[email protected] ~]# 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
查看大小
[[email protected] ~]# 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/homevollvextend -- 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 initiallvextend
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