Linux下实现raid5磁盘阵列

一.做raid5磁盘阵列

fdisk -l                                                                  //列出所有磁盘分区

fdisk /dev/sdh    m查看各种参数(n,1...4,p,初始值,结束值,t,fd,p,w等)     //给新硬盘分区,sdh1,sdh2,sdh3,sdh4(大小一致)

partprobe                                                                 //激活分区

mdadm -Cv /dev/md0 -l5 -n3 -x1 -c128 /dev/sdh[1,2,3,4]                    //创建raid5阵列磁盘

more /proc/mdstat                                                         //查看阵列状态

/****************************************************出现则完成****************************************************/

Personalities : [raid5]

     md0 : active raid5 sdd1[2] sde1[3] sdc1[1] sdb1[0]

     75469842 blocks level 5, 128k chunk, algorithm 2 [3/3] [UUU]

     unused devices:

/******************************************************************************************************************/

mdadm -Ds > /etc/mdadm.conf                                               //生成raid配置文件

(mkfs.ext3 /dev/md0                                                       //磁盘阵列md0创建文件系统

 mkdir /mnt/raid                                                          //创建挂载点

 mount /dev/md0 /mnt/raid                                                 //挂载

 vi /etc/fstab                                                            //自动挂载   

 /dev/md0 /mnt/raid ext3 defaults 0 0)

二.在raid上建lvm 

pvcreate -f /dev/md0                                                      //划分pv

vgcreate vgdata /dev/md0                                                  //建vg    (此刻vgdata在/etc/lvm下)

lvcreate -L 1000m -n lvdata /dev/vgdata                                   //建lv    (此刻vgdata在/dev下)

mkfs.ext3 /dev/vgdata/lvdata                                              //lv创建文件系统

mkdir /database                                                           //创建挂载点

mount /dev/vgdata/lvdata /database                                        //挂载

df -h                                                                     //查看挂载情况

(umount /database

 lvextend -L +500m /dev/vgdata/lvdata                                     //扩lv

 fsck /dev/vgdata/lvdata                                                  //检查磁盘

 resize2fs /dev/vgdata/lvdata                                             //扩文件系统                              

 ext2online /dev/vgdata/lvdata)                                           //动态扩文件系统,无须umount

三.整体检测

mdadm /dev/md0 -f /dev/sdh2                                               //将/dev/sdh2标记为已损坏的设备

more /proc/mdstat                                                         //查看阵列状态

/****************************************************出现未完成****************************************************/

Personalities : [raid5]

md0 : active raid5 sdd1[2] sde1[3] sdc1[1] sdb1[4](F)

75469842 blocks level 5, 128k chunk, algorithm 2 [3/2] [U_U]

[=>...................] recovery = 8.9% (3358407/37734912) finish=1.6min speed=9382K/sec

unused devices:

/******************************************************************************************************************/

more /proc/mdstat                                                         //查看阵列状态

/****************************************************出现则完成****************************************************/

Personalities : [raid5]

md0 : active raid5 sdd1[2] sde1[0] sdc1[1] sdb1[3](F)

75469842 blocks level 5, 128k chunk, algorithm 2 [3/3] [UUU]

unused devices:

/******************************************************************************************************************/

mdadm /dev/md0 -r /dev/sdh2                                               //移除损坏的设备

more /proc/mdstat                                                         //查看阵列状态

mdadm /dev/md0 -a /dev/sdh2                                               //将新设备添加到阵列中

more /proc/mdstat                                                         //查看阵列状态

注:常用阵列命令:

mdadm -As (/dev/md0)                                                        //启动md0阵列

mdadm -S  /dev/md0                                                          //停止md0阵列

mdadm -D  /dev/md0                                                          //显示md0信息

相关推荐