Linux 磁盘管理--RAID1创建

1.  场景

2.  POC环境

 

# uname -a

Linux localhost 3.10.0-123.el7.x86_64 #1SMP Mon Jun 30 12:09:22 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

# cat /etc/redhat-release

CentOS Linux release 7.0.1406 (Core)

3.  具体操作

3.1.  分区

# fdisk -l

Disk /dev/sdc: 32.2 GB, 32212254720 bytes,62914560 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

 

Disk /dev/sdd: 32.2 GB, 32212254720 bytes,62914560 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

.........

# fdisk /dev/sdc

..........

Command (m for help): p

 

Disk /dev/sdc: 32.2 GB, 32212254720 bytes,62914560 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

Disk label type: dos

Disk identifier: 0x3dbf19dc

 

  Device Boot      Start        End      Blocks   Id System

 

Command (m for help): n

Partition type:

  p   primary (0 primary, 0extended, 4 free)

  e   extended

Select (default p): p

Partition number (1-4, default 1):

First sector (2048-62914559, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G}(2048-62914559, default 62914559):

Using default value 62914559

Partition 1 of type Linux and of size 30GiB is set

 

Command (m for help): t

Selected partition 1

Hex code (type L to list all codes): fd

Changed type of partition ‘Linux‘ to ‘Linuxraid autodetect‘

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

# fdisk -l/dev/sdc

 

Disk /dev/sdc: 32.2 GB, 32212254720 bytes, 62914560sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

Disk label type: dos

Disk identifier: 0x3dbf19dc

  Device Boot      Start         End      Blocks  Id  System

/dev/sdc1            2048    62914559   31456256   fd  Linux raid autodetect

/dev/sdd进行同样的分区操作

# fdisk -l/dev/sdd

 

Disk /dev/sdd: 32.2 GB, 32212254720 bytes,62914560 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

Disk label type: dos

Disk identifier: 0x2b1e2fef

 

  Device Boot      Start         End      Blocks  Id  System

/dev/sdd1            2048    62914559   31456256   fd  Linux raid autodetect

3.2.  创建RAID1

# mount /dev/cdrom /mnt/cdrom

mount: /dev/sr0 is write-protected,mounting read-only

# cd/mnt/cdrom/Packages

# ls md*

mdadm-3.2.6-31.el7.x86_64.rpm

# rpm -Uvhmdadm-3.2.6-31.el7.x86_64.rpm

error: Failed dependencies:

       libreport-filesystem is needed by mdadm-3.2.6-31.el7.x86_64

#rpm -Uvh mdadm-3.2.6-31.el7.x86_64.rpmlibreport-filesystem-2.1.11-10.el7.centos.x86_64.rpm

 

Preparing...                         ################################# [100%]

Updating / installing...

  1:libreport-filesystem-2.1.11-10.el################################# [50%]

  2:mdadm-3.2.6-31.el7              ################################# [100%]

# mdadm -c/dev/md0 -l 1 -n 2 /dev/sd[cd]1

mdadm: -c does not set the mode, and socannot be the first option.

[root@localhost Packages]# mdadm --create/dev/md0 -l 1 -n 2 /dev/sd[cd]1

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? yes

mdadm: Defaulting to version 1.2 metadata

mdadm: array /dev/md0 started.

3.3.  创建文件系统

格式化磁盘阵列

# mkfs.ext4/dev/md0

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

1966080 inodes, 7859936 blocks

392996 blocks (5.00%) reserved for thesuper user

First data block=0

Maximum filesystem blocks=2155872256

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

 

Allocating group tables: done

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystemaccounting information: done

#mkdir /data

# mount  /dev/md0  /data

# ll /data

total 16

drwx------ 2 root root 16384 Aug 15 03:01lost+found

 

设置开机自动挂载

# vi /etc/fstab

在最后添加一行

/dev/md0         /data                   ext4    defaults        0 0

# mdadm -Ds

ARRAY/dev/md0 metadata=1.2 name=localhost:0 UUID=e236da40:5469327f:1683de23:2d391d6f

写入到配置文件

# mdadm -Ds>> /etc/mdadm.conf

重启验证

#reboot

# mount

/dev/md0 on /data type ext4(rw,relatime,data=ordered)

 

# cat /proc/mdstat

Personalities : [raid1]

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

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

 

unused devices: <none>

4.  模拟故障

30GA.vmdk删除

# cat /proc/mdstat

Personalities : [raid1]

md0 : active raid1 sdc1[1]

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

 

unused devices: <none>

 

5.  重建RAID1

模拟恢复,还是30GB的硬盘,添加新的磁盘文件将30GC.VMDK

# fdisk -l

 

# mdadm /dev/md0 -a /dev/sdc1

mdadm: added /dev/sdc1

# cat /proc/mdstat

Personalities : [raid1]

md0 : active raid1 sdc1[2] sdd1[1]

      31439744 blocks super1.2 [2/1] [_U]

     [==>..................] recovery = 11.3% (3554240/31439744) finish=2.2min speed=209072K/sec

 

unused devices: <none>

查看日志

md: bind<sdc1>

md: recovery of RAID array md0

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

md: using maximum available idle IO bandwidth (but not more than200000 KB/sec) for recovery.

md: using 128k window, over a total of 31439744k.


Linux 磁盘管理--RAID1创建,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。