AS4+Raid

创建 RAID5
Linux 下使用 mdadm 创建和管理软 raid 注:本次操作以 RHEL4 为例,但应该可以应用到其它大部分的 distro 上( guess )。
mdadm 的几个常用参数
-C 创建 Raid ,后面跟参数,代表 raid 设备的名称。比如: /dev/md0 /dev/md1 大写
-n 用于创建磁盘阵列的磁盘个数。                                                小写
-l Raid 的级别。                                                                小写
-x 指定用于 hotspare (热备盘)的磁盘个数。如果阵列中有一块硬盘坏了,它会立刻顶上,并 rebuild
-D 显示软 raid 的详细信息;                                                     大写
-s 扫描配置文件( /etc/mdadm.conf )或 ''/proc/mdstat'' 来查看遗漏的信息 f      小写
创建软 raid 的大体流程
使用 fdisk 工具为新磁盘创建分区;
使用 mkfs.XXXX 工具将刚才划分好的分区格式化成某种格式的文件系统。比如: ext3 reiserfs 等;
    (此处的格式化可以在 raid 创建后再格式化)
使用 mdadm 来创建软 raid
创建 /etc/mdadm.conf 文件(注意文件的格式,包括是否有逗号等等。该文件是为了系统在重启后能够自动启用软 raid 。可以查看 /etc/rc.sysinit 脚本,搜索 ''mdadm'' 字符串就明白了);
示例:创建软 raid5 +hotspare )以下是我的一次实际操作的完整过程:
这是用 ''fdisk -l'' 命令查看到的我当前的磁盘和分区情况(只有 /dev/sda 在使用,其它四个都是新磁盘,没有分区,没有格式化):
# fdisk -l

Disk /dev/sda: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 720 5783368+ 83 Linux
/dev/sda2 721 783 506047+ 82 Linux swap

Disk /dev/sdb: 214 MB, 214748160 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Disk /dev/sdb doesn''t contain a valid partition table

Disk /dev/sdc: 214 MB, 214748160 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Disk /dev/sdc doesn''t contain a valid partition table

Disk /dev/sdd: 214 MB, 214748160 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Disk /dev/sdd doesn''t contain a valid partition table

Disk /dev/sde: 214 MB, 214748160 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Disk /dev/sde doesn''t contain a valid partition table
使用 fdisk 创建分区(本例中将整块磁盘划分为一个主分区。其余几块磁盘也做相同的操作。):
# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won''t be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help):
n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4):
1
First cylinder (1-204, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-204, default 204):
Using default value 204

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
为刚才新建的分区建立文件系统(其余几个分区依次做相同的操作):
# mkfs.ext3 /dev/sdb1     // 该步骤在 raid 创建后在执行
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
52416 inodes, 208880 blocks
10444 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
26 block groups
8192 blocks per group, 8192 fragments per group
2016 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
所有磁盘都操作完后,再次用 ''fdisk -l'' 查看磁盘及分区状态:
# fdisk -l

Disk /dev/sda: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 720 5783368+ 83 Linux
/dev/sda2 721 783 506047+ 82 Linux swap

Disk /dev/sdb: 214 MB, 214748160 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 204 208880 83 Linux

Disk /dev/sdc: 214 MB, 214748160 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Device Boot Start End Blocks Id System
/dev/sdc1 1 204 208880 83 Linux

Disk /dev/sdd: 214 MB, 214748160 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Device Boot Start End Blocks Id System
/dev/sdd1 1 204 208880 83 Linux

Disk /dev/sde: 214 MB, 214748160 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Device Boot Start End Blocks Id System
/dev/sde1 1 204 208880 83 Linux
 
使用 mdadm 创建一个软 raid raid 级别: 5 ;并有一个 hotspare 盘:
# mdadm -C /dev/md0 -l5 -n3 -x1 /dev/sd[b-e]1
mdadm: array /dev/md0 started.
输出信息显示软 raid(/dev/md0) 已经启用了。使用 mdadm -D 参数( --detail )可以查看软 raid 状态:
# mdadm -D /dev/md0
/dev/md0:
Version : 00.90.01
Creation Time : Wed Aug 23 15:10:19 2006
Raid Level : raid5
Array Size : 417536 (407.75 MiB 427.56 MB)
Device Size : 208768 (203.88 MiB 213.78 MB)
Raid Devices : 3
Total Devices : 4
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Wed Aug 23 15:10:21 2006
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1

Layout : left-symmetric
Chunk Size : 64K

Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
2 8 49 2 active sync /dev/sdd1
3 8 65 -1 spare /dev/sde1
UUID : f8283de5: 39c 73d89:b9fbc266:fdceb416
Events : 0.2
生成配置文件( /etc/mdadm.conf ):
# mdadm -D -s >/etc/mdadm.conf
查看一下:
# cat /etc/mdadm.conf
ARRAY /dev/md0 level=raid5 num-devices=3 UUID=f8283de5:39c73d89:b9fbc266:fdceb416
devices=/dev/sdb1,/dev/sdc1,/dev/sdd1,/dev/sde1
修改(把上面 devices= 后面的磁盘,都放到 DEVICE 后面,并且不要逗号。而 /dev/md0 之后的内容,都要用逗号来分隔):
DEVICE /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
ARRAY /dev/md0 level=raid5,num-devices=3,UUID=f8283de5:39c73d89:b9fbc266:fdceb416
重启一下,检测配置好的软 raid 是否能够在系统重启后自动启用。
重启后,查看 ''/proc/mdstat'' 文件就可以看到软 raid 的状态:
# cat /proc/mdstat
Personalities : [raid5]
md0 : active raid5 sdb1[0] sde1[3] sdd1[2] sdc1[1]
417536 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]

unused devices: <none>
That''s all.
出现故障后的恢复这里指的出现故障,是指 raid 中的一块磁盘出现了故障,无法使用。这时候需要使用额外的磁盘来代替它。这里以强制将某块磁盘标记为已损坏,来模拟实际出现故障(注:新的磁盘的容量最好和已损坏的磁盘一致):
/dev/sdb1 标记为已损坏:
# mdadm /dev/md0 -f /dev/sdb1
mdadm: set /dev/sdb1 faulty in /dev/md0
这时候使用 mdadm -D 参数来查看状态,可以看到 /dev/sdb1 已经被认为是 faulty ,而 hotspare (热备)盘 ''/dev/sde1'' 已经顶替了它的位置(这就是 hotspare 的作用):
# mdadm -D /dev/md0
/dev/md0:
Version : 00.90.01
Creation Time : Wed Aug 23 15:10:19 2006
Raid Level : raid5
Array Size : 417536 (407.75 MiB 427.56 MB)
Device Size : 208768 (203.88 MiB 213.78 MB)
Raid Devices : 3
Total Devices : 4
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Wed Aug 23 15:42:24 2006
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 1
Spare Devices : 0

Layout : left-symmetric
Chunk Size : 64K

Number Major Minor RaidDevice State
0 8 65 0 active sync /dev/sde1
1 8 33 1 active sync /dev/sdc1
2 8 49 2 active sync /dev/sdd1
3 8 17 -1 faulty /dev/sdb1
UUID : f8283de5: 39c 73d89:b9fbc266:fdceb416
Events : 0.4
既然 ''/dev/sdb1'' 出现了故障,当然就要将它移除:
# mdadm /dev/md0 -r /dev/sdb1
mdadm: hot removed /dev/sdb1
现在可以关机了。关机之后拔下这块已损坏的磁盘了,换上你的新磁盘。换好之后,分区, mkfs.XXXX 。然后将它加入到软 raid 中:
# mdadm /dev/md0 -a /dev/sdb1
mdadm: hot added /dev/sdb1
这时候再使用 mdadm ''-D'' 参数,可以看到 sdb1 已经作为 hotspare 盘了:
# mdadm -D /dev/md0
/dev/md0:
Version : 00.90.01
Creation Time : Wed Aug 23 15:10:19 2006
Raid Level : raid5
Array Size : 417536 (407.75 MiB 427.56 MB)
Device Size : 208768 (203.88 MiB 213.78 MB)
Raid Devices : 3
Total Devices : 4
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Wed Aug 23 16:19:36 2006
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1

Layout : left-symmetric
Chunk Size : 64K

Number Major Minor RaidDevice State
0 8 65 0 active sync /dev/sde1
1 8 33 1 active sync /dev/sdc1
2 8 49 2 active sync /dev/sdd1
3 8 17 -1 spare /dev/sdb1
UUID : f8283de5: 39c 73d89:b9fbc266:fdceb416
Events : 0.6
misc
假如创建了 RAID ,但是没有生成 /etc/mdadm.conf 文件,那么系统重启后是不会启用 RAID 的,这时候需要这样做:
# mdadm -A /dev/md0 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
 
vi /etc/fstab
/dev/md0    /backuppc    defaults   0 0
mount -v
 
 
 

本文出自 “小黑技术交流群” 博客,转载请与作者联系!

你可能感兴趣的:(linux,职场,休闲)