lvm 條帶化

1、條帶化的概念

通常以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

2、條帶化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的測試,先用前三塊硬盤建立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


3、條帶化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個。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

 

無覓相關文章插件,快速提高流量

 

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
相關文章
相關標籤/搜索