CentOS/Redhat 如何创建软raid1
时间:2019-11-20 08:52:43 来源:igfitidea点击:
raid1 也称为镜像备份。
两块磁盘的数据一模一样。
RAID设备是由两个或多个实际块设备创建的虚拟设备。Linux支持RAID1和其他级别。您需要在两个磁盘上有相同大小的分区,即在第二个磁盘上创建与第一个磁盘完全相同的分区,并将类型设置为fd(Linux raid autodetect)。您需要使用以下命令来创建raid1。
在CentOS Linux中创建软raid1
查看磁盘分区
# fdisk -l # fdisk -l /dev/sdb # fdisk -l /dev/sdc
输出示例
Disk /dev/sdb: 73.2 GB, 73295462400 bytes 255 heads, 63 sectors/track, 8910 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 * 1 37 297171 83 Linux Disk /dev/sdc: 73.2 GB, 73295462400 bytes 255 heads, 63 sectors/track, 8910 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdc1 * 1 37 297171 83 Linux
修改分区标签
# fdisk /dev/sdb
输出示例:
Command (m for help): p Disk /dev/sdb: 73.2 GB, 73295462400 bytes 255 heads, 63 sectors/track, 8910 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 * 1 37 297171 83 Linux Command (m for help): t Partition number (1-5): 3 Hex code (type L to list codes): fd Changed system type of partition 3 to fd (Linux raid autodetect) Command (m for help): p Disk /dev/sdb: 73.2 GB, 73295462400 bytes 255 heads, 63 sectors/track, 8910 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 * 1 37 297171 fd Linux Command (m for help): w The partition table has been altered!
可以看到id由83变成fd。
同样对sdc进行操作
# fdisk /dev/sdc
重新加载分区
# partprobe /dev/sdb # partprobe /dev/sdc
或者
# echo 1 > /sys/block/sdb/device/rescan # echo 1 > /sys/block/sdc/device/rescan
创建raid1阵列
使用/dev/sdb1和/dev/sdc1创建RAID1
# mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
查看RAID创建进度,
# watch cat /proc/mdstat
在新的软raid设备上创建文件系统
# mkfs.ext3 /dev/md0
mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 4872896 inodes, 9737360 blocks 486868 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 298 block groups 32768 blocks per group, 32768 fragments per group 16352 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 39 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
将RAID1挂载到/raid1
执行以下命令:
# mkdir /raid1 # mount /dev/md0 /raid1/ # df -H /raid1/
输出示例:
Filesystem Size Used Avail Use% Mounted on /dev/md0 40G 185M 38G 1% /raid1
如何测试RAID 1的速度?
可以使用dd命令,如下所示:
使用dd命令一定要注意
# cd /raid1/ # dd if=/dev/zero of=output bs=8k count=256k # rm output
262144+0 records in 262144+0 records out 2147483648 bytes (2.1 GB) copied, 6.01068 seconds, 357 MB/s
更新/etc/fstab
设置系统启动时,自动挂载软raid文件系统
# echo '/dev/md0 /raid1 ext3 noatime,rw 0 0' >> /etc/fstab
如何获取有关RAID 1的详细信息?
输入以下命令:
# mdadm --query --detail /dev/md0
输出示例:
/dev/md0: Version : 0.90 Creation Time : Wed May 26 01:58:53 2010 Raid Level : raid1 Array Size : 38949440 (37.15 GiB 39.88 GB) Used Dev Size : 38949440 (37.15 GiB 39.88 GB) Raid Devices : 2 Total Devices : 2 Preferred Minor : 0 Persistence : Superblock is persistent Update Time : Wed May 26 12:18:22 2010 State : clean Active Devices : 2 Working Devices : 2 Failed Devices : 0 Spare Devices : 0 UUID : b6f207e1:7f73424f:53f63bfd:e76b77d8 Events : 0.2 Number Major Minor RaidDevice State 0 8 3 0 active sync /dev/sda3 1 8 17 1 active sync /dev/sdb1