首页 > 其他 > 详细

MDADM

时间:2014-08-15 10:51:50      阅读:423      评论:0      收藏:0      [点我收藏+]

先在虚拟机上添加两块硬盘

bubuko.com,布布扣

查看一下操作系统

[root@web1 ~]# uname -a

Linux web1.abc.local 2.6.32-358.el6.x86_64#1 SMP Tue Jan 29 11:47:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

[root@web1 ~]# cat /etc/redhat-release

Red Hat Enterprise Linux Server release 6.4(Santiago)

查看mdadm的版本信息

[root@web1 ~]# rpm -qi mdadm

Name       : mdadm                       Relocations: (not relocatable)

Version    : 3.2.5                            Vendor: Red Hat, Inc.

Release     : 4.el6                         Build Date: Fri 07 Dec2012 12:14:45 AM CST

Install Date: Fri 01 Aug 2014 06:05:19 PMCST      Build Host:x86-003.build.bos.redhat.com

Group      : System Environment/Base      Source RPM: mdadm-3.2.5-4.el6.src.rpm

Size       : 860588                          License: GPLv2+

Signature  : RSA/8, Mon 28 Jan 2013 10:48:06 PM CST, Key ID 199e2f91fd431d51

Packager   : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>

URL        : http://www.kernel.org/pub/linux/utils/raid/mdadm/

Summary    : The mdadm program controls Linux md devices (software RAID arrays)

Description :

The mdadm program is used to create,manage, and monitor Linux MD (software

RAID)devices.  As such, it provides similarfunctionality to the raidtools

package. However, mdadm is a single program, and it can perform

almost all functions without aconfiguration file, though a configuration

file can be used to help with some commontasks.

1.分区操作


[root@web1 ~]# fdisk /dev/sdb

 

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 forhelp): p

 

Disk /dev/sdb:32.2 GB, 32212254720 bytes

255 heads, 63 sectors/track, 3916 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x09a1a34a

 

  Device Boot      Start         End      Blocks  Id  System

 

Command (m forhelp): n

Command action

  e   extended

  p   primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-3916, default 1):

Using defaultvalue 1

Last cylinder, +cylinders or +size{K,M,G}(1-3916, default 3916):

Using default value 3916

 

Command (m forhelp): p

 

Disk /dev/sdb:32.2 GB, 32212254720 bytes

255 heads, 63 sectors/track, 3916 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x09a1a34a

 

  Device Boot      Start         End      Blocks  Id  System

/dev/sdb1               1        3916   31455238+  83  Linux

 

Command (m forhelp): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.


对dev/sdc进行同样的操作

通过fdisk -l查看


[root@web1 ~]# fdisk -l /dev/sdb

 

Disk /dev/sdb:32.2 GB, 32212254720 bytes

255 heads, 63 sectors/track, 3916 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x09a1a34a

 

  Device Boot      Start         End      Blocks  Id  System

/dev/sdb1               1        3916   31455238+  83  Linux

[root@web1 ~]# fdisk -l /dev/sdc

 

Disk /dev/sdc:32.2 GB, 32212254720 bytes

255 heads, 63 sectors/track, 3916 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x6881f1ac

 

  Device Boot      Start         End      Blocks  Id  System

/dev/sdc1               1        3916   31455238+  83  Linux


2.建立RAID1


[root@web1 ~]# mdadm -C /dev/md0 -l 1 -n 2/dev/sdb1 /dev/sdc1

mdadm: Note: this array has metadata at thestart 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/md0 started.


输入tail -f /var/log/messages打开日志,在日志中可看到如下内容


md: bind<sdb1>

md: bind<sdc1>

md: raid1 personality registered for level1

bio: create slab <bio-1> at 1

md/raid1:md0: not clean -- startingbackground reconstruction

md/raid1:md0: active with 2 out of 2mirrors

md0: detected capacity change from 0 to32193249280

md: resync of RAID array md0

md: minimum _guaranteed_  speed: 1000 KB/sec/disk.

md: using maximum available idle IObandwidth (but not more than 200000 KB/sec) for resync.

md: using 128k window, over a total of31438720k.

 md0:unknown partition table


3.创建文件系统


先格式化该磁盘阵列

[root@web1 ~]# mkfs.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=0 blocks, Stripe width=0 blocks

1966080 inodes, 7859680 blocks

392984 blocks (5.00%) reserved for thesuper user

First data block=0

Maximum filesystem blocks=4294967296

240 block groups

32768 blocks per group, 32768 fragments pergroup

8192 inodes per group

Superblock backups stored on blocks:

       32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

       4096000

 

Writing inodetables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystemaccounting information: done

 

This filesystemwill be automatically checked every 30 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.


挂载


[root@web1 ~]# mount /dev/md0 /data

[root@web1 ~]# ll /data

total 16

drwx------2 root root 16384 Aug 13 19:18 lost+found


[root@web1 ~]# vi /etc/fstab

 

#

# /etc/fstab

# Created by anaconda on Fri Aug  1 18:02:23 2014

#

# Accessible filesystems, by reference, aremaintained under ‘/dev/disk‘

# See man pagesfstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

/dev/mapper/VolGroup-lv_root /                       ext4    defaults        1 1

UUID=e3738a2c-63a9-4c8d-99db-8e0794534f45/boot                   ext4    defaults        1 2

/dev/mapper/VolGroup-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/md0                /data                   ext4    defaults        0 0


[root@web1 ~]# mdadm -Ds

ARRAY /dev/md0 metadata=1.2name=web1.abc.local:0 UUID=562b4e91:606904d1:33e5d565:e5a9f609


写入到配置文件


[root@web1 ~]# mdadm -Ds >>/etc/mdadm.conf


重新启动验证


[root@web1 ~]# reboot


[root@web1 ~]# mount

/dev/mapper/VolGroup-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/md0 on /data type ext4 (rw)

none on /proc/sys/fs/binfmt_misc typebinfmt_misc (rw)


[root@web1 ~]# cat /proc/mdstat

Personalities : [raid1]

md0 : active raid1 sdb1[0] sdc1[1]

     31438720 blocks super 1.2 [2/2] [UU]

 

unused devices: <none>


4.模拟故障


删除一块硬盘


bubuko.com,布布扣


# cat /proc/mdstat

Personalities : [raid1]

md0 : active raid1 sdb1[0](F) sdc1[1]

      31438720 blocks super 1.2 [2/1] [_U]

 

unused devices: <none>


5.RAID1重建


新添加一块名为30GBC的磁盘


bubuko.com,布布扣


在线加入新组成单元

[root@web1 ~]# mdadm /dev/md0 -a /dev/sdb1


[root@web1 ~]# cat /proc/mdstat


本文出自 “thawliu” 博客,请务必保留此出处http://thawliu.blog.51cto.com/9274422/1540297

MDADM,布布扣,bubuko.com

MDADM

原文:http://thawliu.blog.51cto.com/9274422/1540297

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!