通常以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请求能被一次性处理完成。
大概的条带化的概念就是这样。node
先看本机中的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的测试,先用前三块硬盘建立vg01app
[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的可用空间。ide
[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扩容,先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个。ui
[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,可是结果是失败的,提示不够用。this
[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个。spa
[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
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.
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