[root@centos5 ~]#yum install -y mdadm
[root@centos5 ~]# fdisk /dev/hdb
The number of cylinders for this disk is set to 17753.
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-17753, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-17753, default 17753):
Using default value 17753 ----回车即可
Command (m for help):t ------指定磁盘格式 (L可以查看所有格式)
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect) 选择了raid格式因为我们要做raid嘛!
Command (m for help): w -----------写入
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos5 ~]# fdisk /dev/hdd 同上!
然后用 mdadm这个命令创建raid
[root@centos5 ~]# mdadm -C /dev/md0 -l0 -n2 /dev/hd[bd]1 创建raid0
这个是简写全部命令是 mdadm -C /dev/md0 --levle=raid0 --raid-devices=2 /dev/hdb1 /dev/hdd1
[root@centos5 ~]# mkfs.ext3 -t /dev/md0 格式化!
[root@centos5 ~]# mkdir -p /mnt/raid0
[root@centos5 ~]# mount /dev/md0 /mnt/raid0 挂载
[root@centos5 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/hda1 7.3G 1.8G 5.2G 26% /
tmpfs 94M 0 94M 0% /dev/shm
/dev/md0 16G 173M 15G 2% /mnt/raid0
cat /proc/mdstate
查看raid的状态呢?
mdadm -D /dev/md*
--------------------------------------------------------------------------------------------------------------------------
1、确保你的 2 块硬盘一模一样
2、fdisk 对两块硬盘分区,全部只分一个区即可,分区标识用 fd
3、假如你的系统硬盘是 sda,两块硬盘分别是 sdb 和 sdc
# mdadm -C /dev/md0 -l1 -n2 /dev/sdb1 /dev/sdc1
# mdadm -Ds > /etc/mdadm.conf
# mkfs.ext3 /dev/md0
# mount /dev/md0 /mnt/raid
4、修改你的 /etc/fstab 让系统启动后自动挂载
------------------------------------------------------------------------------------------------------------------------------
创建raid 5 的命令。
[root@centos /]# mdadm -C -v /dev/md0 -l5 -n3 /dev/sda1 /dev/sdb1 /dev/sdc1 -x1 /dev/sdd1
-------------------------------------------------------------------------------------------------------------------------------
一.停止 raid
[root@localhost media]# mdadm -S /dev/md10
mdadm: stopped /dev/md10
4.启动和停止
停止之前需要umount,然后mdadm –S /dev/md0
启动:[root@centos /]# mdadm -A /dev/md0 /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1
如果已经建立了配置文件,启动可使用命令mdadm –As /dev/md0
[root@localhost media]#
二.删除 raid
mdadm /dev/md10 --fail /dev/sde1 --remove /dev/sde1
mdadm /dev/md10 --fail /dev/sdd1 --remove /dev/sdd1
mdadm /dev/md10 --fail /dev/sdc1 --remove /dev/sdc1
mdadm /dev/md10 --fail /dev/sdb1 --remove /dev/sdb1
三.删除/dev/md10
rmdir /dev/md10
1.测试前,在/mnt/radi下建立一个文件使用
[root@centos raid]# ll / |tee ./ls.txt
mdadm自带命令可以标记某块硬盘为损坏,参看帮助mdadm --manage –h。
故障测试中,标记sda硬盘损坏
[root@centos /]# mdadm /dev/md0 -f /dev/sda1
mdadm: set /dev/sda1 faulty in /dev/md0
2.查看状态
[root@centos /]# more /proc/mdstat
Personalities : [raid5]
md0 : active raid5 sdd1[3] sdc1[2] sdb1[1] sda1[4](F)
16771584 blocks level 5, 64k chunk, algorithm 2 [3/2] [_UU]
[====>................] recovery = 22.8% (1916928/8385792) finish=1.9min speed=55892K/sec
unused devices:
[root@centos /]#
因为sdd硬盘为热备,系统显示raid重构中,进度22.8%,且sda1标记(F)。
稍等再次查看:
[root@centos/]# more /proc/mdstat
Personalities : [raid5]
md0 : active raid5 sdd1[0] sdc1[2] sdb1[1] sda1[3](F)
16771584 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
unused devices:
[root@centos /]# mdadm -D /dev/md0
/dev/md0:
Version : 00.90.01
Creation Time : Fri Jun 1 13:00:31 2007
Raid Level : raid5
Array Size : 16771584 (15.99 GiB 17.17 GB)
Device Size : 8385792 (7.100 GiB 8.59 GB)
Raid Devices : 3
Total Devices : 4
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Fri Jun 1 13:23:49 2007
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 49 0 active sync /dev/sdd1
1 8 17 1 active sync /dev/sdb1
2 8 33 2 active sync /dev/sdc1
3 8 1 -1 faulty /dev/sda1
UUID : 63cb965b:79486986:d389c551:67677f20
3.移除损坏的硬盘
[root@centos /]# mdadm /dev/md0 -r /dev/sda
mdadm: hot removed /dev/sda
4.添加新的硬盘到raid中
新硬盘接入系统中,应进行正确的分区,且最好与之前换掉的硬盘保持相同的设备号。然后执行命令
mdadm /dev/md0 -a /dev/sda
所有评论(0)