两块磁盘创建RAID1镜像
添加两块磁盘并分区,将分区的系统类型改为fd
fdisk -l //sdb,sdc
fdisk /dev/sdb //
创建分区 n
提示选择分区类型 p
分区号 1
起始 默认
last 默认
t
fd
p
w
安装mdadm软件包并且检查磁盘
yum install mdadm.x86_64 -y
[root@apenglinux-002 ~]# mdadm -E /dev/sdb /dev/sdc
/dev/sdb:
MBR Magic : aa55
Partition[0] : 20969472 sectors at 2048 (type fd)
/dev/sdc:
MBR Magic : aa55
Partition[0] : 20969472 sectors at 2048 (type fd)
创建RAID1设备
[root@apenglinux-002 ~]# mdadm --create /dev/md0 --level=mirror --raid-devices=2 /dev/sdb1 /dev/sdc1
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@apenglinux-002 ~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
10476544 blocks super 1.2 [2/2] [UU]
[===============>.....] resync = 78.2% (8202368/10476544) finish=0.1min speed=200018K/sec
unused devices: <none>
mdadm -E /dev/sd[b-c]1
mdadm --detail /dev/md0
在RAID设备上创建文件系统,并挂载,写入内容
mkfs.ext4 /dev/md0
mkdir /raid1
mount /dev/md0 /raid1
echo "raid test file" > /raid1/testraid.txt
开机自动挂载
echo "/dev/md0 /raid1 ext4 defaults 0 0" >> /etc/fstab
检查fstab中的条目是否有错误
mount -av
保存RAID的配置到文件“mdadm.conf”中
mdadm --detail --scan --verbose >> /etc/mdadm.conf
将磁盘sdc拔出重启,看看情况
mdadm --detail /dev/md0
...................以上省略......................
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
- 0 0 1 removed
查看数据是否存在
cat /raid1/testraid.txt
raid test file