場景
POC環境
CentOS 7 MDADM Raid1
查看版本
#uname -a
Linuxzzsrv1.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)
掛載硬盤
yum 安裝mdadm的支持包
#yum -y install mdadm
Warning:RPMDB altered outside of yum.
Installing :libreport-filesystem-2.1.11-10.el7.centos.x86_64 1/2
Installing : mdadm-3.2.6-31.el7.x86_64 2/2
Verifying : libreport-filesystem-2.1.11-10.el7.centos.x86_64 1/2
Verifying : mdadm-3.2.6-31.el7.x86_64 2/2
Installed:
mdadm.x86_64 0:3.2.6-31.el7
DependencyInstalled:
libreport-filesystem.x86_640:2.1.11-10.el7.centos
Complete!
創建分區
#fdisk/dec/sdb //分區
#fdisk/dec/sdc
[sdb] Cache data unavailable
[sdb] Assuming drive cache: write through
[sdc] Cache data unavailable
[sdc] Assuming drive cache: write through
創建RAID1
# mdadm -C /dev/md0 -l 1 -n 2 /dev/sdb1 /dev/sdc1
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? yes
mdadm:Defaulting to version 1.2 metadata
mdadm:array /dev/md0 started.
dmesg中查看內容
md: bind<sdb1>
md: bind<sdc1>
md: raid1 personality registered for level 1
md/raid1:md0: not clean -- starting backgroundreconstruction
md/raid1:md0: active with 2 out of 2 mirrors
md0: detected capacity change from 0 to10728898560
md0: unknown partition table
md: resync of RAID array md0
md: minimum _guaranteed_ speed: 1000 KB/sec/disk.
md: using maximum available idle IO bandwidth(but not more than 200000 KB/sec) for resync.
md: using 128k window, over a total of10477440k.
md: md0: resync done.
RAID1 conf printout:
--- wd:2 rd:2
disk 0, wo:0, o:1, dev:sdb1
disk 1, wo:0, o:1, dev:sdc1
查看日誌
kernel: md: bind<sdb1>
kernel: md: bind<sdc1>
kernel: md: raid1 personality registered forlevel 1
kernel: md/raid1:md0: not clean -- startingbackground reconstruction
kernel: md/raid1:md0: active with 2 out of 2mirrors
kernel: md0: detected capacity change from 0to 10728898560
kernel: md0: unknown partition table
kernel: md: resync of RAID array md0
kernel: md: minimum _guaranteed_ speed: 1000 KB/sec/disk.
kernel: md: using maximum available idle IObandwidth (but not more than 200000 KB/sec) for resync.
kernel: md: using 128k window, over a total of10477440k.
kernel: md: md0: resync done.
創建文件系統
格式化:
#mkfs.ext4 /dev/md0
Aug 1503:51:49 zzsrv1 kernel: EXT4-fs (md0): mounted filesystem with ordered datamode. Opts: (null)
創建目錄:
#mkdir /data
掛載光驅到目錄下
#mount /dev/md0 /data
# ll /data/ //查看目錄下內容
total 16
drwx------.2 root root 16384 Aug 15 03:51 lost+found
編譯文件添加掛載目錄和RAID1
#vi /etc/fstab //在最後添加
/dev/md0 /data ext4 defaults 0 0
查看最終狀態
# mdadm -Ds
ARRAY/dev/md0 metadata=1.2 name=zzsrv1.bigcloud.local:0UUID=bb9031b3:c25b3254:8f306614:f33741b8
寫入到配置文件
# mdadm -Ds >>/etc/mdadm.conf
創建測試文件
#mkdir /data/mdadm
#touch/data/a.txt
重新啓動驗證
# Reboot
查看掛載信息
# cat/proc/mdstat
Personalities: [raid1]
md0 :active raid1 sdb1[0] sdc1[1]
10477440 blocks super 1.2 [2/2] [UU]
unuseddevices: <none>
模擬故障
/dev/sdc1壞掉
#reboot
# cat /proc/mdstat
Personalities: [raid1]
md0 :active raid1 sdb1[1]
10477440 blocks super 1.2 [2/1] [_U]
unused devices: <none>
RAID1重建
模擬恢復,在創建30GB的硬盤
重新分區
#fdisk /dev/sdb
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: 0x46134903
Device Boot Start End Blocks Id System
/dev/sdc1 2048 20973567 10485760 83 Linux
# 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 0xedffc7e6.
Command(m for help): p //查看分區
Disk/dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0xedffc7e6
Device Boot Start End Blocks Id System
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-41943039, default 2048): //從當前柱面開始
Usingdefault value 2048
Lastsector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G //分區爲10G
Partition1 of type Linux and of size 10 GiB is set
Command(m for help): w //保存分區
Thepartition table has been altered!
Callingioctl() to re-read partition table.
Syncingdisks.
# mkfs.ext4 /dev/sdb1 //格式化分區
mke2fs1.42.9 (28-Dec-2013)
Filesystemlabel=
OS type:Linux
Blocksize=4096 (log=2)
Fragmentsize=4096 (log=2)
Stride=0blocks, Stripe width=0 blocks
655360inodes, 2621440 blocks
131072blocks (5.00%) reserved for the super user
Firstdata block=0
Maximumfilesystem blocks=2151677952
80 blockgroups
32768 blocksper group, 32768 fragments per group
8192inodes per group
Superblockbackups stored on blocks:
32768, 98304, 163840, 229376, 294912,819200, 884736, 1605632
Allocatinggroup tables: done
Writinginode tables: done
Creatingjournal (32768 blocks): done
Writingsuperblocks and filesystem accounting information: done //格式化完成
# mdadm /dev/md0 -a /dev/sdb1 //在線添加磁盤到/Dev/md0
mdadm:added /dev/sdb1
# cat /proc/mdstat
Personalities: [raid1]
md0 :active raid1 sdb1[2] sdc1[1]
10477440 blocks super 1.2 [2/1] [_U]
[===========>.........] recovery = 55.2% (5792896/10477440)finish=0.3min speed=206889K/sec
unuseddevices: <none>
查看日誌重建過程
#tail -f /var/log/messages
kernel: sdb: sdb1
kernel: md:bind<sdb1>
kernel: md:recovery of RAID array md0
kernel: md:minimum _guaranteed_ speed: 1000KB/sec/disk.
kernel: md:using maximum available idle IO bandwidth (but not more than 200000 KB/sec) forrecovery.
kernel: md:using 128k window, over a total of 10477440k.
kernel: md:md0: recovery done.
mdadm使用文檔
mdadm中文man(引用)
基本語法: mdadm [mode][options]
[mode] 有7種:
Assemble:將以前定義的某個陣列加入當前在用陣列。
Build:Build a legacy array ,每個device 沒有 superblocks
Create:創建一個新的陣列,每個device 具有 superblocks
Manage:管理陣列,比如 add 或 remove
Misc:允許單獨對陣列中的某個 device 做操作,比如抹去superblocks或終止在用的陣列。
Follow or Monitor:監控 raid 1,4,5,6 和 multipath 的狀態
Grow:改變raid 容量或陣列中的 device 數目
可用的[options]:
-A, --assemble:加入一個以前定義的陣列
-B, --build:Build a legacy array without superblocks.
-C, --create:創建一個新的陣列
-Q, --query:查看一個device,判斷它爲一個 mddevice 或是一個 md 陣列的一部分
-D, --detail:打印一個或多個 md device 的詳細信息
-E, --examine:打印 device 上的 md superblock 的內容
-F, --follow, --monitor:選擇 Monitor 模式
-G, --grow:改變在用陣列的大小或形態
-h, --help:幫助信息,用在以上選項後,則顯示該選項信息
--help-options
-V, --version
-v, --verbose:顯示細節
-b, --brief:較少的細節。用於 --detail 和 --examine 選項
-f, --force
-c, --config= :指定配置文件,缺省爲/etc/mdadm/mdadm.conf
-s, --scan:掃描配置文件或 /proc/mdstat以搜尋丟失的信息。配置文件/etc/mdadm/mdadm.conf
create 或 build 使用的選項:
-c, --chunk=:Specify chunk size of kibibytes. 缺省爲 64.
--rounding=: Specify rounding factor for lineararray (==chunk size)
-l, --level=:設定 raid level.
--create可用:linear, raid0, 0, stripe, raid1,1, mirror,raid4, 4, raid5, 5, raid6, 6, multipath, mp.
--build可用:linear, raid0, 0,stripe.
-p, --parity=:設定 raid5 的奇偶校驗規則:eft-asymmetric,left-symmetric, right-asymmetric, right-symmetric, la, ra, ls, rs.缺省爲left-symmetric
--layout=:類似於--parity
-n, --raid-devices=:指定陣列中可用 device 數目,這個數目只能由 --grow 修改
-x, --spare-devices=:指定初始陣列的富餘device 數目
-z, --size=:組建RAID1/4/5/6後從每個device獲取的空間總數
--assume-clean:目前僅用於 --build 選項
-R, --run:陣列中的某一部分出現在其他陣列或文件系統中時,mdadm會確認該陣列。此選項將不作確認。
-f, --force:通常mdadm不允許只用一個device 創建陣列,而且創建raid5時會使用一個device作爲missing drive。此選項正相反。
-a, --auto{=no,yes,md,mdp,part,p}{NN}:
總結:體會用mdadm創建RAID1的過程