1. 首页
  2. IT资讯

linux下软raid的实现

raid是当前存储提高安全和性能的主要技术手段,实现raid一般用raid卡实现,也就是硬raid。除此之外,我们还可以用软件来实现raid技术。这篇文章就简单介绍如何用软件实现raid技术(以raid0为例)。有两个可以实现软raid的工具:raidtools, mdadm。raidtool,这是在RHEL3中所使用的,但是我在RHEL4中没有找到raidtool,只有mdadm,看来RH也是偏向于使用mdadm的。本文也以mdadm为例讲述。一、查看当前硬盘情况[root@primary /]# fdisk -lDisk /dev/sda: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83 Linux/dev/sda2 14 1114 8843782+ 83 Linux/dev/sda3 1115 1305 1534207+ 82 Linux swapDisk /dev/sdb: 107 MB, 107374080 bytes64 heads, 32 sectors/track, 102 cylindersUnits = cylinders of 2048 * 512 = 1048576 bytesDisk /dev/sdb doesn’t contain a valid partition tableDisk /dev/sdc: 107 MB, 107374080 bytes64 heads, 32 sectors/track, 102 cylindersUnits = cylinders of 2048 * 512 = 1048576 bytesDisk /dev/sdc doesn’t contain a valid partition table二、为硬盘分区raid一般多个硬盘来组成,你也可以用同一个硬盘的多个分区组成raid,但这样是没有意义的。[root@primary /]# fdisk /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel. Changes will remain in memory only,until you decide to write them. After that, of course, the previouscontent won’t be recoverable.Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)Command (m for help): nCommand action e extended p primary partition (1-4)pPartition number (1-4): 1First cylinder (1-102, default 1): Using default value 1Last cylinder or +size or +sizeM or +sizeK (1-102, default 102): Using default value 102Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.[root@primary /]# fdisk /dev/sdcDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel. Changes will remain in memory only,until you decide to write them. After that, of course, the previouscontent won’t be recoverable.Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)Command (m for help): nCommand action e extended p primary partition (1-4)pPartition number (1-4): 1First cylinder (1-102, default 1): Using default value 1Last cylinder or +size or +sizeM or +sizeK (1-102, default 102): Using default value 102Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.此时硬盘的分区情况:[root@primary /]# fdisk -lDisk /dev/sda: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83 Linux/dev/sda2 14 1114 8843782+ 83 Linux/dev/sda3 1115 1305 1534207+ 82 Linux swapDisk /dev/sdb: 107 MB, 107374080 bytes64 heads, 32 sectors/track, 102 cylindersUnits = cylinders of 2048 * 512 = 1048576 bytes Device Boot Start End Blocks Id System/dev/sdb1 1 102 104432 83 LinuxDisk /dev/sdc: 107 MB, 107374080 bytes64 heads, 32 sectors/track, 102 cylindersUnits = cylinders of 2048 * 512 = 1048576 bytes Device Boot Start End Blocks Id System/dev/sdc1 1 102 104432 83 Linux三、创建raid0[root@primary /]# mdadm –create /dev/md0 –level=raid0 –chunk=8 –raid-devices=2 /dev/sdb1 /dev/sdc1四、格式化raidmdadm: array /dev/md0 started.[root@primary /]# mkfs.ext3 /dev/md0mke2fs 1.35 (28-Feb-2004)max_blocks 213647360, rsv_groups = 26080, rsv_gdb = 256Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)52208 inodes, 208640 blocks10432 blocks (5.00%) reserved for the super userFirst data block=1Maximum filesystem blocks=6737100826 block groups8192 blocks per group, 8192 fragments per group2008 inodes per groupSuperblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729, 204801Writing inode tables: done inode.i_blocks = 3586, i_size = 67383296Creating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 26 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.五、挂载raid分区[root@primary /]# mount /dev/md0 /opt[root@primary /]# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda2 8.4G 5.7G 2.3G 73% //dev/sda1 99M 8.4M 86M 9% /bootnone 252M 0 252M 0% /dev/shm/dev/hdc 161M 161M 0 100% /media/cdrom/dev/md0 198M 5.8M 182M 4% /opt六、查看raid的信息[root@primary opt]# mdadm –detail /dev/md0/dev/md0: Version : 00.90.01 Creation Time : Sun Jul 8 22:54:28 2007 Raid Level : raid0 Array Size : 208640 (203.75 MiB 213.65 MB) Raid Devices : 2 Total Devices : 2Preferred Minor : 0 Persistence : Superblock is persistent Update Time : Sun Jul 8 22:54:29 2007 State : clean Active Devices : 2Working Devices : 2 Failed Devices : 0 Spare Devices : 0 Chunk Size : 8K Number Major Minor RaidDevice State 0 8 17 0 active sync /dev/sdb1 1 8 33 1 active sync /dev/sdc1 UUID : a86f0502:df5715c0:fd871bbc:9f75e0ad Events : 0.1 七、生成mdadm配置文件mdadm的缺省配置文件为/etc/mdadm.conf,它主要是为了方便阵列的日常管理而设置的,对于阵列而言不是必须的,但是为了减少日后管理中不必要的麻烦,还是应该坚持把这一步做完。在mdadm.conf文件中要包含两种类型的行:一种是以DEVICE开头的行,它指明在阵列中的设备列表;另一种是以ARRAY开头的行,它详细地说明了阵列的名称、模式、阵列中活动设备的数目以及设备的UUID号。 我们可以用mdadm -Ds来得到mdadm.conf文件需要的信息: [root@primary ~]# mdadm -DsARRAY /dev/md0 level=raid0 num-devices=2 UUID=63f24968:d367038d:f207e458:9a803df9 devices=/dev/sdb1,/dev/sdc1根据上面的信息编辑/etc/mdadm.conf,如下:[root@primary ~]# more /etc/mdadm.conf ARRAY /dev/md0 level=raid0 num-devices=2 UUID=63f24968:d367038d:f207e458:9a803df9device /dev/sdb1 /dev/sdc1 如果不配置这个文件,在重启后尝试mount raid设备的时候会报错:[root@primary ~]# mount /dev/md0 /opt/dev/md0: Invalid argumentmount: /dev/md0: can’t read superblock八、设置开机自动挂载为了让系统开机后能自动挂载raid设备,需要在/etc/fstab添加如下行:vi /etc/fstab/dev/md0 /opt ext3 defaults 0 0至此,一个raid0就算配置完毕了。其他级别的raid也可以用类似的方法配置,具体可以看帮助。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/231499/viewspace-63836/,如需转载,请注明出处,否则将追究法律责任。

主题测试文章,只做测试使用。发布者:布吉卡,转转请注明出处:http://www.cxybcw.com/195733.html

联系我们

13687733322

在线咨询:点击这里给我发消息

邮件:1877088071@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

QR code