感谢支持
我们一直在努力

磁盘管理——RAID 1

一 什么是RAID1

RAID1,可称为镜像,将数据写到多个磁盘,比如一组数据叫做 A,那么数据会这样存在:A、A ,这样数据安全性高,但性能不佳。

两组以上的N个磁盘相互作镜像,在一些多线程操作系统中能有很好的读取速度,另外写入速度有微小的降低。除非拥有相同资料的主磁碟与镜像同时损坏,否则只要一个磁盘正常即可维持运作,可靠性最高。RAID 1就是镜像。其原理为在主硬盘上存放数据的同时也在镜像硬盘上写一样的数据。当主硬盘(物理)损坏时,镜像硬盘则代替主硬盘的工作。因为有镜像硬盘做数据备份,所以RAID 1的数据安全性在所有的RAID级别上来说是最好的。但无论用多少磁碟做RAID 1,仅算一个磁碟的容量,是所有RAID上磁盘利用率最低的一个级别。

推荐阅读:

Debian软RAID安装笔记 – 使用mdadm安装RAID1 http://www.linuxidc.com/Linux/2013-06/86487.htm

RAID技术穷途末路了吗? http://www.linuxidc.com/Linux/2013-06/86158.htm

常用RAID技术介绍以及示例演示(多图) http://www.linuxidc.com/Linux/2013-03/81481.htm

Linux实现最常用的磁盘阵列– RAID5 http://www.linuxidc.com/Linux/2013-01/77880.htm

RAID0+1和RAID5的性能测试结果 http://www.linuxidc.com/Linux/2012-07/65567.htm

二 RAID1演示

第一步 对磁盘进行分区

#对/dev/sdb进行分区
root@serv01 ~]# fdisk /dev/sdb
#对/dev/sdc进行分区
root@serv01 ~]# fdisk /dev/sdc
 
[root@serv01 ~]# ls /dev/sdb
sdb  sdb1
[root@serv01 ~]# ls /dev/sdc
sdc  sdc1

第二步 制作RAID1

[root@serv01 ~]# mdadm -C /dev/md1 -l 1 -n2 /dev/sdb1 /dev/sdc1
mdadm: /dev/sdb1 appears to contain anext2fs file system
  size=208812K  mtime=Wed Jul 3122:17:43 2013
mdadm: /dev/sdb1 appears to be part of araid array:
  level=raid0 devices=0 ctime=Thu Jan 1 07:00:00 1970
mdadm: partition table exists on /dev/sdb1but will be lost or
      meaningless after creating array
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/md1 started.
#格式化
[root@serv01 ~]# mkfs.ext4 /dev/md1
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
131072 inodes, 523853 blocks
26192 blocks (5.00%) reserved for the superuser
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments pergroup
8192 inodes per group
Superblock backups stored on blocks:
      32768,98304, 163840, 229376, 294912
 
Writing inode tables: done                         
Creating journal (8192 blocks): done
Writing superblocks and filesystemaccounting information: done
 
This filesystem will be automaticallychecked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

第三步 挂载

[root@serv01 ~]# mount /dev/md1 /web
[root@serv01 ~]# cat /etc/fstab
 
#
# /etc/fstab
# Created by anaconda on Tue Jul 2300:54:37 2013
#
# Accessible filesystems, by reference, aremaintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8),mount(8) and/or blkid(8) for more info
#
UUID=110fab7c-85c4-4bae-9114-98bc2ada24d8/                      ext4    defaults        1 1
UUID=ab434325-bf02-48e9-8ce7-78494a8ac71e/boot                  ext4    defaults        1 2
UUID=02ed2b3b-b7e1-493d-9a43-8e1dcac8aa6f/opt                    ext4    defaults        1 2
UUID=a088a35a-16d8-456a-a177-95c769c16e41swap                    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

第四步 修改配置文件

#追加内容到/etc/fstab文件
[root@serv01 ~]# echo “/dev/md1 /webext4 defaults 1 2” >> /etc/fstab
#再次查看文件内容
[root@serv01 ~]# cat /etc/fstab
 
#
# /etc/fstab
# Created by anaconda on Tue Jul 2300:54:37 2013
#
# Accessible filesystems, by reference, aremaintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8),mount(8) and/or blkid(8) for more info
#
UUID=110fab7c-85c4-4bae-9114-98bc2ada24d8/                      ext4    defaults        1 1
UUID=ab434325-bf02-48e9-8ce7-78494a8ac71e/boot                  ext4    defaults        1 2
UUID=02ed2b3b-b7e1-493d-9a43-8e1dcac8aa6f/opt                    ext4    defaults        1 2
UUID=a088a35a-16d8-456a-a177-95c769c16e41swap                    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/md1 /web ext4 defaults 1 2
#创建mdadm.conf文件
[root@serv01 ~]# mdadm –detail —scan >/etc/mdadm.conf

第五步 模拟硬盘坏掉

#重启
[root@serv01 ~]# reboot
#拷贝内容
[root@serv01 ~]# cp /boot/* /web/ -rvf
#清除磁盘,o清除,然后保存
[root@serv01 ~]# fdisk /dev/sdb
#拷贝内容
[root@serv01 ~]# cp /etc/* /web/ -rvf
     
#重启
[root@larrywen Desktop]# ssh 192.168.1.11
root@192.168.1.11’s password:
Last login: Thu Aug  1 17:55:43 2013 from 192.168.1.1
[root@serv01 ~]# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sdc1[1] sdb1[0]
    2095415 blocks super 1.2 [2/2] [UU]
   
unused devices: <none>
 
[root@larrywen Desktop]# ssh 192.168.1.11
root@192.168.1.11’s password:
Last login: Thu Aug  1 18:05:58 2013 from 192.168.1.1
#查看状态
[root@serv01 ~]# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sdc1[1]
    2095415 blocks super 1.2 [2/1] [_U]
   
unused devices: <none>
 
[root@serv01 ~]# mdadm –detail /dev/md1
/dev/md1:
      Version : 1.2
 Creation Time : Thu Aug  117:58:09 2013
    Raid Level : raid1
    Array Size : 2095415 (2046.65 MiB 2145.70 MB)
 Used Dev Size : 2095415 (2046.65 MiB 2145.70 MB)
  Raid Devices : 2
 Total Devices : 1
  Persistence : Superblock is persistent
 
  Update Time : Thu Aug  1 18:07:522013
        State : clean, degraded
 Active Devices : 1
Working Devices : 1
 FailedDevices : 0
 Spare Devices : 0
 
          Name : serv01.host.com:1  (localto host serv01.host.com)
          UUID : a8930aef:a5ddcdde:789a11bf:40f7eed6
        Events : 23
 
  Number  Major  Minor  RaidDevice State
      0      0        0      0      removed
      1      8      33      1      active sync  /dev/sdc1
#拷贝内容
[root@serv01 web]# cp /boot/* . -rvf
[root@serv01 web]# mount
/dev/sda2 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,rootcontext=”system_u:object_r:tmpfs_t:s0″)
/dev/sda1 on /boot type ext4 (rw)
/dev/sda5 on /opt type ext4 (rw)
/dev/md1 on /web type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc(rw)
/dev/sr0 on /iso type iso9660 (ro)
[root@serv01 web]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2            9.7G  1.1G 8.1G  12% /
tmpfs                188M    0 188M  0% /dev/shm
/dev/sda1            194M  25M 160M  14% /boot
/dev/sda5            4.0G  137M 3.7G  4% /opt
/dev/md1              2.0G  54M 1.9G  3% /web
/dev/sr0              3.4G  3.4G    0 100% /iso

接下来请看第2页精彩内容: http://www.linuxidc.com/Linux/2013-08/88616p2.htm

第六步 添加磁盘

#添加另一个磁盘
[root@serv01 web]# fdisk /dev/sdd
[root@serv01 web]# ls /dev/sdd
sdd sdd1
[root@serv01 web]# mdadm –manage /dev/md1–add /dev/sdd1
mdadm: added /dev/sdd1
[root@serv01 web]# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sdd1[2] sdc1[1]
2095415 blocks super 1.2 [2/1] [_U]
[=========>………..] recovery = 47.7% (1000064/2095415) finish=0.0min speed=250016K/sec

unused devices: <none>

[root@serv01web]# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sdd1[2] sdc1[1]
2095415 blocks super 1.2 [2/2] [UU]

unused devices: <none>
[root@serv01web]# reboot
[root@larrywenDesktop]# ssh 192.168.1.11
root@192.168.1.11’s password:
Last login: Thu Aug 1 18:08:05 2013 from 192.168.1.1
[root@serv01 ~]# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sdd1[2] sdc1[1]
2095415 blocks super 1.2 [2/2] [UU]

unused devices: <none>
[root@serv01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.7G 1.1G 8.1G 12% /
tmpfs 188M 0 188M 0% /dev/shm
/dev/sda1 194M 25M 160M 14% /boot
/dev/sda5 4.0G 137M 3.7G 4% /opt
/dev/md1 2.0G 54M 1.9G 3% /web
/dev/sr0 3.4G 3.4G 0 100% /iso

[root@serv01 ~]# mdadm –detail /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Thu Aug 117:58:09 2013
Raid Level : raid1
Array Size : 2095415 (2046.65 MiB 2145.70 MB)
Used Dev Size : 2095415 (2046.65 MiB 2145.70 MB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent

Update Time : Thu Aug 1 18:18:482013
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

Name : serv01.host.com:1 (localto host serv01.host.com)
UUID :a8930aef:a5ddcdde:789a11bf:40f7eed6
Events : 60

Number Major Minor RaidDevice State
2 8 49 0 active sync /dev/sdd1
1 8 33 1 active sync /dev/sdc1

#不重启添加磁盘
#干掉/dev/sdc,o
[root@serv01 ~]# fdisk /dev/sdc
#查看详细信息,发现没坏
[root@serv01 ~]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Thu Aug 117:58:09 2013
Raid Level : raid1
Array Size : 2095415 (2046.65 MiB 2145.70 MB)
Used Dev Size : 2095415 (2046.65 MiB 2145.70 MB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent

Update Time : Thu Aug 1 18:24:242013
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

Name : serv01.host.com:1 (localto host serv01.host.com)
UUID : a8930aef:a5ddcdde:789a11bf:40f7eed6
Events : 60

Number Major Minor RaidDevice State
2 8 49 0 active sync /dev/sdd1
1 8 33 1 active sync /dev/sdc1
#拷贝文件也不能看到
[root@serv01 ~]# cp /etc/inittab /web
#查看详细信息
[root@serv01 ~]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Thu Aug 117:58:09 2013
Raid Level : raid1
Array Size : 2095415 (2046.65 MiB 2145.70 MB)
Used Dev Size : 2095415 (2046.65 MiB 2145.70 MB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent

Update Time : Thu Aug 1 18:27:312013
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

Name : serv01.host.com:1 (localto host serv01.host.com)
UUID : a8930aef:a5ddcdde:789a11bf:40f7eed6
Events : 60

Number Major Minor RaidDevice State
2 8 49 0 active sync /dev/sdd1
1 8 33 1 active sync /dev/sdc1

#标志/dev/sdc1错误
root@serv01 ~]# mdadm –manage /dev/md1–fail /dev/sdc1
mdadm: set /dev/sdc1 faulty in /dev/md1
#查看状态
[root@serv01 ~]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Thu Aug 117:58:09 2013
Raid Level : raid1
Array Size : 2095415 (2046.65 MiB 2145.70 MB)
Used Dev Size : 2095415 (2046.65 MiB 2145.70 MB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent

Update Time : Thu Aug 1 18:28:312013
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 1
Spare Devices : 0

Name : serv01.host.com:1 (localto host serv01.host.com)
UUID : a8930aef:a5ddcdde:789a11bf:40f7eed6
Events : 61

Number Major Minor RaidDevice State
2 8 49 0 active sync /dev/sdd1
1 0 0 1 removed

1 8 33 – faulty spare /dev/sdc1
[root@serv01 ~]# fdisk /dev/sde
#添加/dev/sde1硬盘
[root@serv01 ~]# mdadm –manage /dev/md1–add /dev/sde1
mdadm: added /dev/sde1
#查看详细信息
[root@serv01 ~]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Thu Aug 117:58:09 2013
Raid Level : raid1
Array Size : 2095415 (2046.65 MiB 2145.70 MB)
Used Dev Size : 2095415 (2046.65 MiB 2145.70 MB)
Raid Devices : 2
Total Devices : 3
Persistence : Superblock is persistent

Update Time : Thu Aug 1 18:29:562013
State : clean, degraded, recovering
Active Devices : 1
Working Devices : 2
Failed Devices : 1
Spare Devices : 1

Rebuild Status : 85% complete

Name : serv01.host.com:1 (localto host serv01.host.com)
UUID : a8930aef:a5ddcdde:789a11bf:40f7eed6
Events : 80

Number Major Minor RaidDevice State
2 8 49 0 active sync /dev/sdd1
3 8 65 1 spare rebuilding /dev/sde1

1 8 33 – faulty spare /dev/sdc1
#移除磁盘
[root@serv01 ~]# mdadm –manage /dev/md1–remove /dev/sdc1
mdadm: hot removed /dev/sdc1 from /dev/md1
[root@serv01 ~]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Thu Aug 117:58:09 2013
Raid Level : raid1
Array Size : 2095415 (2046.65 MiB 2145.70 MB)
Used Dev Size : 2095415 (2046.65 MiB 2145.70 MB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent

Update Time : Thu Aug 1 18:30:092013
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

Name : serv01.host.com:1 (local to host serv01.host.com)
UUID : a8930aef:a5ddcdde:789a11bf:40f7eed6
Events : 87

Number Major Minor RaidDevice State
2 8 49 0 active sync /dev/sdd1
3 8 65 1 active sync /dev/sde1

第七步 实验完毕,清空磁盘

[root@serv01 ~]# umount /dev/md1
#停掉
[root@serv01 ~]# mdadm –manage /dev/md1–stop
mdadm: stopped /dev/md1
#删除配置文件
[root@serv01 ~]# rm -rf /etc/mdadm.conf
[root@serv01 ~]# fdisk -l |grep -e sdb -esdc -e sdd -e sde
Disk /dev/sdf doesn’t contain a validpartition table
Disk /dev/sdg doesn’t contain a validpartition table
Disk /dev/sdb: 2147 MB, 2147483648 bytes
Disk /dev/sdc: 2147 MB, 2147483648 bytes
Disk /dev/sdd: 2147 MB, 2147483648 bytes
Disk /dev/sde: 2147 MB, 2147483648 bytes

#清除磁盘
[root@serv01 ~]# mdadm –misc—zero-superblock /dev/sdb1
[root@serv01 ~]# fdisk /dev/sdb
#清除磁盘
[root@serv01 ~]# mdadm –misc—zero-superblock /dev/sdc1
[root@serv01 ~]# fdisk /dev/sdc

三 相关文章

磁盘管理——RAID 0  http://www.linuxidc.com/Linux/2013-08/88577.htm

赞(0) 打赏
转载请注明出处:服务器评测 » 磁盘管理——RAID 1
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏