一 什么是RAID0
RAID0,将数据分为几半,写到多个磁盘 A :A1 A2…… 性能提升。最小需要两个磁盘。
将多个磁碟合并成一个大的磁碟,不具有冗余,并行I/O,速度最快。RAID 0亦称为带区集。它是将多个磁盘并列起来,成为一个大磁盘。在存放数据时,其将数据按磁盘的个数来进行分段,然后同时将这些数据写进这些盘中,所以在所有的级别中,RAID 0的速度是最快的。但是RAID 0没有冗余功能,如果一个磁盘(物理)损坏,则所有的数据都会丢失,危险程度与JBOD相当。
理论上越多的磁碟效能就等于“单一磁碟效能”ד磁碟数”,但实际上受限于汇流排I/O瓶颈及其它因素的影响,RAID效能会随边际递减,也就是说,假设一个磁碟的效能是50MB每秒,两个磁碟的RAID 0效能约96MB每秒,三个磁碟的RAID 0也许是130MB每秒而不是150MB每秒,所以两个磁碟的RAID 0最能明显感受到效能的提升。
但如果是以软体方式来实作RAID,则磁碟的空间则不见得受限于此(例如Linux Software RAID),透过软体实作可以经由不同的组合而善用所有的磁碟空间。
二 RAID0演示
第一步 对磁盘进行分区
[root@serv01 /]# ls /dev/sdb
/dev/sdb
[root@serv01 /]# ls /dev/sdc
/dev/sdc
[root@serv01 /]# ls /dev/sdb* /dev/sdc* -l
brw-rw----. 1 root disk 8, 16 Jul 31 23:20/dev/sdb
brw-rw----. 1 root disk 8, 17 Jul 31 23:20/dev/sdb1
brw-rw----. 1 root disk 8, 32 Jul 31 23:21/dev/sdc
brw-rw----. 1 root disk 8, 33 Jul 31 23:21/dev/sdc1
#分区:只分一个区(/dev/sdb),注意需要把分区类型改为fd(t,fd)
#Linux raid autodetect:fd
[root@serv01 /]# fdisk /dev/sdb
#分区:只分一个区(/dev/sdc),注意需要把分区类型改为fd(t,fd)
[root@serv01 /]# fdisk /dev/sdc
[root@serv01 /]# fdisk -l | grep -e sdb -esdc
Disk /dev/sdb: 2147 MB, 2147483648 bytes
/dev/sdb1 1 261 2096451 fd Linux raid autodetect
Disk /dev/sdc: 2147 MB, 2147483648 bytes
/dev/sdc1 1 261 2096451 fd Linux raid autodetect
#安装mdadm——软RAID的实现
[root@serv01 /]# yum install /sbin/mdadm -y
[root@serv01 /]# ls /dev/sdb*
/dev/sdb /dev/sdb1
[root@serv01 /]# ls /dev/sdc*
/dev/sdc /dev/sdc1
#创建RAID
[root@serv01 /]# mdadm --create /dev/md0--level 0 --raid-devices=2 /dev/sdb1 /dev/sdc1
mdadm: /dev/sdb1 appears to contain anext2fs file system
size=208812K mtime=Wed Jul 3122:17:43 2013
mdadm: /dev/sdb1 appears to be part of araid array:
level=raid0 devices=0 ctime=Thu Jan 1 07:00:00 1970
mdadm: partition table exists on /dev/sdb1but will be lost or
meaningless after creating array
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@serv01 /]# ls /dev/md0
/dev/md0
#查看/dev/md0的详细信息
[root@serv01 /]# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Wed Jul 31 23:30:26 2013
Raid Level : raid0
Array Size : 4190208 (4.00 GiB 4.29 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Wed Jul 31 23:30:26 2013
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Chunk Size : 512K
Name : serv01.host.com:0 (localto host serv01.host.com)
UUID : 1f1a007f:7ed82aa0:49722d2f:1e664330
Events : 0
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
[root@serv01 /]# cat /proc/mdstat
Personalities : [raid0]
md0 : active raid0 sdc1[1] sdb1[0]
4190208 blocks super 1.2 512k chunks
unused devices: <none>
第二步 格式化
[root@serv01 /]# mkfs.ext4 /dev/md0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
262144 inodes, 1047552 blocks
52377 blocks (5.00%) reserved for the superuser
First data block=0
Maximum filesystem blocks=1073741824
32 block groups
32768 blocks per group, 32768 fragments pergroup
8192 inodes per group
Superblock backups stored on blocks:
32768,98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (16384 blocks): mdone
Writing superblocks and filesystemaccounting information: done
This filesystem will be automaticallychecked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@serv01 /]# mount /dev/md0 /web/
[root@serv01 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.7G 1.1G 8.1G 12% /
tmpfs 188M 0 188M 0% /dev/shm
/dev/sda1 194M 25M 160M 14% /boot
/dev/sda5 4.0G 137M 3.7G 4% /opt
/dev/sr0 3.4G 3.4G 0 100% /iso
/dev/md0 4.0G 72M 3.7G 2% /web
[root@serv01 /]# vim /etc/fstab
[root@serv01 /]# echo "/dev/md0 /webext4 defaults 1 2" >> /etc/fstab
[root@serv01 /]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Jul 2300:54:37 2013
#
# Accessible filesystems, by reference, aremaintained under '/dev/disk'
# See man pages fstab(5), findfs(8),mount(8) and/or blkid(8) for more info
#
UUID=110fab7c-85c4-4bae-9114-98bc2ada24d8/ ext4 defaults 1 1
UUID=ab434325-bf02-48e9-8ce7-78494a8ac71e/boot ext4 defaults 1 2
UUID=02ed2b3b-b7e1-493d-9a43-8e1dcac8aa6f/opt ext4 defaults 1 2
UUID=a088a35a-16d8-456a-a177-95c769c16e41swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/md0 /web ext4 defaults 1 2
第三步 重启后更名的解决及演示RAID0的应用
#然后重启,发现错误
#查看,发现已经更名
[root@serv01 ~]# ls /dev/md
md/ md127
[root@serv01 ~]# mdadm --manage /dev/md127--stop
mdadm: stopped /dev/md127
[root@serv01 ~]# ls /dev/md
md-device-map
[root@serv01 ~]# mdadm --datail /dev/md0
mdadm: unrecognized option '--datail'
Usage: mdadm --help
forhelp
#查看RAID状态,发现没有使用
[root@serv01 ~]# cat /proc/mdstat
Personalities : [raid0]
unused devices: <none>
#固定名字,然后启动RAID
[root@serv01 ~]# mdadm --assemble /dev/md0/dev/sdb1 /dev/sdc1
mdadm: /dev/md0 has been started with 2drives.
#查看状态,已经启动了
[root@serv01 ~]# cat /proc/mdstat
Personalities : [raid0]
md0 : active raid0 sdb1[0] sdc1[1]
4190208 blocks super 1.2 512k chunks
unused devices: <none>
#将RAID的信息保存到配置文件
[root@serv01 ~]# mdadm --detail —scan >/etc/mdadm.conf
#然后输入设备的挂载信息
[root@serv01 ~]# echo "/dev/md0 /webext4 defaults 1 2" >> /etc/fstab
#然后重启
[root@serv01 ~]# reboot
[root@larrywen 0731]# ssh 192.168.1.11
root@192.168.1.11's password:
Last login: Wed Jul 31 23:43:44 2013 from192.168.1.1
[root@serv01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.7G 1.1G 8.1G 12% /
tmpfs 188M 0 188M 0% /dev/shm
/dev/sda1 194M 25M 160M 14% /boot
/dev/sda5 4.0G 137M 3.7G 4% /opt
/dev/md0 4.0G 72M 3.7G 2% /web
/dev/sr0 3.4G 3.4G 0 100% /iso
[root@serv01 ~]# cat /proc/mdstat
Personalities : [raid0]
md0 : active raid0 sdb1[0] sdc1[1]
4190208 blocks super 1.2 512k chunks
unused devices: <none>
#发现正常
[root@serv01 ~]# ls /dev/md
md/ md0
#磁盘大小不一样,按照小的,比如一个磁盘是1G,另一个是2G,那么真正有用的只有1G
#RAID0:一块坏了,另一块就无法使用
[root@serv01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.7G 1.1G 8.1G 12% /
tmpfs 188M 0 188M 0% /dev/shm
/dev/sda1 194M 25M 160M 14% /boot
/dev/sda5 4.0G 137M 3.7G 4% /opt
/dev/md0 4.0G 72M 3.7G 2% /web
/dev/sr0 3.4G 3.4G 0 100% /iso
[root@serv01 ~]# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated.It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0xf85ef5bd
Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 fd Linux raid autodetect
Command (m for help): o
Building a new DOS disklabel with diskidentifier 0xc29e300a.
Changes will remain in memory only, untilyou decide to write them.
After that, of course, the previous contentwon't be recoverable.
Warning: invalid flag 0x0000 of partitiontable 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated.It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition tablefailed with error 16: Device or resource busy.
The kernel still uses the old table. Thenew table will be used at
the next reboot or after you runpartprobe(8) or kpartx(8)
Syncing disks.
[root@serv01 ~]# fdisk -l|/dev/sdb1
-bash: /dev/sdb1: Permission denied
Disk /dev/sdd doesn't contain a validpartition table
Disk /dev/sde doesn't contain a validpartition table
Disk /dev/sdf doesn't contain a validpartition table
Disk /dev/sdg doesn't contain a validpartition table
Disk /dev/md0 doesn't contain a validpartition table
[root@serv01 ~]# fdisk -l|/dev/sdb
-bash: /dev/sdb: Permission denied
Disk /dev/sdd doesn't contain a validpartition table
Disk /dev/sde doesn't contain a validpartition table
Disk /dev/sdf doesn't contain a validpartition table
Disk /dev/sdg doesn't contain a validpartition table
Disk /dev/md0 doesn't contain a validpartition table
#重启发现提示你是否进入修复模式
#重新挂载根分区
mount -o remount,rw /
#删除配置的RAID,然后重启
#重新查看,然后发现RAID已经不能使用了
[root@larrywen 0731]# ssh 192.168.1.11
root@192.168.1.11's password:
Last login: Wed Jul 31 23:49:41 2013 from192.168.1.1
[root@serv01 ~]# cat /proc/mdstat
Personalities : [raid0]
md0 : inactive sdc1[1]
2095104 blocks super 1.2
unused devices: <none>
[root@serv01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.7G 1.1G 8.1G 12% /
tmpfs 188M 0 188M 0% /dev/shm
/dev/sda1 194M 25M 160M 14% /boot
/dev/sda5 4.0G 137M 3.7G 4% /opt
/dev/sr0 3.4G 3.4G 0 100% /iso
[root@serv01 ~]# mdadm --detail /dev/md
md/ md0
[root@serv01 ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Wed Jul 31 23:30:26 2013
Raid Level : raid0
Raid Devices : 2
Total Devices : 1
Persistence : Superblock is persistent
Update Time : Wed Jul 31 23:30:26 2013
State : active, FAILED, Not Started
Active Devices : 1
Working Devices : 1
Failed Devices : 0
Spare Devices : 0
Chunk Size : 512K
Name : serv01.host.com:0 (localto host serv01.host.com)
UUID : 1f1a007f:7ed82aa0:49722d2f:1e664330
Events : 0
Number Major Minor RaidDevice State
0 0 0 0 removed
1 8 33 1 active sync /dev/sdc1
第四步 实验完毕,清理磁盘
#清理数据,做RAID必须做如下操作
#首先停掉RAID
[root@serv01 ~]# mdadm --manage /dev/md0--stop
mdadm: stopped /dev/md0
[root@serv01 ~]# rm -rf /etc/mdadm.conf
[root@serv01 ~]# mdadm -E /dev/sdb1
mdadm: cannot open /dev/sdb1: No such fileor directory
#检测发现有残留信息
[root@serv01 ~]# mdadm -E /dev/sdc1
/dev/sdc1:
Magic : a92b4efc
Version : 1.2
Feature Map : 0x0
Array UUID : 1f1a007f:7ed82aa0:49722d2f:1e664330
Name : serv01.host.com:0 (localto host serv01.host.com)
Creation Time : Wed Jul 31 23:30:26 2013
Raid Level : raid0
Raid Devices : 2
Avail Dev Size : 4190854 (2046.66 MiB 2145.72MB)
Data Offset : 2048 sectors
Super Offset : 8 sectors
State : clean
Device UUID : 7e3d4caf:35001960:b95d9eae:19fa3093
Update Time : Wed Jul 31 23:30:26 2013
Checksum : 64b18466 - correct
Events : 0
Chunk Size : 512K
Device Role : Active device 1
Array State : AA ('A' == active, '.' == missing)
#清空磁盘
[root@serv01 ~]# mdadm --misc—zero-superblock /dev/sdc1
[root@serv01 ~]# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated.It's strongly recommended to
switch off the mode (command 'c') andchange display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-261, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G}(1-261, default 261):
Using default value 261
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@serv01 ~]# mdadm -E /dev/sdb1
/dev/sdb1:
Magic : a92b4efc
Version : 1.2
Feature Map : 0x0
Array UUID : 1f1a007f:7ed82aa0:49722d2f:1e664330
Name : serv01.host.com:0 (localto host serv01.host.com)
Creation Time : Wed Jul 31 23:30:26 2013
Raid Level : raid0
Raid Devices : 2
Avail Dev Size : 4190854 (2046.66 MiB 2145.72MB)
Data Offset : 2048 sectors
Super Offset : 8 sectors
State : clean
Device UUID : f76937d2:74ac3af1:506bed88:795c81ed
Update Time : Wed Jul 31 23:30:26 2013
Checksum : 4d5dcd15 - correct
Events : 0
Chunk Size : 512K
Device Role : Active device 0
Array State : AA ('A' == active, '.' == missing)
#清空磁盘
[root@serv01 ~]# mdadm --misc--zero-superblock /dev/sdb1
mdadm: Couldn't open /dev/sdb1 for write -not zeroing
[root@serv01 ~]# cat /proc/mdstat
Personalities : [raid0]
md0 : inactive sdb1[0](S)
2095427 blocks super 1.2
unused devices: <none>
root@serv01 ~]# mdadm --manage /dev/md0--stop
mdadm: stopped /dev/md0
[root@serv01 ~]# mdadm --misc--zero-superblock /dev/sdb1
[root@serv01 ~]#
[root@serv01 ~]# mdadm -E /dev/sdb1
/dev/sdb1:
MBR Magic : aa55
[root@serv01 ~]# mdadm -E /dev/sdc1
mdadm: No md superblock detected on/dev/sdc1.
三 参考资料
http://zh.wikipedia.org/wiki/RAID
四 相关文章
我的邮箱:wgbno27@163.com 新浪微博:@Wentasy27 微信公众平台:JustOracle(微信号:justoracle) 数据库技术交流群:336882565(加群时验证 From CSDN XXX) Oracle交流讨论组:https://groups.google.com/d/forum/justoracle By Larry Wen
![]() | ![]() ![]() |
@Wentasy 博文仅供参考,欢迎大家来访。如有错误之处,希望批评指正。原创博文如需转载请注明出处,谢谢 :) [CSDN博客] |