4-构建软RAID磁盘阵列


2016.6.16

案例:构建软RAID磁盘阵列

需求描述

  • 为Linux服务器添加4块SCSI硬盘
  • 使用mdadm软件包,构建RAID5磁盘阵列,提高磁盘存储的性能和可靠性

步骤

  • 安装mdadm

安装mdadm

  • 准备用于RAID阵列的分区
    • 为Linux服务器添加4块SCSI硬盘,并使用fdisk工具个划分出一块2GB的分区依次为:/dev/sde1、/dev/sdg1、/dev/sdh1、/dev/sdf1
    • 将其类型ID更改为“fd”,对应为“Linux raid autodetect”,表示支持用于RAID磁盘阵列
  • 创建RAID设备
  • 在RAID设备中建立文件系统
  • 挂载并使用文件系统

增加硬盘、分区(关掉虚拟机的情况下,增加硬盘)
1.增加分区(虚拟机是这样,真机是需要加硬盘)
2.分区以及检验分区信息
3.转换类型以及查看转后的信息

现有磁盘信息:

[root@test2 jason]# fdisk -l

Disk /dev/sdb: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa8f24694

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2612    20980858+  83  Linux
/dev/sdb2            2613        5224    20980890   8e  Linux LVM
/dev/sdb3            5225       10443    41921617+  83  Linux

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d0a36

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM

Disk /dev/sdd: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xef9a8da9

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1       13054   104856223+  8e  Linux LVM

Disk /dev/sde: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdc: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8967e34e

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        2612    20980858+  83  Linux
/dev/sdc2            2613        5224    20980890   8e  Linux LVM

Disk /dev/sdg: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdf: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdh: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg_jason-lv_root: 18.8 GB, 18798870528 bytes
255 heads, 63 sectors/track, 2285 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg_jason-lv_swap: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/mail_store-mbox: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[root@test2 jason]#

sde1分出2G的主分区,并转换成"fd”(Linux raid autodetect ):

[root@test2 jason]# fdisk /dev/sde
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xe4b1d138.
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)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +2G

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): p

Disk /dev/sde: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe4b1d138

   Device Boot      Start         End      Blocks   Id  System
/dev/sde1               1         262     2104483+  fd  Linux raid autodetect

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@test2 jason]#

一样的方法来处理sdg

[root@test2 jason]# fdisk /dev/sd
sda   sda1  sda2  sdb   sdb1  sdb2  sdb3  sdc   sdc1  sdc2  sdd   sdd1  sde   sde1  sdf   sdg   sdh
[root@test2 jason]# fdisk /dev/sdg
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x37970afa.
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)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +2G

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): p

Disk /dev/sdg: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x37970afa

   Device Boot      Start         End      Blocks   Id  System
/dev/sdg1               1         262     2104483+  fd  Linux raid autodetect

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

Calling ioctl() to re-read partition table.
Syncing disks.

sdf:

[root@test2 jason]# fdisk /dev/sd
sda   sda2  sdb1  sdb3  sdc1  sdd   sde   sdf   sdg1
sda1  sdb   sdb2  sdc   sdc2  sdd1  sde1  sdg   sdh
[root@test2 jason]# fdisk /dev/sdf
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x65c9c4f1.
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)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +2g
Unsupported suffix: 'g'.
Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte)
            2^N: K  (KibiByte), M  (MebiByte), G  (GibiByte)
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +2G

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): p

Disk /dev/sdf: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x65c9c4f1

   Device Boot      Start         End      Blocks   Id  System
/dev/sdf1               1         262     2104483+  fd  Linux raid autodetect

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

Calling ioctl() to re-read partition table.
Syncing disks.

sdh

[root@test2 jason]# fdisk /dev/sd
sda   sda2  sdb1  sdb3  sdc1  sdd   sde   sdf   sdg   sdh
sda1  sdb   sdb2  sdc   sdc2  sdd1  sde1  sdf1  sdg1
[root@test2 jason]# fdisk /dev/sdh
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xdeb9d0d0.
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)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +2G

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): p

Disk /dev/sdh: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xdeb9d0d0

   Device Boot      Start         End      Blocks   Id  System
/dev/sdh1               1         262     2104483+  fd  Linux raid autodetect

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@test2 jason]#

探测刚刚的分区是否被电脑识别:

[root@test2 jason]# partprobe /dev/sde
sde   sde1
[root@test2 jason]# partprobe /dev/sdg
sdg   sdg1
[root@test2 jason]# partprobe /dev/sdh
sdh   sdh1
[root@test2 jason]# partprobe /dev/sdf
sdf   sdf1

再次查看分区信息:

[root@test2 jason]# fdisk -l | grep "/dev"
Disk /dev/sdb: 85.9 GB, 85899345920 bytes
/dev/sdb1               1        2612    20980858+  83  Linux
/dev/sdb2            2613        5224    20980890   8e  Linux LVM
/dev/sdb3            5225       10443    41921617+  83  Linux
Disk /dev/sda: 21.5 GB, 21474836480 bytes
/dev/sda1   *           1          64      512000   83  Linux
/dev/sda2              64        2611    20458496   8e  Linux LVM
Disk /dev/sdd: 107.4 GB, 107374182400 bytes
/dev/sdd1               1       13054   104856223+  8e  Linux LVM
Disk /dev/sde: 21.5 GB, 21474836480 bytes
/dev/sde1               1         262     2104483+  fd  Linux raid autodetect
Disk /dev/sdc: 85.9 GB, 85899345920 bytes
/dev/sdc1               1        2612    20980858+  83  Linux
/dev/sdc2            2613        5224    20980890   8e  Linux LVM
Disk /dev/sdg: 21.5 GB, 21474836480 bytes
/dev/sdg1               1         262     2104483+  fd  Linux raid autodetect
Disk /dev/sdf: 21.5 GB, 21474836480 bytes
/dev/sdf1               1         262     2104483+  fd  Linux raid autodetect
Disk /dev/sdh: 21.5 GB, 21474836480 bytes
/dev/sdh1               1         262     2104483+  fd  Linux raid autodetect
Disk /dev/mapper/vg_jason-lv_root: 18.8 GB, 18798870528 bytes
Disk /dev/mapper/vg_jason-lv_swap: 2147 MB, 2147483648 bytes
Disk /dev/mapper/mail_store-mbox: 128.8 GB, 128849018880 bytes
[root@test2 jason]#

1.创建
2.查看

  • ls -l /dev/md0
  • cat /proc/mdstat

创建阵列

[root@test2 jason]# mdadm -Cv /dev/md0 -a yes -n4 -l5 /dev/sde1 /dev/sdg1 /dev/sdh1 /dev/sdf1
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 2102272K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@test2 jason]#
  • -a:就是如果有需要创建的,就直接创建,比如说md0这个之前是不存在的目录,那么在创建阵列的同时直接创建md0
  • md0:一般讲RAID命名成md0
  • -n:几块硬盘,就写几
  • -l:级别,或者说类型,5,就是RAID5
  • 后面跟着的是把具体某个硬盘的某个分区创建成RAID
  • -C:是创建阵列

另一种方法:

  • --create:创建这列
  • --auto=yes
  • --raid-devices=4
  • --level=5
  • --spare-devices

创建后的查看:

[root@test2 jason]# ls -l /dev/md0
brw-rw---- 1 root disk 9, 0 Jun 16 16:11 /dev/md0
[root@test2 jason]#

另一种查看方式:

[root@test2 jason]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdf1[4] sdh1[2] sdg1[1] sde1[0]
      6306816 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/4] [UUUU]

unused devices: <none>
[root@test2 jason]#
  • [4/4]:第一个4是代表4个分区,第二个4表示正常工作的有几个
  • [UUUU]:表示up,正常启动的有几个,如果有一个有问题,那么会用“_”(下划线)来表示。
    • 上面sdf1[4]代表的是最后一个U
    • sde1[0]代表是第一个U
    • sdg1[1]则是第二个
    • sdh1[2]是第三个

1.查看格式化前的信息
2.格式化
3.检验格式化的结果
格式化:

[root@test2 jason]# mkfs -t ext4 /dev/md0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=128 blocks, Stripe width=384 blocks
394352 inodes, 1576704 blocks
78835 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1614807040
49 block groups
32768 blocks per group, 32768 fragments per group
8048 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736

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

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@test2 jason]#

挂载
1.检查挂载前的信息
2.明确挂载目录(如果已经存在可以直接挂载,如果不存在就需要自己挂载)
3.挂载方式

* 一次性挂载
* 开机后自动挂载

4.检验挂载行为的结果

* mount
* df -hT

创建mdata目录在根下面,作为挂载点:

[root@test2 jason]# mkdir /mdata

挂载/dev/md0:

[root@test2 jason]# mount /dev/md0 /mdata

查看挂载信息的方式:

[root@test2 jason]# mount
/dev/mapper/vg_jason-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sdc1 on /home type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sr0 on /media/CentOS_6.5_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)
/dev/md0 on /mdata type ext4 (rw)

另一种查看挂载信息的方式:

[root@test2 jason]# df -hT
Filesystem                   Type     Size  Used Avail Use% Mounted on
/dev/mapper/vg_jason-lv_root ext4      18G  4.3G   13G  27% /
tmpfs                        tmpfs    3.9G   76K  3.9G   1% /dev/shm
/dev/sda1                    ext4     485M   40M  421M   9% /boot
/dev/sdc1                    ext4      20G  422M   19G   3% /home
/dev/sr0                     iso9660  4.2G  4.2G     0 100% /media/CentOS_6.5_Final
/dev/md0                     ext4     6.0G  141M  5.5G   3% /mdata
[root@test2 jason]#

因为是RAID 5,有一块盘是用来做校验的,所以实际的容量是6G。

修改fstab配置文件,达到开机后自动挂载的目的。
1.备份fstab
2.修改
3.测试修改的效果

  • 卸载
  • 重新挂载
  • 查看挂载信息

先备份一下fstab文件

[root@test2 jason]# cp /etc/fstab /etc/fstab.bak

更改配置文件,以便于重启之后可以自动挂载

[root@test2 jason]# vim /etc/fstab

#
# /etc/fstab
# Created by anaconda on Wed May 18 04:04:40 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_jason-lv_root /                       ext4    defaults        1 1
UUID=12a13375-c595-4876-9fc2-3158f535861d /boot                   ext4    defaults        1 2
/dev/mapper/vg_jason-lv_swap swap                    swap    defaults        0 0
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
/dev/sdc1       /home   ext4    defaults        0 0
/dev/md0        /mdata  ext4    defaults        0 0
~
~
~
~
~
~
~
~
~
~
~
~
~
:wq

测试是否奏效: 先卸载并查看挂载信息:

[root@test2 jason]# umount /mdata/
[root@test2 jason]# df -hT
Filesystem                   Type     Size  Used Avail Use% Mounted on
/dev/mapper/vg_jason-lv_root ext4      18G  4.3G   13G  27% /
tmpfs                        tmpfs    3.9G   76K  3.9G   1% /dev/shm
/dev/sda1                    ext4     485M   40M  421M   9% /boot
/dev/sdc1                    ext4      20G  422M   19G   3% /home
/dev/sr0                     iso9660  4.2G  4.2G     0 100% /media/CentOS_6.5_Final
[root@test2 jason]#

挂载,并查看信息:

[root@test2 jason]# mount -a [root@test2 jason]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/vg_jason-lv_root ext4 18G 4.3G 13G 27% / tmpfs tmpfs 3.9G 76K 3.9G 1% /dev/shm /dev/sda1 ext4 485M 40M 421M 9% /boot /dev/sdc1 ext4 20G 422M 19G 3% /home /dev/sr0 iso9660 4.2G 4.2G 0 100% /media/CentOS_6.5_Final /dev/md0 ext4 6.0G 141M 5.5G 3% /mdata [root@test2 jason]#

RAID阵列的管理及设备恢复

  • 扫描或查看磁盘阵列信息
  • 启动/停止RAID阵列
  • 设备恢复操作
    • 模拟阵列设备故障
    • 更换故障设备,并恢复数据

查看磁盘阵列信息

注意参数这里面是在意顺序的:

[root@test2 jason]# mdadm -sDv
mdadm: -s does not set the mode, and so cannot be the first option.

合适的顺序:

[root@test2 jason]# mdadm -vDs
ARRAY /dev/md0 level=raid5 num-devices=4 metadata=1.2 name=test2:0 UUID=10a00bcf:d67ab596:18b5fa25:8ef335e1
   devices=/dev/sde1,/dev/sdg1,/dev/sdh1,/dev/sdf1
[root@test2 jason]#

另一种查看方式:

[root@test2 jason]# mdadm -vDs /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Thu Jun 16 16:11:19 2016
     Raid Level : raid5
     Array Size : 6306816 (6.01 GiB 6.46 GB)
  Used Dev Size : 2102272 (2.00 GiB 2.15 GB)
   Raid Devices : 4
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Thu Jun 16 16:43:12 2016
          State : clean
 Active Devices : 4
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 512K

           Name : test2:0  (local to host test2)
           UUID : 10a00bcf:d67ab596:18b5fa25:8ef335e1
         Events : 18

    Number   Major   Minor   RaidDevice State
       0       8       65        0      active sync   /dev/sde1
       1       8       97        1      active sync   /dev/sdg1
       2       8      113        2      active sync   /dev/sdh1
       4       8       81        3      active sync   /dev/sdf1
[root@test2 jason]#

自己创建mdadm.conf文件的方法和格式:

[root@test2 jason]# mdadm -vDs > /etc/mdadm.conf
[root@test2 jason]# vi /etc/mdadm.conf

DEVICE /dev/sde1 /dev/sdg1 /dev/sdh1 /dev/sdf1ARRAY /dev/md0 level=raid5 num-devices=4  UUID=10a00bcf:d67ab596:18b5fa25:8ef335e1
   devices=/dev/sde1,/dev/sdg1,/dev/sdh1,/dev/sdf1
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
:wq

通过停止和启动/dev/md0来测试配置文件是否生效: 直接停止:

[root@test2 jason]# mdadm -S /dev/md0
mdadm: Cannot get exclusive access to /dev/md0:Perhaps a running process, mounted filesystem or active volume group?
[root@test2 jason]#

提示是正在运行的进程

卸载:

[root@test2 jason]# umount /dev/md0

停止:

[root@test2 jason]# mdadm -S /dev/md0
mdadm: stopped /dev/md0
[root@test2 jason]# df -hT
Filesystem                   Type     Size  Used Avail Use% Mounted on
/dev/mapper/vg_jason-lv_root ext4      18G  4.3G   13G  27% /
tmpfs                        tmpfs    3.9G   76K  3.9G   1% /dev/shm
/dev/sda1                    ext4     485M   40M  421M   9% /boot
/dev/sdc1                    ext4      20G  422M   19G   3% /home
/dev/sr0                     iso9660  4.2G  4.2G     0 100% /media/CentOS_6.5_Final

启动:

[root@test2 jason]# mdadm -A /dev/md0
mdadm: /dev/md0 has been started with 4 drives.

证明配置文件是正确的

启动不等于挂载

[root@test2 jason]# df -hT
Filesystem                   Type     Size  Used Avail Use% Mounted on
/dev/mapper/vg_jason-lv_root ext4      18G  4.3G   13G  27% /
tmpfs                        tmpfs    3.9G   76K  3.9G   1% /dev/shm
/dev/sda1                    ext4     485M   40M  421M   9% /boot
/dev/sdc1                    ext4      20G  422M   19G   3% /home
/dev/sr0                     iso9660  4.2G  4.2G     0 100% /media/CentOS_6.5_Final
[root@test2 jason]#

重新挂载:

[root@test2 jason]# mount -a
[root@test2 jason]# mount
/dev/mapper/vg_jason-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sdc1 on /home type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sr0 on /media/CentOS_6.5_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)
/dev/md0 on /mdata type ext4 (rw)
[root@test2 jason]#

移除一块硬盘
1.查看移除前的状态
2.移除

* 设定为faulty状态
* 移除操作

3.检查移除后的状态

现在模拟,假设sde1坏掉,然后把sde1移除:
第一步将sde1设定为"faulty"状态:

[root@test2 jason]# mdadm /dev/md0 -f /dev/sde1
mdadm: set /dev/sde1 faulty in /dev/md0

查看mdstat

[root@test2 jason]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sde1[0](F) sdf1[4] sdh1[2] sdg1[1]
      6306816 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/3] [_UUU]

unused devices: <none>

第二部移除坏掉的sde1:

[root@test2 jason]# mdadm /dev/md0 -r /dev/sde1
mdadm: hot removed /dev/sde1 from /dev/md0

查看remove后的信息:

[root@test2 jason]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdf1[4] sdh1[2] sdg1[1]
      6306816 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/3] [_UUU]

unused devices: <none>
[root@test2 jason]#

增加一块硬盘
1.检查增加前的状态
2.增加
3.检查增加后的状态。

现在假定sde1是正常的盘,再把sde1加进md0当中:

[root@test2 jason]# mdadm /dev/md0 -a /dev/sde1
mdadm: added /dev/sde1

使用/proc/mdstat来查看加入的进度:

[root@test2 jason]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sde1[5] sdf1[4] sdh1[2] sdg1[1]
      6306816 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/3] [_UUU]
      [======>..............]  recovery = 33.6% (706560/2102272) finish=0.0min speed=235520K/sec

unused devices: <none>
[root@test2 jason]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sde1[5] sdf1[4] sdh1[2] sdg1[1]
      6306816 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/3] [_UUU]
      [===========>.........]  recovery = 56.2% (1182388/2102272) finish=0.0min speed=236477K/sec

unused devices: <none>
[root@test2 jason]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sde1[5] sdf1[4] sdh1[2] sdg1[1]
      6306816 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/3] [_UUU]
      [=============>.......]  recovery = 66.5% (1400064/2102272) finish=0.0min speed=200009K/sec

unused devices: <none>
[root@test2 jason]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sde1[5] sdf1[4] sdh1[2] sdg1[1]
      6306816 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/3] [_UUU]
      [=================>...]  recovery = 85.5% (1800064/2102272) finish=0.0min speed=225008K/sec

unused devices: <none>
[root@test2 jason]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sde1[5] sdf1[4] sdh1[2] sdg1[1]
      6306816 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/3] [_UUU]
      [==================>..]  recovery = 92.0% (1936640/2102272) finish=0.0min speed=215182K/sec

unused devices: <none>

加入完成:

[root@test2 jason]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sde1[5] sdf1[4] sdh1[2] sdg1[1]
      6306816 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/4] [UUUU]

unused devices: <none>
[root@test2 jason]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sde1[5] sdf1[4] sdh1[2] sdg1[1]
      6306816 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/4] [UUUU]

unused devices: <none>
[root@test2 jason]#

results matching ""

    No results matching ""