基础程序安装
# 使用yum安装 yum -y install gdisk mdadm
检查是否安装配置过RAID
# 检查设备是否已经做过raid mdadm -E /dev/vd{b,c}
磁盘分区
# 对磁盘分区, gdisk /dev/vdb
# 列出分区类型 L
# 调整分区类型 t
# Linux RAID类型 fd00
# 保存配置 w
# 确认 y
gdisk /dev/vdb GPT fdisk (gdisk) version 0.8.10 Partition table scan: MBR: not present BSD: not present APM: not present GPT: not present Creating new GPT entries. Command (? for help): n Partition number (1-128, default 1): First sector (34-41943006, default = 2048) or {+-}size{KMGTP}: Last sector (2048-41943006, default = 41943006) or {+-}size{KMGTP}: Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): fd00 Changed type of partition to 'Linux RAID' Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/vdb. The operation has completed successfully.
gdisk /dev/vdc GPT fdisk (gdisk) version 0.8.10 Partition table scan: MBR: not present BSD: not present APM: not present GPT: not present Creating new GPT entries. Command (? for help): n Partition number (1-128, default 1): First sector (34-41943006, default = 2048) or {+-}size{KMGTP}: Last sector (2048-41943006, default = 41943006) or {+-}size{KMGTP}: Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): fd00 Changed type of partition to 'Linux RAID' Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/vdc. The operation has completed successfully.
验证分区定义是否为RAID
# 验证是否正确定义RAID
mdadm -E /dev/vd{b,c}
创建RAID
# 创建RAID0
mdadm -C /dev/md0 -l raid0 -n 2 /dev/vd{b,c} -C #创建 -l #级别 -n #RAID设备数 最后指定原始设备
mdadm -C /dev/md0 -l raid0 -n 2 /dev/vd{b,c} mdadm: partition table exists on /dev/vdb mdadm: partition table exists on /dev/vdb but will be lost or meaningless after creating array mdadm: partition table exists on /dev/vdc mdadm: partition table exists on /dev/vdc but will be lost or meaningless after creating array Continue creating array? Continue creating array? (y/n) Continue creating array? (y/n) y mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started.
检查RAID是否正确创建
# 查看是否创建RAID成功 cat /proc/mdstat # 验证是否正确定义RAID mdadm -E /dev/vd{b,c} # 查看raid0信息 mdadm -D /dev/md0
格式化并挂载RAID
# 格式化文件系统 mkfs.xfs -f /dev/md0 # 创建挂在目录 mkdir /mnt/raid0 # 挂在raid0 mount /dev/md0 /mnt/raid0/ # 查看uuid,分区类型 blkid /dev/md0 # 添加自动挂载 vim /etc/fstab /dev/md0 /mnt/raid0 xfs defaults 0 0 # 检查fstab语法 mount -av
保存配置,以便停止后重新装配
# 保存RAID配置 echo DEVICE /dev/sd{b,c}1 > /etc/mdadm.conf mdadm -Dvs >> /etc/mdadm.conf mdadm -D -s -v >> /etc/mdadm.conf mdadm --detail --scan --verbose >> /etc/mdadm.conf cat /etc/mdadm.conf
清除raid0
#取消挂载 umount /dev/md0 # 停止raid0 mdadm -S /dev/md0 # 清除成员磁盘当中阵列的超级块信息 mdadm --zero-superblock /dev/vd{b,c} # 删除或注释/etc/fstab上的挂载信息 vi /etc/fstab # /dev/md0 /mnt/raid0 xfs defaults 0 0
重新装配
# 将已经停止的阵列重新装配 mdadm -A /dev/md0 /dev/vd{b,c} # 自动装配,自动从/etc/mdadm.conf配置文件读取配置 mdadm -A /dev/md0