Raid陣列和lvm邏輯卷組主要用于磁盤備份和擴充,其中Raid用于磁盤備份,lvm用于磁盤空間管理。
一:Raid工作原理。
1.軟Raid比較常用的有Raid0、Raid1、Raid5和Raid10,Raid0最少隻要一塊硬碟即可:如果多塊硬碟的話資料會呈帶狀分布在各個硬碟上(如圖)。因為不提供備援,是以Raid0是所有Raid方案中讀/寫速度最快的,但完全沒有容錯能力,任何一塊硬碟損壞都會使整個Raid失效,安全性較低
<a href="http://blog.51cto.com/attachment/201301/005922855.png" target="_blank"></a>
2.Raid1也至少需要2塊硬碟,互為鏡像,一個工作一個備份(如上圖),是Raid的方案中安全性最高的。
3.Raid5是在Raid0的基礎上加了校驗,沒有備份功能;當一塊硬碟壞後Raid5會利用其他剩下的資料和相應的校驗資訊去回複損壞的資料。
<a href="http://blog.51cto.com/attachment/201301/005946953.png" target="_blank"></a>
4.Raid10是結合了Raid0和Raid1,既增加了硬碟的讀/寫速度還有備份的功能。但Raid10最少需要4塊硬碟(如上圖)。
二:LVM的工作原理:
1.LVM是邏輯盤卷管理(LogicalVolumeManager)的簡稱,它是Linux環境下對磁盤分區進行管理的一種機制,LVM是建立在硬碟和分區之上的一個邏輯層,來提高磁盤分區管理的靈活性。通過LVM系統管理者可以輕松管理磁盤分區,如:将若幹個磁盤分區連接配接為一個整塊的卷組 (volumegroup),形成一個存儲池。管理者可以在卷組上随意建立邏輯卷組(logicalvolumes),并進一步在邏輯卷組上建立檔案系統。管理者通過LVM可以友善的調整存儲卷組的大小,并且可以對磁盤存儲按照組的方式進行命名、管理和配置設定,例如按照使用用途進行定義: “development”和“sales”,而不是使用實體磁盤名“sda”和“sdb”。而且當系統添加了新的磁盤,通過LVM管理者就不必将磁盤的檔案移動到新的磁盤上以充分利用新的存儲空間,而是直接擴充檔案系統跨越磁盤即可。
2.LVM的相關術語:
*實體存儲媒體(The physical media)
這裡指系統的儲存設備:硬碟,如:/dev/hda1、/dev/sda等等,是存儲系統最低層的
存儲單元。
* 實體卷(physical volume)
實體卷就是指硬碟分區或從邏輯上與磁盤分區具有同樣功能的裝置(如RAID),是LVM的
基本存儲邏輯塊,但和基本的實體存儲媒體(如分區、磁盤等)比較,卻包含有與LVM相
關的管理參數。
* 卷組(Volume Group)
卷組是LVM 中最高抽象層,是由一個或多個實體卷所組成的存儲器池。
* 邏輯卷(logical volume)
邏輯卷相當于非LVM 系統中的分區,它在卷組上建立,是一個标準的塊裝置,可以在其上
建立檔案系統(比如/home或者/usr等)。
* 實體塊 PE(physical extent)
每一個實體卷被劃分為稱為PE(Physical Extents)的基本單元,具有唯一編号的PE是
可以被LVM尋址的最小單元。PE的大小是可配置的,預設為4MB。
* 邏輯塊LE(logical extent)
邏輯塊也被劃分為被稱為LE(Logical Extents) 的可被尋址的基本機關。在同一個卷
組中,LE的大小和PE是相同的,并且一一對應。
注:卷組(vg)、邏輯卷(lv)、實體卷(pv)、邏輯塊(le)、實體塊(pe)的關系如圖:
<a href="http://blog.51cto.com/attachment/201301/010019207.png" target="_blank"></a>
從上圖可以看到,PE和LE有着一一對應的關系。邏輯卷建立在卷組上。邏輯卷就相當于
非LVM系統的磁盤分區,可以在其上建立檔案系統。
下圖是磁盤分區、卷組、邏輯卷和檔案系統之間的邏輯關系的示意圖:
<a href="http://blog.51cto.com/attachment/201301/010044154.png" target="_blank"></a>
3.建立LVM邏輯卷的一般步驟:
(1)建立分區 (2)建立實體卷 (3)建立卷組 (4)激活卷組 (5)建立邏輯卷 (6)
建立檔案系統 (7)挂載使用
案例一:使用磁盤分區建立邏輯卷
1.檢視系統中的硬碟:
[root@lyt ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2610 20860402+ 8e Linux LVM
Disk /dev/sdb: 21.4 GB, 21474836480 bytes
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/sdc: 21.4 GB, 21474836480 bytes
Disk /dev/sdc doesn't contain a valid partition table
Disk /dev/sdd: 21.4 GB, 21474836480 bytes
Disk /dev/sdd doesn't contain a valid partition table
Disk /dev/sde: 21.4 GB, 21474836480 bytes
Disk /dev/sde doesn't contain a valid partition table
2.給磁盤建立分區:
在/dev/sdb上建立兩個分區(其他磁盤同樣操作,這裡不再列出)
[root@lyt ~]# fdisk /dev/sdb
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): +200M
Partition number (1-4): 2
First cylinder (26-2610, default 26):
Using default value 26
Last cylinder or +size or +sizeM or +sizeK (26-2610, default 2610): +200M
Command (m for help): p
/dev/sdb1 1 25 200781 83 Linux
/dev/sdb2 26 50 200812+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@lyt ~]#
3.更改磁盤分區類型:
(其他磁盤同樣操作,這裡不再列出)
Command (m for help): t
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Changed system type of partition 2 to 8e (Linux LVM)
/dev/sdb1 1 25 200781 8e Linux LVM
/dev/sdb2 26 50 200812+ 8e Linux LVM
4.将建好的分區轉換成實體卷(pv)
[root@lyt ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
[root@lyt ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created
[root@lyt ~]# pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created
[root@lyt ~]# pvcreate /dev/sdc2
Physical volume "/dev/sdc2" successfully created
[root@lyt ~]# pvcreate /dev/sdd1
Physical volume "/dev/sdd1" successfully created
[root@lyt ~]# pvcreate /dev/sdd2
Physical volume "/dev/sdd2" successfully created
5.建立卷組
[root@lyt ~]# vgcreate vgtest /dev/sdb1 /dev/sdb2 /dev/sdc1 /dev/sdc2 /dev/sdd1 /dev/sdd2 #卷組名是vgtest
/dev/cdrom: open failed: Read-only file system
Attempt to close device '/dev/cdrom' which is not open.
Volume group "vgtest" successfully created
6.在卷組的基礎上建立邏輯卷
[root@lyt ~]# lvcreate -L 1G -n lvtest vgtest #-L表示大小,這裡大小是1G,-n表示名字,這裡名字是lvtest
Logical volume "lvtest" created
7.格式化邏輯卷
[root@lyt ~]# mkfs -t ext3 /dev/vgtest/lvtest #格式化的檔案系統是ext3
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
131072 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
8.挂載
[root@lyt ~]# mkdir /lvdate
[root@lyt ~]# mount /dev/vgtest/lvtest /lvdate/ #挂載
[root@lyt ~]# ll /lvdate/
total 16
drwx------ 2 root root 16384 Dec 23 22:57 lost+found
[root@lyt ~]# df -h /lvdate/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vgtest-lvtest
1008M 34M 924M 4% /lvdate
本文轉自 liuyatao666 51CTO部落格,原文連結:http://blog.51cto.com/5503845/1123453,如需轉載請自行聯系原作者