- 论坛徽章:
- 0
|
RAID1
1、硬盘分区
[root@localhost ~]# fdisk /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 1
First cylinder (1-261, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261):
Using default value 261
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 5 Extended
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1-261, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261): 87
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 5 Extended
/dev/sdb5 1 87 698764+ 83 Linux
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (88-261, default 88):
Using default value 88
Last cylinder or +size or +sizeM or +sizeK (88-261, default 261): 174
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 5 Extended
/dev/sdb5 1 87 698764+ 83 Linux
/dev/sdb6 88 174 698796 83 Linux
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (175-261, default 175):
Using default value 175
Last cylinder or +size or +sizeM or +sizeK (175-261, default 261):
Using default value 261
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 5 Extended
/dev/sdb5 1 87 698764+ 83 Linux
/dev/sdb6 88 174 698796 83 Linux
/dev/sdb7 175 261 698796 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
2、将sdb5,6,7分区标志为raid类型
[root@localhost ~]# fdisk /dev/sdb
Command (m for help): t
Partition number (1-7): 5
Hex code (type L to list codes): fd
Changed system type of partition 5 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-7): 6
Hex code (type L to list codes): fd
Changed system type of partition 6 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-7): 7
Hex code (type L to list codes): fd
Changed system type of partition 7 to fd (Linux raid autodetect)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3、创建raid1设备及定义raid盘
[root@localhost ~]# mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/sdb{5,6,7}
mdadm: array /dev/md0 started.
4、查看raid1的情况
[root@localhost ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 0.90
Creation Time : Wed Dec 30 05:45:22 2009
Raid Level : raid1
Array Size : 698688 (682.43 MiB 715.46 MB)
Used Dev Size : 698688 (682.43 MiB 715.46 MB)
Raid Devices : 2
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Wed Dec 30 05:45:28 2009
State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
UUID : 44013808:89fc5658:2729b6e0:1ee871b0
Events : 0.2
Number Major Minor RaidDevice State
0 8 21 0 active sync /dev/sdb5
1 8 22 1 active sync /dev/sdb6
2 8 23 - spare /dev/sdb7
5、格式化raid1设备
[root@localhost ~]# mke2fs -j /dev/md0
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
87360 inodes, 174672 blocks
8733 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=180355072
6 block groups
32768 blocks per group, 32768 fragments per group
14560 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840
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.
6、将raid设备每次重启都生效
[root@localhost ~]# mdadm -D -s > /etc/mdadm.conf
[root@localhost ~]# cat /etc/mdadm.conf
ARRAY /dev/md0 level=raid1 num-devices=2 metadata=0.90 spares=1 UUID=44013808:89fc5658:2729b6e0:1ee871b0
7、让raid设备每次重启自动挂载
[root@localhost ~]# vi /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/opt /opt ext3 defaults 1 2
LABEL=/var /var ext3 defaults 1 2
LABEL=/home /home ext3 defaults 1 2
LABEL=/boot /boot ext3 defaults 1 2
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
LABEL=SWAP-sda7 swap swap defaults 0 0
/dev/md0 /mnt/raid1 ext3 defaults 0 0
8、模拟让sdb5这个分区出故障,并查看raid设备的情况
[root@localhost mnt]# mdadm /dev/md0 -f /dev/sdb5
mdadm: set /dev/sdb5 faulty in /dev/md0
[root@localhost mnt]# mdadm --detail /dev/md0
/dev/md0:
Version : 0.90
Creation Time : Wed Dec 30 05:45:22 2009
Raid Level : raid1
Array Size : 698688 (682.43 MiB 715.46 MB)
Used Dev Size : 698688 (682.43 MiB 715.46 MB)
Raid Devices : 2
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Wed Dec 30 05:51:35 2009
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 1
Spare Devices : 0
UUID : 44013808:89fc5658:2729b6e0:1ee871b0
Events : 0.6
Number Major Minor RaidDevice State
0 8 23 0 active sync /dev/sdb7
1 8 22 1 active sync /dev/sdb6
2 8 21 - faulty spare /dev/sdb5
这里发现以前的hot盘sdb7替代了故障盘sdb5
9、将故障分区sdb5从raid1设备中删除,并再次查看raid的情况
[root@localhost mnt]# mdadm /dev/md0 -r /dev/sdb5
mdadm: hot removed /dev/sdb5
[root@localhost mnt]# mdadm --detail /dev/md0
/dev/md0:
Version : 0.90
Creation Time : Wed Dec 30 05:45:22 2009
Raid Level : raid1
Array Size : 698688 (682.43 MiB 715.46 MB)
Used Dev Size : 698688 (682.43 MiB 715.46 MB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Wed Dec 30 05:53:01 2009
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
UUID : 44013808:89fc5658:2729b6e0:1ee871b0
Events : 0.8
Number Major Minor RaidDevice State
0 8 23 0 active sync /dev/sdb7
1 8 22 1 active sync /dev/sdb6
10、添加一个好的分区sdb8到raid设备中,并查看raid情况
[root@localhost mnt]# mdadm /dev/md0 -a /dev/sdb8
mdadm: added /dev/sdb8
[root@localhost mnt]# mdadm --detail /dev/md0
/dev/md0:
Version : 0.90
Creation Time : Wed Dec 30 05:45:22 2009
Raid Level : raid1
Array Size : 698688 (682.43 MiB 715.46 MB)
Used Dev Size : 698688 (682.43 MiB 715.46 MB)
Raid Devices : 2
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Wed Dec 30 05:53:01 2009
State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
UUID : 44013808:89fc5658:2729b6e0:1ee871b0
Events : 0.8
Number Major Minor RaidDevice State
0 8 23 0 active sync /dev/sdb7
1 8 22 1 active sync /dev/sdb6
2 8 21 - spare /dev/sdb8
RAID5
1,2步骤见上面raid1,此处略
3、创建raid1设备及定义raid盘
[root@localhost ~]# mdadm -C /dev/md0 -a yes -l 5 -n 2 -x 1 /dev/sdb{5,6,7}
mdadm: /dev/sdb5 appears to contain an ext2fs file system
size=698688K mtime=Wed Dec 30 05:49:28 2009
mdadm: /dev/sdb5 appears to be part of a raid array:
level=raid1 devices=2 ctime=Wed Dec 30 05:45:22 2009
mdadm: /dev/sdb6 appears to contain an ext2fs file system
size=698688K mtime=Thu Jan 1 08:00:00 1970
mdadm: /dev/sdb6 appears to be part of a raid array:
level=raid1 devices=2 ctime=Wed Dec 30 05:45:22 2009
mdadm: /dev/sdb7 appears to contain an ext2fs file system
size=698688K mtime=Thu Jan 1 08:00:00 1970
mdadm: /dev/sdb7 appears to be part of a raid array:
level=raid1 devices=2 ctime=Wed Dec 30 05:45:22 2009
Continue creating array? y
mdadm: array /dev/md0 started.
[root@localhost ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 0.90
Creation Time : Wed Dec 30 07:04:53 2009
Raid Level : raid5
Array Size : 698688 (682.43 MiB 715.46 MB)
Used Dev Size : 698688 (682.43 MiB 715.46 MB)
Raid Devices : 2
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Wed Dec 30 07:05:13 2009
State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 64K
UUID : d83ca10c:df98f84c:89bf706a:03e510d9
Events : 0.2
Number Major Minor RaidDevice State
0 8 21 0 active sync /dev/sdb5
1 8 22 1 active sync /dev/sdb6
2 8 23 - spare /dev/sdb7
4,5,6,7,8,9,10步骤见上面raid1
1:创建一个RAID设备,在RHEL 5中RAID设备必须从md0开始依次增加。
2:同意创建设备,如不加此参数时必须先使用mknod /dev/md1 b 9 0命令来创建一个RAID设备,不过推荐使用-a yes参数一次性创建。
3:RAID级别,此处定义的是RAID 1。
4:使用几个分区实现RAID。
5:热备分区的个数。当定义一些具有容错功能的RAID级别(RAID1、RAID5)时,可多定义一块或热备分区,这样当RAID阵列中有1块硬盘损坏时,这个热备分区会自动补上去开始工作。
6:加入RAID的分区。
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/93765/showart_2180545.html |
|