software RAID 筆記

tonykorn97發表於2008-07-18

1,software RAID Configuration
Create and define RAID devices using mdadm
mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/sda1 /dev/sdb1 /dev/sdc1

-l: raid級別
-n: 硬碟數
-x: 熱備份硬碟數

format each RAID device with a filesystem
mke2fs -j /dev/md0

test the RAID devices
mdadm allows you to check the status of your RAID devices
mdadm --detail /dev/md0[@more@]

2,software RAID testing and recovery
simulating disk failures
mdadm /dev/md0 -f /dev/sda1
(模擬sda1硬碟壞 )

recovering from a software RAID disk failure
replace the failed hard drive and power on
reconstruct partitions on the replacement drive

增加新硬碟
mdadm /dev/md0 -a /dev/sda1
刪除硬碟
mdadm /dev/md0 -r /dev/sda1

mdadm,/proc/mdstat,and syslog messages


例子:
1,準備的分割槽資訊
/dev/sda5 1864 1988 1004031 83 Linux
/dev/sda6 1989 2113 1004031 83 Linux
/dev/sda7 2114 2238 1004031 83 Linux


2,建立陣列
[root@tonykorn97 ~]# mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/sda{5,6,7}
mdadm: /dev/sda5 appears to contain an ext2fs file system
size=1004028K mtime=Sun May 18 06:03:36 2008
Continue creating array? y
mdadm: array /dev/md0 started.

此時fdisk 可以檢視到/dev/md0分割槽
[root@tonykorn97 ~]# fdisk -l
...
Disk /dev/md0: 1027 MB, 1027997696 bytes
2 heads, 4 sectors/track, 250976 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

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


3,格式化分割槽並掛載
[root@tonykorn97 ~]# mkfs.ext3 /dev/md0
...
[root@tonykorn97 ~]# mkdir /data
[root@tonykorn97 ~]# mount /dev/md0 /data

4,檢視當前raid資訊
[root@tonykorn97 ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.03
Creation Time : Sun Jul 13 10:15:49 2008
Raid Level : raid1
Array Size : 1003904 (980.54 MiB 1028.00 MB)
Device Size : 1003904 (980.54 MiB 1028.00 MB)
Raid Devices : 2
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Sun Jul 13 10:17:27 2008
State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1

UUID : 95695625:471aa8d7:1d74ab8c:1224f36e
Events : 0.2

Number Major Minor RaidDevice State
0 8 5 0 active sync /dev/sda5
1 8 6 1 active sync /dev/sda6

2 8 7 - spare /dev/sda7
[root@tonykorn97 ~]#


4,模擬一個硬碟壞
[root@tonykorn97 ~]# mdadm --fail /dev/md0 /dev/sda5
mdadm: set /dev/sda5 faulty in /dev/md0

此時raid的狀態
[root@tonykorn97 ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.03
Creation Time : Sun Jul 13 10:15:49 2008
Raid Level : raid1
Array Size : 1003904 (980.54 MiB 1028.00 MB)
Device Size : 1003904 (980.54 MiB 1028.00 MB)
Raid Devices : 2
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Sun Jul 13 10:20:03 2008
State : clean, degraded, recovering
Active Devices : 1
Working Devices : 2
Failed Devices : 1
Spare Devices : 1

Rebuild Status : 41% complete

UUID : 95695625:471aa8d7:1d74ab8c:1224f36e
Events : 0.4

Number Major Minor RaidDevice State
2 8 7 0 spare rebuilding /dev/sda7
1 8 6 1 active sync /dev/sda6

3 8 5 - faulty spare /dev/sda5
[root@tonykorn97 ~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sda7[2] sda6[1] sda5[3](F)
1003904 blocks [2/1] [_U]
[============>........] recovery = 64.6% (649344/1003904) finish=0.2min speed=20946K/sec

unused devices:
[root@tonykorn97 ~]#

陣列用備用盤代替壞掉硬碟後的狀態:
[root@tonykorn97 ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.03
Creation Time : Sun Jul 13 10:15:49 2008
Raid Level : raid1
Array Size : 1003904 (980.54 MiB 1028.00 MB)
Device Size : 1003904 (980.54 MiB 1028.00 MB)
Raid Devices : 2
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Sun Jul 13 10:20:53 2008
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 1
Spare Devices : 0

UUID : 95695625:471aa8d7:1d74ab8c:1224f36e
Events : 0.6

Number Major Minor RaidDevice State
0 8 7 0 active sync /dev/sda7
1 8 6 1 active sync /dev/sda6

2 8 5 - faulty spare /dev/sda5
[root@tonykorn97 ~]#


移出這個出問題的磁碟:
[root@tonykorn97 ~]# mdadm --remove /dev/md0 /dev/sda5
mdadm: hot removed /dev/sda5
[root@tonykorn97 ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.03
Creation Time : Sun Jul 13 10:15:49 2008
Raid Level : raid1
Array Size : 1003904 (980.54 MiB 1028.00 MB)
Device Size : 1003904 (980.54 MiB 1028.00 MB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Sun Jul 13 10:23:11 2008
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

UUID : 95695625:471aa8d7:1d74ab8c:1224f36e
Events : 0.8

Number Major Minor RaidDevice State
0 8 7 0 active sync /dev/sda7
1 8 6 1 active sync /dev/sda6
[root@tonykorn97 ~]#


新增硬碟
[root@tonykorn97 ~]# mdadm -a /dev/md0 /dev/sda5
mdadm: added /dev/sda5
You have new mail in /var/spool/mail/root
[root@tonykorn97 ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.03
Creation Time : Sun Jul 13 10:15:49 2008
Raid Level : raid1
Array Size : 1003904 (980.54 MiB 1028.00 MB)
Device Size : 1003904 (980.54 MiB 1028.00 MB)
Raid Devices : 2
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Sun Jul 13 10:23:45 2008
State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1

UUID : 95695625:471aa8d7:1d74ab8c:1224f36e
Events : 0.8

Number Major Minor RaidDevice State
0 8 7 0 active sync /dev/sda7
1 8 6 1 active sync /dev/sda6

2 8 5 - spare /dev/sda5
[root@tonykorn97 ~]#


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/312079/viewspace-1007484/,如需轉載,請註明出處,否則將追究法律責任。

相關文章