Chinaunix首页 | 论坛 | 博客
  • 博客访问: 783445
  • 博文数量: 231
  • 博客积分: 3217
  • 博客等级: 中校
  • 技术积分: 2053
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-04 12:01
文章分类

全部博文(231)

文章存档

2015年(1)

2013年(10)

2012年(92)

2011年(128)

分类: 服务器与存储

2011-08-19 18:24:01

实验平台

windowsXP+VMware workstation 7.1.3虚拟机+RedHat enterprise Linux5.4

基本上参照大侠写的博客;我从前面一些东西详细的实现这个过程。

第一步 增加硬盘

(就好比你新买了几块硬盘插到机器上)

点击“虚拟机“->"设置"->"添加”会弹出“添加硬件向导”;在下面选项中选择”硬盘“->"下一步”->选择创建一个新的虚拟磁盘->

选择SCSI硬盘->设置容量并在下面选项中选择“磁盘拆分多个多个文件”(在windows xp系统中多数是不支持超过2GB的文件,所以要选择磁盘拆分多个文件选项)->下一步在选择RedHat enterprise Linux5 的配置文件点击完成,就建立起一块虚拟的磁盘。接下来就按照大侠的博客走一片就行了。

完成后,按同样方法再增加3块硬盘,如下图,我一共增加了4块硬盘。

注意,在设置硬盘容量时,可以选择随数据增加或立即分配,当然选择随数据增加,这样虚拟的硬盘并不占用你的硬盘空间。

新增硬盘完成后,开机,使用fdisk命令查看磁盘的情况

[root@fedora8 ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000bbc75

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          25      200781   83  Linux
/dev/sda2              26        1044     8185117+  8e  Linux LVM

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/sdc: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/sdc doesn't contain a valid partition table

Disk /dev/sdd: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/sdd doesn't contain a valid partition table

Disk /dev/sde: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

可以看到,新增的4块硬盘/dev/sdb、/dev/sdc、/dev/sdd和/dev/sde。

下面对4块硬盘逐个进行分区

[root@fedora8 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x703fd5b5.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.


The number of cylinders for this disk is set to 1044.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): m

输入m打开帮助
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   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)

Command (m for help): n

输入n新建一个分区,因为是新盘,所以新建的分区只能是主分区,即分区号1-4。在这里提到另外一点,除了新增硬盘,其实也可以通过新增分区来实现,即在原硬盘上新增一些扩展分区(extended),RAID同样也可以基于这些分区来构建。
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1044, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-1044, default 1044):
Using default value 1044

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x571fa394

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1044     8385898+  83  Linux

更改分区的系统类型为RAID自动监测,然后不要忘记最后重要的一步选择w保存退出。

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
按同样方法依次处理其它的新增硬盘。完成后再次使用fdisk查看,4块硬盘都已经处理完毕,准备就绪。

[root@fedora8 ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000bbc75

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          25      200781   83  Linux
/dev/sda2              26        1044     8185117+  8e  Linux LVM

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x778ceb68

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1044     8385898+  fd  Linux raid autodetect

Disk /dev/sdc: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xb3cd5590

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        1044     8385898+  fd  Linux raid autodetect

Disk /dev/sdd: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x915d8050

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1        1044     8385898+  fd  Linux raid autodetect

Disk /dev/sde: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x7c809770

   Device Boot      Start         End      Blocks   Id  System
/dev/sde1               1        1044     8385898+  fd  Linux raid autodetect

 

第二步 安装mdadm

这一步比较简单,网上的相关介绍也很多,mdadm的官方下载地址

下载完成后,解压缩,编译,安装

[root@fedora8 SOURCES]# tar -zxvf mdadm-3.0.tar.gz

[root@fedora8 mdadm-3.0]# make

[root@fedora8 mdadm-3.0]# make install

mdadm安装完成后,仅生成一个可执行程序mdadm,RAID的所有操作都通过该程序实现。这也是mdadm的方便之处。

 

第三步 配置RAID5

创建RAID采用create选项(可以先使用mdadm --help熟悉下mdadm的选项和参数),查看帮助

[root@fedora8 /]# mdadm --create --help
Usage:  mdadm --create device -chunk=X --level=Y --raid-devices=Z devices

 This usage will initialise a new md array, associate some
 devices with it, and activate the array.   In order to create an
 array with some devices missing, use the special word 'missing' in
 place of the relevant device name.

 Before devices are added, they are checked to see if they already contain
 raid superblocks or filesystems.  They are also checked to see if
 the variance in device size exceeds 1%.
 If any discrepancy is found, the user will be prompted for confirmation
 before the array is created.  The presence of a '--run' can override this
 caution.

 If the --size option is given then only that many kilobytes of each
 device is used, no matter how big each device is.
 If no --size is given, the apparent size of the smallest drive given
 is used for raid level 1 and greater, and the full device is used for
 other levels.

 Options that are valid with --create (-C) are:
  --bitmap=          : Create a bitmap for the array with the given filename
  --chunk=      -c   : chunk size of kibibytes
  --rounding=        : rounding factor for linear array (==chunk size)
  --level=      -l   : raid level: 0,1,4,5,6,linear,multipath and synonyms
  --parity=     -p   : raid5/6 parity algorithm: {left,right}-{,a}symmetric
  --layout=          : same as --parity
  --raid-devices= -n : number of active devices in array
  --spare-devices= -x: number of spares (eXtras) devices in initial array
  --size=       -z   : Size (in K) of each drive in RAID1/4/5/6/10 - optional
  --force       -f   : Honour devices as listed on command line.  Don't
                     : insert a missing drive for RAID5.
  --run         -R   : insist of running the array even if not all
                     : devices are present or some look odd.
  --readonly    -o   : start the array readonly - not supported yet.
  --name=       -N   : Textual name for array - max 32 characters
  --bitmap-chunk=    : bitmap chunksize in Kilobytes.
  --delay=      -d   : bitmap update delay in seconds.

可以看到大部分选项都有简写形式,使用下面的指令创建RAID,指令可以解释为:

-Cv 创建RAID并输出详细信息

/dev/md0 RAID的设备名

-l5 level5即RAID5

-n3 3块激活磁盘/dev/sdb /dev/sdc /dev/sdd

-x1 1块备份盘/dev/sde

[root@fedora8 /]# mdadm -Cv /dev/md0 -l5 -n3 /dev/sdb /dev/sdc /dev/sdd -x1 /dev/sde
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 64K
mdadm: size set to 8388544K
mdadm: array /dev/md0 started.
查看创建RAID的结果,可以看到你的RAID的一些信息。

[root@fedora8 /]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdd[4] sde[3](S) sdc[1] sdb[0]
      16777088 blocks level 5, 64k chunk, algorithm 2 [3/2] [UU_]
      [==>..................]  recovery = 10.4% (876808/8388544) finish=10.7min speed=11636K/sec

第四步 格式化raid

[root@fedora8 /]# mkfs.ext2 /dev/md0

第五步 使用RAID

RAID创建完毕后,我的fedora8系统自动将其挂载到了/media/disk下,如果没有自动挂载的话,需要执行挂载才能使用

[root@fedora8 /]# mount /dev/md0 /mnt/raid

然后就可以进行存储了。注意若要系统启动后就可以使用RAID,需要将创建RAID和挂载的指令添加到启动脚本中。另外注意关机前不要忘了卸载RAID。

阅读(1431) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~