md:
mdadm: 将任何块设备做成RAID

模式化的命令:
1.创建模式

-C  专用选项:

-l: 级别
-n #: 设备个数
-a {yes|no}: 是否自动为其创建设备文件
-c: CHUNK大小, ^n,默认为64KB,最好为块的倍数 ,为了提高raid 0/5 的性能 mke2fs -E stride=16 -b 4096 /dev/md0
-x #: 指定空闲盘个数

3.管理模式

--add, --remove, --fail
mdadm /dev/md# --fail /dev/sda7

4.监控模式

-F

5.增长模式

-G

6.装配模式

-A

查看RAID阵列的详细信息

mdadm -D /dev/md#
--detail

停止阵列:

mdadm -S /dev/md#
--stop

删除设备文件

rm /dev/md#

创建功能:

1.创建一个空间大小为6G的RAID0设备

RAID0 6G:
  2: 3GB

首先创建2个3G大小的分区,并把类型调成read的类型

root@VM_160_34_centos:~> fdisk /dev/xvdb

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): p Disk /dev/xvdb: 53.7 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xc77f92d7 Device Boot Start End Blocks Id System
/dev/xvdb4 Extended
/dev/xvdb5 Linux
/dev/xvdb6 Linux
/dev/xvdb7 Linux
/dev/xvdb8 Linux
/dev/xvdb9 Linux Command (m for help): d
Partition number (-): Command (m for help): p Disk /dev/xvdb: 53.7 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xc77f92d7 Device Boot Start End Blocks Id System Command (m for help): n
Command action
e extended
p primary partition (-)
e
Partition number (-):
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ):
Using default value Command (m for help): p Disk /dev/xvdb: 53.7 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xc77f92d7 Device Boot Start End Blocks Id System
/dev/xvdb4 Extended Command (m for help): n
Command action
l logical ( or over)
p primary partition (-)
l
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +3G Command (m for help): p Disk /dev/xvdb: 53.7 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xc77f92d7 Device Boot Start End Blocks Id System
/dev/xvdb4 Extended
/dev/xvdb5 + Linux Command (m for help): n
Command action
l logical ( or over)
p primary partition (-)
l
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +3G Command (m for help): p Disk /dev/xvdb: 53.7 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xc77f92d7 Device Boot Start End Blocks Id System
/dev/xvdb4 Extended
/dev/xvdb5 + Linux
/dev/xvdb6 Linux Command (m for help): t
Partition number (-):
Hex code (type L to list codes): l Empty NEC DOS Minix / old Lin bf Solaris
FAT12 Plan Linux swap / So c1 DRDOS/sec (FAT-
XENIX root 3c PartitionMagic Linux c4 DRDOS/sec (FAT-
XENIX usr Venix OS/ hidden C: c6 DRDOS/sec (FAT-
FAT16 <32M PPC PReP Boot Linux extended c7 Syrinx
Extended SFS NTFS volume set da Non-FS data
FAT16 4d QNX4.x NTFS volume set db CP/M / CTOS / .
HPFS/NTFS 4e QNX4.x 2nd part Linux plaintext de Dell Utility
AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
AIX bootable OnTrack DM Amoeba e1 DOS access
a OS/ Boot Manag OnTrack DM6 Aux Amoeba BBT e3 DOS R/O
b W95 FAT32 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
OPUS Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
Compaq diagnost SpeedStor a9 NetBSD f4 SpeedStor
Hidden FAT16 < GNU HURD or Sys ab Darwin boot f2 DOS secondary
Hidden FAT16 Novell Netware af HFS / HFS+ fb VMware VMFS
Hidden HPFS/NTF Novell Netware b7 BSDI fs fc VMware VMKCORE
AST SmartSleep DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 PC/IX bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 Old Minix be Solaris boot ff BBT
1e Hidden W95 FAT1
Hex code (type L to list codes): fd
Changed system type of partition to fd (Linux raid autodetect) Command (m for help): t
Partition number (-):
Hex code (type L to list codes): fd
Changed system type of partition to fd (Linux raid autodetect) Command (m for help): p Disk /dev/xvdb: 53.7 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xc77f92d7 Device Boot Start End Blocks Id System
/dev/xvdb4 Extended
/dev/xvdb5 + fd Linux raid autodetect
/dev/xvdb6 fd Linux raid autodetect

确认一下分区已被内核识别

root@VM_160_34_centos:~> cat /proc/partitions
major minor #blocks name xvda
xvda1
xvdb
xvdb4
xvdb5
xvdb6
xvdc

执行创建命令

root@VM_160_34_centos:~> mdadm -C /dev/md0 -a yes -l  -n  /dev/xvdb{,}
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

我们 看一下 /proc/mdstat 文件, 这个文件里面记录着系统中所有启动在的raid 设备

root@VM_160_34_centos:~> cat /proc/mdstat
Personalities : [raid0]
md0 : active raid0 xvdb6[] xvdb5[]
blocks super 1.2 512k chunks unused devices: <none>

我们把它们格式化,

root@VM_160_34_centos:~> mke2fs -j /dev/md0
mke2fs 1.41. (-May-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.

然后挂载到mnt下

root@VM_160_34_centos:~> mount /dev/md0 /mnt/
root@VM_160_34_centos:~> ll /mnt/
total
drwx------ root root Nov : lost+found

到此这个 raid 成功可以使用

创建1G的 raid1

  我们首先创建2个1G的分区,并调整它的类型

root@VM_160_34_centos:~> fdisk /dev/xvdb

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): p Disk /dev/xvdb: 53.7 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xc77f92d7 Device Boot Start End Blocks Id System
/dev/xvdb4 Extended
/dev/xvdb5 + fd Linux raid autodetect
/dev/xvdb6 fd Linux raid autodetect Command (m for help): n
Command action
l logical ( or over)
p primary partition (-)
l
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +1G Command (m for help): n
Command action
l logical ( or over)
p primary partition (-)
l
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +1G Command (m for help): p Disk /dev/xvdb: 53.7 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xc77f92d7 Device Boot Start End Blocks Id System
/dev/xvdb4 Extended
/dev/xvdb5 + fd Linux raid autodetect
/dev/xvdb6 fd Linux raid autodetect
/dev/xvdb7 + Linux
/dev/xvdb8 + Linux Command (m for help): t
Partition number (-):
Hex code (type L to list codes): fd
Changed system type of partition to fd (Linux raid autodetect) Command (m for help): t
Partition number (-):
Hex code (type L to list codes): fd
Changed system type of partition to fd (Linux raid autodetect) Command (m for help): p Disk /dev/xvdb: 53.7 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xc77f92d7 Device Boot Start End Blocks Id System
/dev/xvdb4 Extended
/dev/xvdb5 + fd Linux raid autodetect
/dev/xvdb6 fd Linux raid autodetect
/dev/xvdb7 + fd Linux raid autodetect
/dev/xvdb8 + fd Linux raid autodetect Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error : Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe() or kpartx()
Syncing disks.

确保内核已经识别了我们的分区,如果没有执行 partx -a /dev/xvdb 来识别(可能需要umount 该盘其他挂载点) ,

root@VM_160_34_centos:~> mdadm -C /dev/md1 -a yes -l  -n  /dev/xvdb{,}
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90

执行创建命令

root@VM_160_34_centos:~> mdadm -C /dev/md1 -a yes -l  -n  /dev/xvdb{,}
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.

执行的时候它会问你是否需要创建, 这个是毫无疑问的.

我们查看一下它的状态

root@VM_160_34_centos:~> cat /proc/mdstat
Personalities : [raid0] [raid1]
md1 : active raid1 xvdb8[] xvdb7[]
blocks super 1.2 [/] [UU]
[==========>..........] resync = 54.6% (/) finish=.0min speed=144881K/sec md0 : active raid0 xvdb6[] xvdb5[]
blocks super 1.2 512k chunks unused devices: <none>

格式化,

root@VM_160_34_centos:~> mke2fs -j /dev/md1
mke2fs 1.41. (-May-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.

挂载

root@VM_160_34_centos:~> mount /dev/md1 /storage/
root@VM_160_34_centos:~> ll /storage/
total
drwx------ root root Nov : lost+found

我们查看一下这个阵列的属性:

root@VM_160_34_centos:~> mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Fri Nov ::
Raid Level : raid1
Array Size : (1034.57 MiB 1084.64 MB)
Used Dev Size : (1034.57 MiB 1084.64 MB)
Raid Devices :
Total Devices :
Persistence : Superblock is persistent Update Time : Fri Nov ::
State : clean
Active Devices :
Working Devices :
Failed Devices :
Spare Devices : Name : VM_160_34_centos: (local to host VM_160_34_centos)
UUID : 4e1ea263:6297d669:9d5877af:6e5fc1e0
Events : Number Major Minor RaidDevice State
active sync /dev/xvdb7
active sync /dev/xvdb8

然后拷贝个文件进去,模拟损坏一个设备,文件照常访问

root@VM_160_34_centos:~> mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Fri Nov ::
Raid Level : raid1
Array Size : (1034.57 MiB 1084.64 MB)
Used Dev Size : (1034.57 MiB 1084.64 MB)
Raid Devices :
Total Devices :
Persistence : Superblock is persistent Update Time : Fri Nov ::
State : clean
Active Devices :
Working Devices :
Failed Devices :
Spare Devices : Name : VM_160_34_centos: (local to host VM_160_34_centos)
UUID : 4e1ea263:6297d669:9d5877af:6e5fc1e0
Events : Number Major Minor RaidDevice State
active sync /dev/xvdb7
active sync /dev/xvdb8
root@VM_160_34_centos:~> mdadm /dev/md1 -f /dev/xvdb8
mdadm: set /dev/xvdb8 faulty in /dev/md1
root@VM_160_34_centos:~> mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Fri Nov ::
Raid Level : raid1
Array Size : (1034.57 MiB 1084.64 MB)
Used Dev Size : (1034.57 MiB 1084.64 MB)
Raid Devices :
Total Devices :
Persistence : Superblock is persistent Update Time : Fri Nov ::
State : clean, degraded
Active Devices :
Working Devices :
Failed Devices :
Spare Devices : Name : VM_160_34_centos: (local to host VM_160_34_centos)
UUID : 4e1ea263:6297d669:9d5877af:6e5fc1e0
Events : Number Major Minor RaidDevice State
active sync /dev/xvdb7
removed - faulty spare /dev/xvdb8
root@VM_160_34_centos:~> cat /storage/passwd
root:x:::root:/root:/bin/bash
bin:x:::bin:/bin:/sbin/nologin
daemon:x:::daemon:/sbin:/sbin/nologin
adm:x:::adm:/var/adm:/sbin/nologin
lp:x:::lp:/var/spool/lpd:/sbin/nologin
sync:x:::sync:/sbin:/bin/sync
shutdown:x:::shutdown:/sbin:/sbin/shutdown
halt:x:::halt:/sbin:/sbin/halt
mail:x:::mail:/var/spool/mail:/sbin/nologin
uucp:x:::uucp:/var/spool/uucp:/sbin/nologin
operator:x:::operator:/root:/sbin/nologin
games:x:::games:/usr/games:/sbin/nologin
gopher:x:::gopher:/var/gopher:/sbin/nologin
ftp:x:::FTP User:/var/ftp:/sbin/nologin
nobody:x:::Nobody:/:/sbin/nologin
dbus:x:::System message bus:/:/sbin/nologin
vcsa:x:::virtual console memory owner:/dev:/sbin/nologin
abrt:x::::/etc/abrt:/sbin/nologin
haldaemon:x:::HAL daemon:/:/sbin/nologin
ntp:x::::/etc/ntp:/sbin/nologin
saslauth:x:::"Saslauthd user":/var/empty/saslauth:/sbin/nologin
postfix:x::::/var/spool/postfix:/sbin/nologin
sshd:x:::Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x::::/:/sbin/nologin
nscd:x:::NSCD Daemon:/:/sbin/nologin
nslcd:x:::LDAP Client User:/:/sbin/nologin
dd:x::::/home/dd:/bin/bash
mysql:x::::/home/mysql:/sbin/nologin
vsftpd:x::::/home/vsftpd:/sbin/nologin
www:x::::/storage/www:/sbin/nologin
hadoop:x::::/home/hadoop:/bin/bash

我们替换1一个好的设备进去

root@VM_160_34_centos:~> mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Fri Nov ::
Raid Level : raid1
Array Size : (1034.57 MiB 1084.64 MB)
Used Dev Size : (1034.57 MiB 1084.64 MB)
Raid Devices :
Total Devices :
Persistence : Superblock is persistent Update Time : Fri Nov ::
State : clean, degraded
Active Devices :
Working Devices :
Failed Devices :
Spare Devices : Name : VM_160_34_centos: (local to host VM_160_34_centos)
UUID : 4e1ea263:6297d669:9d5877af:6e5fc1e0
Events : Number Major Minor RaidDevice State
active sync /dev/xvdb7
removed

添加 xvdb 9

root@VM_160_34_centos:~> mdadm /dev/md1 -a /dev/xvdb9
mdadm: added /dev/xvdb9
root@VM_160_34_centos:~> mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Fri Nov ::
Raid Level : raid1
Array Size : (1034.57 MiB 1084.64 MB)
Used Dev Size : (1034.57 MiB 1084.64 MB)
Raid Devices :
Total Devices :
Persistence : Superblock is persistent Update Time : Fri Nov ::
State : clean
Active Devices :
Working Devices :
Failed Devices :
Spare Devices : Name : VM_160_34_centos: (local to host VM_160_34_centos)
UUID : 4e1ea263:6297d669:9d5877af:6e5fc1e0
Events : Number Major Minor RaidDevice State
active sync /dev/xvdb7
active sync /dev/xvdb9

如果我们再 raid 中添加了3个设备, 那么空余那个会在其中一个设备坏了的之后制动替换掉坏掉的那个.

为了方便以后装载,我们把配置写入配置文件

将当前RAID信息保存至配置文件,以便以后进行装配:
mdamd -D --scan > /etc/mdadm.conf

创建一个 2G的 raid5(只要有冗余的都支持空闲盘,所以我们需要4个1G的设备,跟raid1的用法是一样的)

  

md RAID的更多相关文章

  1. 图文并茂 RAID 技术全解 – RAID0、RAID1、RAID5、RAID10

    RAID 技术相信大家都有接触过,尤其是服务器运维人员,RAID 概念很多,有时候会概念混淆.这篇文章为网络转载,写得相当不错,它对 RAID 技术的概念特征.基本原理.关键技术.各种等级和发展现状进 ...

  2. 【转】RAID 技术发展综述

    原文地址:https://blog.csdn.net/liuaigui/article/details/4581970   摘要 :现代企业信息化水平不断提高,数据已经取代计算成为了信息计算的中心.这 ...

  3. 图文并茂 RAID 技术全解 – RAID0、RAID1、RAID5、RAID100

    RAID 技术相信大家都有接触过,尤其是服务器运维人员,RAID 概念很多,有时候会概念混淆.这篇文章为网络转载,写得相当不错,它对 RAID 技术的概念特征.基本原理.关键技术.各种等级和发展现状进 ...

  4. RAID技术全解图解-RAID0、RAID1、RAID5、RAID100【转】

    图文并茂 RAID 技术全解 – RAID0.RAID1.RAID5.RAID100…… RAID 技术相信大家都有接触过,尤其是服务器运维人员,RAID 概念很多,有时候会概念混淆.这篇文章为网络转 ...

  5. RAID技术超详细讲解

    RAID 技术是一种多磁盘技术,面对数据的各方面有着两面性的影响,整体来说优点大于缺点的,下面我将详细介绍一下 RAID ,简称磁盘阵列技术. 一.RAID 概述 1988 年美国加州大学伯克利分校的 ...

  6. RAID 技术全解

    图文并茂 RAID 技术全解 – RAID0.RAID1.RAID5.RAID100-- RAID 技术相信大家都有接触过,尤其是服务器运维人员,RAID 概念很多,有时候会概念混淆.这篇文章为网络转 ...

  7. Linux就这个范儿 第10章 生死与共的兄弟

    Linux就这个范儿 第10章 生死与共的兄弟 就说Linux系统的开机.必须经过加载BIOS.读取MBR.Boot Loader.加载内核.启动init进程并确定运行等级.执行初始化脚本.启动内核模 ...

  8. Linux的正则表达式grep,egrep

    一.概念 正则表达式是对字符串操作的一种逻辑公式,用事先定义好的一组特殊字符,组成一个"规则字符集合",根据用户指定的文本模式对目标文件进行逐行搜索匹配,显示能被模式匹配到的结果. ...

  9. Logical Volume Manager (LVM)

    LVM 是一种可用在Linux内核的逻辑分卷管理器:可用于管理磁盘驱动器或其他类似的大容量存储设备. 本文提供如何在 Arch Linux 中配置和使用 Logical Volume Manager ...

随机推荐

  1. android app性能优化大汇总(google官方Android性能优化典范 - 第2季)

    Google前几天刚发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitmap的 ...

  2. Android数据库之SQLite数据库

    Android数据库之SQLite数据库 导出查看数据库文件 在android中,为某个应用程序创建的数据库,只有它可以访问,其它应用程序是不能访问的,数据库位于Android设备/data/data ...

  3. .NET调用Java写的WebService

    最近遇到一个用.net调用java写的webservice的应用,对方程序员提供了一个后缀为wsdl的文件,这个跟.Net里面生成的wsdl文件差不多,起初没什么概念就查了点资料,知道可以将这个wsd ...

  4. JavaScript学习笔记 - 进阶篇(1)- JS基础语法

    前言 JavaScript能做什么? 1.增强页面动态效果(如:下拉菜单.图片轮播.信息滚动等) 2.实现页面与用户之间的实时.动态交互(如:用户注册.登陆验证等) JS进阶篇学习什么? 在JavaS ...

  5. 20141017--循环语句whlie,do

    int n = 0; ; ) {//n必须小于100,如果等于100则会再进来进行一次运算,变为101. //因为下面的语句中用到了continue,状态改变n++不能用到最后 n++; ) { m ...

  6. java与C#用protobuf通信--java如何转换protobuf-net中的bcl.Decimal对象

    公司内部有些C#服务使用proto-net,引入了bcl.proto中的bcl.Decimal.bcl.DateTime等.对于java的proto生成代码需要对bcl.Decimal.bcl.Dat ...

  7. 判断Featureclass的类型

    一个Featureclass可以是Shapefile Feature Class.Personal Geodatabase Feature Class.File Geodatabase Feature ...

  8. Makefile 基本知识

    Technorati 标签: Makefile 基本知识   最常见的书写方式: CC = gcc LD = ld STRIP = strip CFLAGS := -Os -static -DEZ_O ...

  9. winform Config文件操作

    using System;using System.Collections.Generic;using System.Text;using System.Xml;using System.Config ...

  10. API地图坐标转化(批量转换坐标)

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...