Red Hat Linux 7 下软件仿真 磁盘阵列(RAID)


一:磁盘阵列的简介

磁盘阵列(Redundant Arrays of Independent Disks,RAID),有“独立磁盘构成的具有冗余能力的阵列”之意。

磁盘阵列是由很多价格较便宜的磁盘,组合成一个容量巨大的磁盘组,利用个别磁盘提供数据所产生加成效果提升整个磁盘系统效能。利用这项技术,将数据切割成许多区段,分别存放在各个硬盘上。
磁盘阵列还能利用同位检查(Parity Check)的观念,在数组中任意一个硬盘故障时,仍可读出数据,在数据重构时,将数据经计算后重新置入新硬盘中。
 
二:磁盘阵列的模式

磁盘阵列其样式有三种,一是外接式磁盘阵列柜、二是内接式磁盘阵列卡,三是利用软件来仿真。
   
三:磁盘阵列仿真的具体操作步骤
    1:实验环境  RedHat7.0
        首先  用  cat /proc/partitions  查看系统中可用磁盘情况

[root@localhost ~]# cat /proc/partitions
major minor #blocks name

253 0 10485760 vda
253 1 10484142 vda1
253 16 10485760 vdb
7 0 3655680 loop0
 
    其中的 vdb 磁盘为没有被使用的,那么我们接下来就里用它来实现我们的目的
        接下来划分我们需要的分区:
         

  使用命令  fdisk  dev/vdb

  然后输入  m 获得帮助
  从中选择  n 代表需要划分一个分区
 
  接下来的分区模式选择主分区 p 也就是默认分区

 在选择Partition number (1-4, default 1): 这个随意
 
在接下来确定First sector (2048-20971519, default 2048): 这个最好选择默认,这样可以充分利用空间

接下来就是选择分区的大小:

然后就可以利用  p 查看分区有没有成功

在下面重要的地方都用蓝色标示:

[root@localhost ~]# fdisk  /dev/vdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xe42a4683.

Command (m for help): n
Partition type:
  p  primary (0 primary, 0 extended, 4 free)
  e  extended
Select (default p):
Using default response p
Partition number (1-4, default 1): 1
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +2G
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): p

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dosDisk identifier: 0xe42a4683

  Device Boot      Start        End      Blocks  Id  System
/dev/vdb1            2048    4196351    2097152  83  Linux

Command (m for help):

 
依次类推我们先划分出3个新的分区

  Device Boot      Start        End      Blocks  Id  System
/dev/vdb1            2048    4196351    2097152  83  Linux
/dev/vdb2        4196352    8390655    2097152  83  Linux
/dev/vdb3        8390656    12584959    2097152  83  Linux

 
接下来我们需要将新建立的分区功能标签修改为      raid
先在    Command (m for help):    l  输入 i

发现倒数第三行 有  fd  Linux raid auto
那么我们就找到了改为  raid  格式 所对应的命令

接下来输入 m
Command (m for help): m

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
然后发现    t      是我们需要的
以此类推将三个分区格式都修改成        Linux raid autodetect 

 点击(此处)折叠或打开

Command (m for help): t
Partition number (1-3, default 3): 1
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'

Command (m for help): p

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xe42a4683

Device Boot Start End Blocks Id System
/dev/vdb1 2048 4196351 2097152 fd Linux raid autodetect
/dev/vdb2 4196352 8390655 2097152 83 Linux
/dev/vdb3 8390656 12584959 2097152 83 Linux

Command (m for help):
 然后出来 时用  wq退出保存
 在用  命令  cat /proc/partitions  产看分区成功没

[root@localhost ~]# cat /proc/partitions
major minor #blocks name

253 0 10485760 vda
253 1 10484142 vda1
253 16 10485760 vdb
253 17 2097152 vdb1
253 18 2097152 vdb2
253 19 2097152 vdb3
7 0 3655680 loop0
    那么就该进入主题了
使用命令:
 mdadm  -C  /dev/md0  -a yes  -l 1 -n 2 -x 1 /dev/vdb{1..3}
                      -C    建立
                      -a    文件不存在建立文件
                      -l    raid级别
                      -n    设备个数
                      -x      闲置设备个数
这条命令就将/dev/md0设备做成相当于raid那个内接卡的功能 将vdb1  vdb2  设备关联  闲置设备  vdb3  以被后患

用  cat/proc/mdstat    查看设备信息

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

Personalities : [raid1]
md0 : active raid1 vdb3[2](S) vdb2[1] vdb1[0]
      2096064 blocks super 1.2 [2/2] [UU]
      [===========>.........] resync = 56.3% (1181056/2096064) finish=0.2min speed=56240K/sec
     
unused devices: <none>
因为你要用它所以需要将其格式化一种文件系统

点击(此处)折叠或打开

[root@localhost ~]# mkfs.xfs /dev/md0
meta-data=/dev/md0 isize=256 agcount=4, agsize=131004 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=524016, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
然后将其挂载到/mnt  mount  /dev/md0    /mnt(临时挂载)
如需永久挂载  vim /etc/fstab
  /dev/md0              /mnt                  xfs                defaults              0  0

[root@localhost ~]# mount /dev/md0 /mnt
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 7009908 3463992 67% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 92 942568 1% /dev/shm
tmpfs 942660 17064 925596 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/loop0 3654720 3654720 0 100% /var/www/html/pub
/dev/md0 2085824 32928 2052896 2% /mnt
这就完成了,但是很多人觉得不看到现象就不觉得成功,那我们接下来 删除它正在使用的一个分区 比如  vdb1
    使用命令    mdadm  /dev/mad0    -f  /dev/vdb1
接下来查看设备状况  用命令  cat /proc/mdstat
就会将损坏的那个分区的数据放到刚刚闲置的  vdb3
而我们如果不是查看设备信息是根本不知道它那样操作,因为是后台悄悄执行,所以并不影响我们手中的工作,我们只需定期检查,更换坏的就好
我们也可以恢复损坏的分区
 mdadm    /dev/md0    -a  /dev/vdb1      恢复设备

[root@localhost dev]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 vdb3[2] vdb2[1] vdb1[0](F)
2096064 blocks super 1.2 [2/1] [_U]
[==========>..........] recovery = 52.6% (1104448/2096064) finish=0.6min speed=25945K/sec

unused devices:
还可以执行如下命令
mdadm  /dev/md0    -r  /dev/vdb1        移除设备
mdadm  -S  /dev/md0                      停止设备

相关内容