内容:
1. LVM条带化简介
2. LV条带化前后数据存储结构探究
LVM的条带化:
描述:
为了性能考虑,考虑将数据跨越多个磁盘上存储,即把LV上连续的数据分成大小相同的块,然后依次存储在各个磁盘PV上,类似于RAID-0的数据存放形式,实现数据读写的并发;管理员依据自己的数据需求,定义数据分块大小,分布PV磁盘个数信息,从而实现读写的性能最佳化;
但是如RAID-0一样,这样带来的数据丢失的危险性也增大,因此的实际的生产活动中,实际数据后台是基于RAID-1或RAID-5的做过了数据冗余形式;所以条带化后即使有PV硬盘损坏,也能数据保证数据不丢失。当然仅仅的用几个磁盘组成VG,然后条带化建立LV,这样数据是危险的;所以选择基于RAID的条带化(镜像的条带化);
注:没有条带化的LVM存储数据时是按顺序进行的,在一个PV划分LV完毕后再从下一个PV中划分空间;
示意图:
简单的条带化:
基于RAID的条带化:
条带化实现:
- [root@bogon ~]# pvcreate /dev/sd{b,c,d,e}1
- Physical volume "/dev/sdb1" successfully created
- Physical volume "/dev/sdc1" successfully created
- # 创建VG:
- [root@bogon ~]# vgcreate vg0 /dev/sd[bc]1
- Volume group "vg0" successfully created
- # 创建条带化的LV:
- [root@bogon ~]# lvcreate -L 1G -n test2 -i 2 -I 64 vg0
- Logical volume "test2" created
- # -i 指定跨PV的个数
- # -I 指定条带单元的大小
条带单元(stripe size):即条带单元的大小,对应于I/O中数据单元块的大小;数值必须为2的幂,单位KB;
探究条带化数据存储形式:
1. 非条带化时:
- # 此时VG0由两个PV:sdb1、sdc1构成:
- [root@bogon ~]# vgdisplay
- --- Volume group ---
- VG Name vg0
- System ID
- Format lvm2
- Metadata Areas 2
- 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 2
- Act PV 2
- VG Size 3.73 GB
- PE Size 4.00 MB #默认的PE为4M
- Total PE 956 #总PE个数为956个
- Alloc PE / Size 0 / 0 #分出的PE个数/大小
- Free PE / Size 956 / 3.73 GB #空闲的PE个数/大小
- VG UUID vAAETX-iGO9-jNUl-qIle-kLFR-F0y8-nIRR3F
- # 创建一个1G的LV:
- [root@bogon ~]# lvcreate -L 1G -n test1 vg0
- Logical volume "test1" created
- # 查看该LV状态:
- [root@bogon ~]# lvdisplay
- --- Logical volume ---
- LV Name /dev/vg0/test1
- VG Name vg0
- LV UUID XIltjY-VKVh-eqUH-YkZx-kxRb-aisu-TNqrXQ
- LV Write Access read/write
- LV Status available
- # open 0 #使用状态,表示是否正在挂载使用;
- LV Size 1.00 GB #LV大小
- Current LE 256 #LE(Logical extentes)数量对应于PE
- Segments 1
- Allocation inherit
- Read ahead sectors auto
- - currently set to 256
- Block device 253:1
- [root@bogon ~]# vgdisplay
- --- Volume group ---
- VG Name vg0
- System ID
- Format lvm2
- Metadata Areas 2
- Metadata Sequence No 2
- VG Access read/write
- VG Status resizable
- MAX LV 0
- Cur LV 1
- Open LV 0
- Max PV 0
- Cur PV 2
- Act PV 2
- VG Size 3.73 GB
- PE Size 4.00 MB
- Total PE 956
- Alloc PE / Size 256 / 1.00 GB #此时PE已经分出了256个,大小是1G
- Free PE / Size 700 / 2.73 GB #空闲的PE及为划分的剩余空间
- VG UUID vAAETX-iGO9-jNUl-qIle-kLFR-F0y8-nIRR3F
- [root@bogon ~]# pvdisplay
- --- Physical volume ---
- PV Name /dev/sdb1
- VG Name vg0
- PV Size 1.87 GB / not usable 1.96 MB
- Allocatable yes
- PE Size (KByte) 4096
- Total PE 478 #PV中总PE块数
- Free PE 222 #PV中空闲的PE块数
- Allocated PE 256 #已经分出的PE数量:256*4M=1G
- PV UUID NeBQU9-4TGz-Dp1y-nGq1-M25t-vdQ7-oYzsEj
- --- Physical volume ---
- PV Name /dev/sdc1
- VG Name vg0
- PV Size 1.87 GB / not usable 1.96 MB
- Allocatable yes
- PE Size (KByte) 4096
- Total PE 478 #总PE数
- Free PE 478 #对应上面的
- Allocated PE 0 #对应上面的已分配空间
- PV UUID LRmTY8-J066-bOXu-dlee-7VTM-ELMg-n3NIbP
由上面可以从看出:不条带化时,划分LV是顺序划分的,所以数据肯定也顺序存储了;只有在一个PV磁盘存储完毕,才会使用下一个PV;
2. 条带化时:
- # 先清除一下上面非条带化时数据;
- [root@bogon ~]# lvremove /dev/vg0/test1
- Do you really want to remove active logical volume test1? [y/n]: y
- Logical volume "test1" successfully removed
- # 建立条带化的LV:
- [root@bogon ~]# lvcreate -L 1G -n test2 -i 2 -I 64 vg0
- Logical volume "test2" created
- # -i 指定跨PV的个数为2
- # -I 指定条带单元的大小为64KB
- [root@bogon ~]# lvdisplay
- --- Logical volume ---
- LV Name /dev/vg0/test2
- VG Name vg0
- LV UUID Eceigt-gLe1-x1lW-3vyi-l6Rx-HM2r-i4F6vw
- LV Write Access read/write
- LV Status available
- # open 0
- LV Size 1.00 GB
- Current LE 256 # 256*4M=1G
- Segments 1
- Allocation inherit
- Read ahead sectors auto
- - currently set to 512
- Block device 253:1
- [root@bogon ~]# vgdisplay
- --- Volume group ---
- VG Name vg0
- System ID
- Format lvm2
- Metadata Areas 2
- Metadata Sequence No 4
- VG Access read/write
- VG Status resizable
- MAX LV 0
- Cur LV 1
- Open LV 0
- Max PV 0
- Cur PV 2
- Act PV 2
- VG Size 3.73 GB
- PE Size 4.00 MB
- Total PE 956
- Alloc PE / Size 256 / 1.00 GB # 整个VG中已分配出去256个PE块
- Free PE / Size 700 / 2.73 GB
- VG UUID vAAETX-iGO9-jNUl-qIle-kLFR-F0y8-nIRR3F
- [root@bogon ~]# pvdisplay
- --- Physical volume ---
- PV Name /dev/sdb1
- VG Name vg0
- PV Size 1.87 GB / not usable 1.96 MB
- Allocatable yes
- PE Size (KByte) 4096
- Total PE 478
- Free PE 350
- Allocated PE 128 # 此时,在sdb1整个PV上划分出了128个PE块
- PV UUID NeBQU9-4TGz-Dp1y-nGq1-M25t-vdQ7-oYzsEj
- --- Physical volume ---
- PV Name /dev/sdc1
- VG Name vg0
- PV Size 1.87 GB / not usable 1.96 MB
- Allocatable yes
- PE Size (KByte) 4096
- Total PE 478
- Free PE 350
- Allocated PE 128 # 此时,在sdb1整个PV上划分出了128个PE块
- PV UUID LRmTY8-J066-bOXu-dlee-7VTM-ELMg-n3NIbP
由上面数据:条带化时,LV会跨多个PV磁盘,数据存储在PV上循环存储;
拓展:
条带化后,LV扩展机制是怎么样的,是否因为存储形式的不同需要对PV增加个数有限制?!(待续,做实验,出来结果跟预期有差距...o(╯□╰)o)