centos 中 软RAID创建

运维 ouk 1247℃ 0评论

软RAID创建,这里是在虚拟机中操作,对分区进行raid
首先添加一个硬盘,然后对其进行分区
1、查看磁盘情况
[root@localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

2、对磁盘进行分区
[root@localhost ~]# 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 0xb186dd35.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): +1G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (133-652, default 133):
Using default value 133
Last cylinder, +cylinders or +size{K,M,G} (133-652, default 652): +1G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (265-652, default 265):
Using default value 265
Last cylinder, +cylinders or +size{K,M,G} (265-652, default 652): +1G

划分三个主分区,每个分区的大小为1G,然后对每个分区进行修改system id
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): fd
Changed system type of partition 2 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): fd
Changed system type of partition 3 to fd (Linux raid autodetect)

输入p命令查看分区状态,确认分区是否正确
然后w保存
通过fdisk查看分区
[root@localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb186dd35
Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ fd Linux raid autodetect
/dev/sdb2 133 264 1060290 fd Linux raid autodetect
/dev/sdb3 265 396 1060290 fd Linux raid autodetect

查看内核是否识别
接下开始创建RAID5
[root@localhost ~]# mdadm -C /dev/md5 -a yes -l5 -n3 /dev/sdb{1,2,3}
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md5 : active raid5 sdb3[3] sdb2[1] sdb1[0]
2117632 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [UU_]
[==================>..] recovery = 93.4% (990472/1058816) finish=0.0min speed=24720K/sec
unused devices:

使用mdadm 创建raid ,使用cat /proc/mdstat查看raid情况,上述情况表示正在进行数据同步
对raid对象进行格式化

[root@localhost ~]# mke2fs -j /dev/md5
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
132464 inodes, 529408 blocks
26470 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=545259520
17 block groups
32768 blocks per group, 32768 fragments per group
7792 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

使用“mdadm -D /dev/md5”查看raid详细信息,查看磁盘块是否正常
[root@localhost ~]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Tue May 5 17:51:50 2015
Raid Level : raid5
Array Size : 2117632 (2.02 GiB 2.17 GB)
Used Dev Size : 1058816 (1034.17 MiB 1084.23 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Tue May 5 17:58:08 2015
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Name : localhost.localdomain:5 (local to host localhost.localdomain)
UUID : 4ca12450:a15a9b40:474ac08b:a41d2f2a
Events : 18
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 18 1 active sync /dev/sdb2
3 8 19 2 active sync /dev/sdb3

然后将该RAID对象挂载” mount /dev/md5 ~/test/”
整个RAID创建过完成 如果需要开机启动自动挂载,则添加到/etc/fstab中
模拟RAID中磁盘块损坏 “mdadm /dev/md5 –fail /dev/sdb1” ,用“mdadm -D /dev/md5 查看raid详细信息”测试一块磁盘损坏情况下磁盘是否正常工作,结论是raid正常数据未丢失
移除损坏磁盘”mdadm /dev/md5 -r /dev/sda1“
重新添加磁盘 ”mdadm /dev/md5 -a /dev/sda1“
清除阵列,”mdadm -S /dev/ma5 “ 然后删除/dev/ma5整个整列就删除了 停止阵列先umount 卸载
重启阵列,”[root@localhost ~]# mdadm -A /dev/md5 /dev/{sdb1,sdb2,sdb3}“
”mdadm -D –scan“查看RAID配置
将当前RAID信息保存至配置文件,以便以后进行装配:
mdamd -D –scan > /etc/mdadm.conf
后面重启阵列就不需加磁盘块”mdadm -A /dev/md5“
软raid性能优化
mke2fs -j -E stride=16 -b 4096 /dev/md5 定义stride ,stride等于chunks除以块大小

转载请注明:OUK技术人生 » centos 中 软RAID创建

喜欢 (0)
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址