RAID1
场景
[# uname -a
LinuxZZSRV2.BIGCLOUD.LOCAL 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/redhat-release
CentOSLinux release 7.0.1406 (Core)
为磁盘分区
磁盘一:
[# fdisk /dev/sdb
Welcometo fdisk (util-linux 2.23.2).
Changeswill remain in memory only, until you decide to write them.
Becareful before using the write command.
Devicedoes not contain a recognized partition table
Buildinga new DOS disklabel with disk identifier 0xdb748c9c.
Command(m for help): n
Partitiontype:
p primary (0 primary, 0 extended, 4 free)
e extended
Select(default p): p
Partitionnumber (1-4, default 1): 1
Firstsector (2048-62914559, default 2048):
Usingdefault value 2048
Lastsector, +sectors or +size{K,M,G} (2048-62914559, default 62914559):
Usingdefault value 62914559
Partition1 of type Linux and of size 30 GiB is set
Command(m for help): w
Thepartition table has been altered!
Callingioctl() to re-read partition table.
Syncingdisks.
磁盘二
# fdisk /dev/sdc
Welcometo fdisk (util-linux 2.23.2).
Changeswill remain in memory only, until you decide to write them.
Becareful before using the write command.
Devicedoes not contain a recognized partition table
Buildinga new DOS disklabel with disk identifier 0x15798516.
Command(m for help): n
Partitiontype:
p primary (0 primary, 0 extended, 4 free)
e extended
Select(default p): p
Partitionnumber (1-4, default 1): 1
Firstsector (2048-62914559, default 2048):
Usingdefault value 2048
Lastsector, +sectors or +size{K,M,G} (2048-62914559, default 62914559):
Usingdefault value 62914559
Partition1 of type Linux and of size 30 GiB is set
Command(m for help): w
Thepartition table has been altered!
Callingioctl() to re-read partition table.
Syncingdisks.
建立RAID1
# mdadm -C /dev/md0 -l 1 -n 2 /dev/sd[bc]1
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 ensurethat
your boot-loader understands md/v1.xmetadata, or use
--metadata=0.90
Continuecreating array? y
mdadm:Defaulting to version 1.2 metadata
mdadm:array /dev/md0 started.
创建文件系统
格式化
# mkfs.ext4 /dev/md0
mke2fs1.42.9 (28-Dec-2013)
Filesystemlabel=
OS type:Linux
Blocksize=4096 (log=2)
Fragmentsize=4096 (log=2)
Stride=0blocks, Stripe width=0 blocks
1966080inodes, 7859936 blocks
392996blocks (5.00%) reserved for the super user
Firstdata block=0
Maximumfilesystem blocks=2155872256
240 blockgroups
32768blocks per group, 32768 fragments per group
8192inodes per group
Superblockbackups stored on blocks:
32768, 98304, 163840, 229376, 294912,819200, 884736, 1605632, 2654208,
4096000
Allocatinggroup tables: done
Writinginode tables: done
Creatingjournal (32768 blocks): done
Writingsuperblocks and filesystem accounting information: done
# mkfs.ext4 /dev/md0
# mkdir /data
# mount /dev/md0 /data
# ll /data/
total 16
drwx------ 2 root root 16384 Aug 14 15:21lost+found
# vi /etc/fstab
在最后添加如下内容
/dev/md0 /data ext4 defaults 0 0
# mdadm -Ds
ARRAY/dev/md0 metadata=1.2 name=localhost.localdomain:0UUID=35af8681:eed93527:a121b299:7b7edc7d
# mdadm -Ds >> /etc/mdadm.conf
重启验证
# Reboot
# mount
proc on/proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on/sys type sysfs (rw,nosuid,nodev,noexec,relatime)
devtmpfson /dev type devtmpfs (rw,nosuid,size=241000k,nr_inodes=60250,mode=755)
securityfson /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on/dev/shm type tmpfs (rw,nosuid,nodev)
devpts on/dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on/run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on/sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,mode=755)
cgroup on/sys/fs/cgroup/systemd type cgroup(rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on/sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on/sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on/sys/fs/cgroup/cpu,cpuacct type cgroup(rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on/sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on/sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on/sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on/sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
cgroup on/sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on/sys/fs/cgroup/perf_event type cgroup(rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on/sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
configfson /sys/kernel/config type configfs (rw,relatime)
/dev/mapper/centos-rooton / type xfs (rw,relatime,attr2,inode64,noquota)
systemd-1on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=31,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
debugfson /sys/kernel/debug type debugfs (rw,relatime)
mqueue on/dev/mqueue type mqueue (rw,relatime)
hugetlbfson /dev/hugepages type hugetlbfs (rw,relatime)
/dev/md0on /data type ext4 (rw,relatime,data=ordered)
/dev/sda1on /boot type xfs (rw,relatime,attr2,inode64,noquota)
# cat /proc/mdstat
Personalities: [raid1]
md0 :active raid1 sdc1[1] sdb1[0]
31439744 blocks super 1.2 [2/2] [UU]
unuseddevices: <none>
模拟故障
干掉一块硬盘,
# cat /proc/mdstat
Personalities: [raid1]
md0 :active raid1 sdb1[1]
31439744 blocks super 1.2 [2/1] [_U]
unuseddevices: <none>
重建RAID1
添加一块硬盘
# fdisk -l /dev/sdc
Disk/dev/sdc: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units =sectors of 1 * 512 = 512 bytes
Sectorsize (logical/physical): 512 bytes / 512 bytes
I/O size(minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Diskidentifier: 0x15798516
DeviceBoot Start End Blocks Id System
/dev/sdc1 2048 62914559 31456256 83 Lin
注意:新加入的磁盘需要分区
在线加入新组成单元
# mdadm /dev/md0 -a /dev/sdb1
mdadm:added /dev/sdb1
# cat /proc/mdstat
Personalities: [raid1]
md0 :active raid1 sdb1[2] sdc1[1]
31439744 blocks super 1.2 [2/1] [_U]
[====>................] recovery = 21.4% (6753280/31439744)finish=2.0min speed=200000K/sec
unuseddevices: <none>
菜鸟版RAID1,见谅.