Linux磁盘阵列
RAID概念
RAID可以预防数据丢失,但是它并不能完全保证你的数据不会丢失,所以大家使用RAID的同时还是注意备份重要的数据
RAID的创建有两种方式:软RAID(通过操作系统软件来实现)和硬RAID(使用硬件阵列卡);了解raid1、raid5和raid10。不过随着云的高速发展,供应商一般可以把硬件问题解决掉。
RAID基本思想:把好几块硬盘通过一定组合方式把它组合起来,成为一个新的硬盘阵列组,从而使它能够达到高性能硬盘的要求
RAID三个关键技术:
镜像:提供了数据的安全性;
条带(块大小也可以说是条带的粒度),它的存在的就是提供了数据并发性
数据的校验:提供了数据的安全
RAID的实现方式
面试题:我们做硬件RAID,是在装系统前还是之后?
答:先做阵列才装系统 ,一般服务器启动时,有显示进入配置Riad的提示。
硬RAID:需要RAID卡,我们的磁盘是接在RAID卡的,由它统一管理和控制。数据也由它来进行分配和维护;它有自己的cpu,处理速度快
软RAID:通过操作系统实现
mdadm命令详解:
-a 添加磁盘
-n 指定设备数量
-l 指定RAID级别
-C 创建
-V 显示过程
-f 模拟设备损坏
-r 移除设备
-Q 查看摘要信息
-D 查看详细信息
-S 停止RAID 磁盘阵列
mdadm创建raid阵列–raid10
第一步:添加四块磁盘
[root@ken ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdc /dev/sdd /dev/sde
第二步:下载mdadm
[root@ken ~]# yum install mdadm -y
第三步:创建RAID10阵列
[root@ken ~]# mdadm -C -v /dev/md10 -l 10 -n 4 /dev/sd{b,c,d,e}
mdadm: layout defaults to n2
mdadm: layout defaults to n2
mdadm: chunk size defaults to 512K
mdadm: size set to 20954112K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md10 started.
第四步:查看阵列信息
[root@ken ~]# mdadm -D /dev/md10
/dev/md10:
Version : 1.2
Creation Time : Wed May 15 18:39:37 2019
Raid Level : raid10
Array Size : 41908224 (39.97 GiB 42.91 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 4
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Wed May 15 18:40:09 2019
State : clean, resyncing
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0
Layout : near=2
Chunk Size : 512K
Consistency Policy : resync
Resync Status : 15% complete
Name : ken:10 (local to host ken)
UUID : 9e7f9023:2a2fa0d0:14815344:78bc6f6b
Events : 2
Number Major Minor RaidDevice State
0 8 16 0 active sync set-A /dev/sdb
1 8 32 1 active sync set-B /dev/sdc
2 8 48 2 active sync set-A /dev/sdd
3 8 64 3 active sync set-B /dev/sde
第五步:格式化
[root@ken ~]# mkfs.xfs /dev/md10
meta-data=/dev/md10 isize=512 agcount=16, agsize=654720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=10475520, imaxpct=25
= sunit=128 swidth=256 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=5120, version=2
= sectsz=512 sunit=8 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
第六步:挂载使用
[root@ken ~]# mount /dev/md10 /ken
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.4G 16G 8% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.7M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr0 4.2G 4.2G 0 100% /mnt
/dev/md10 40G 33M 40G 1% /ken
第七步:创建文件
[root@ken ~]# touch /ken/{1..100}.txt
[root@ken ~]# ls /ken
100.txt 17.txt 24.txt 31.txt 39.txt 46.txt 53.txt 60.txt 68.txt 75.txt 82.txt 8.txt 97.txt
10.txt 18.txt 25.txt 32.txt 3.txt 47.txt 54.txt 61.txt 69.txt 76.txt 83.txt 90.txt 98.txt
11.txt 19.txt 26.txt 33.txt 40.txt 48.txt 55.txt 62.txt 6.txt 77.txt 84.txt 91.txt 99.txt
12.txt 1.txt 27.txt 34.txt 41.txt 49.txt 56.txt 63.txt 70.txt 78.txt 85.txt 92.txt 9.txt
13.txt 20.txt 28.txt 35.txt 42.txt 4.txt 57.txt 64.txt 71.txt 79.txt 86.txt 93.txt
14.txt 21.txt 29.txt 36.txt 43.txt 50.txt 58.txt 65.txt 72.txt 7.txt 87.txt 94.txt
15.txt 22.txt 2.txt 37.txt 44.txt 51.txt 59.txt 66.txt 73.txt 80.txt 88.txt 95.txt
16.txt 23.txt 30.txt 38.txt 45.txt 52.txt 5.txt 67.txt 74.txt 81.txt 89.txt 96.txt
[root@ken ~]# umount /dev/md10
[root@ken ~]#
[root@ken ~]#
[root@ken ~]# ls /ken
[root@ken ~]#
第八步:写入到文件
方法一、
[root@ken ~]# echo “mount /dev/md10 /ken” >> /etc/rc.local
方法二、
[root@ken ~]# echo “/dev/md10 /ken xfs defaults 0 0 ” >> /etc/fstab
mdadm管理raid10阵列–模拟磁盘损坏后的处理方式
第一步:模拟损坏磁盘
[root@ken ~]# mdadm /dev/md10 -f /dev/sdd
mdadm: set /dev/sdd faulty in /dev/md10
[root@ken ~]# mdadm -D /dev/md10
/dev/md10:
Version : 1.2
Creation Time : Wed May 15 18:39:37 2019
Raid Level : raid10
Array Size : 41908224 (39.97 GiB 42.91 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 4
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Wed May 15 18:46:53 2019
State : clean, degraded
Active Devices : 3
Working Devices : 3
Failed Devices : 1
Spare Devices : 0
Layout : near=2
Chunk Size : 512K
Consistency Policy : resync
Name : ken:10 (local to host ken)
UUID : 9e7f9023:2a2fa0d0:14815344:78bc6f6b
Events : 26
Number Major Minor RaidDevice State
0 8 16 0 active sync set-A /dev/sdb
1 8 32 1 active sync set-B /dev/sdc
– 0 0 2 removed
3 8 64 3 active sync set-B /dev/sde
2 8 48 – faulty /dev/sdd #显示/dev/sdd磁盘已经损坏
第二步:重启
第三步:添加磁盘
[root@ken ~]# mdadm /dev/md10 -a /dev/sdd
mdadm: added /dev/sdd
[root@ken ~]# mdadm -D /dev/md10
/dev/md10:
Version : 1.2
Creation Time : Wed May 15 18:39:37 2019
Raid Level : raid10
Array Size : 41908224 (39.97 GiB 42.91 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 4
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Wed May 15 18:49:56 2019
State : clean, degraded, recovering
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : near=2
Chunk Size : 512K
Consistency Policy : resync
Rebuild Status : 9% complete
Name : ken:10 (local to host ken)
UUID : 9e7f9023:2a2fa0d0:14815344:78bc6f6b
Events : 29
Number Major Minor RaidDevice State
0 8 16 0 active sync set-A /dev/sdb
1 8 32 1 active sync set-B /dev/sdc
4 8 48 2 spare rebuilding /dev/sdd
3 8 64 3 active sync set-B /dev/sde
mdadm创建RAID阵列–RAID5+热备盘
第一步:添加四块磁盘
[root@ken ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdc /dev/sdd /dev/sde
第二步:创建磁盘阵列RAID5
失败演示:
[root@ken ~]# mdadm -C /dev/ken -l 5 -n 3 -x 1 /dev/sd{b,c,d,e} #磁盘阵列名需要以md开头
mdadm: /dev/ken is an invalid name for an md device. Try /dev/md/ken
正确演示:
[root@ken ~]# mdadm -C /dev/md5 -l 5 -n 3 -x 1 /dev/sd{b,c,d,e}
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
第三步:查看阵列信息
[root@ken ~]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Wed May 15 19:08:06 2019
Raid Level : raid5
Array Size : 41908224 (39.97 GiB 42.91 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Wed May 15 19:09:16 2019
State : clean, degraded, recovering
Active Devices : 2
Working Devices : 4
Failed Devices : 0
Spare Devices : 2
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Rebuild Status : 44% complete
Name : ken:5 (local to host ken)
UUID : 118db989:9ac48e2f:30313d35:4a0268e7
Events : 8
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
4 8 48 2 spare rebuilding /dev/sdd
3 8 64 – spare /dev/sde
第四步:格式化
[root@ken ~]# mkfs.xfs /dev/md5
meta-data=/dev/md5 isize=512 agcount=16, agsize=654720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=10475520, imaxpct=25
= sunit=128 swidth=256 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=5120, version=2
= sectsz=512 sunit=8 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
第五步:挂载
[root@ken ~]# mkdir /ken
[root@ken ~]# mount /dev/md5 /ken
mdadm管理raid5阵列–模拟磁盘损坏后的处理方式
第一步:查看阵列状态
[root@ken ~]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Wed May 15 19:08:06 2019
Raid Level : raid5
Array Size : 41908224 (39.97 GiB 42.91 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Wed May 15 19:11:12 2019
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : ken:5 (local to host ken)
UUID : 118db989:9ac48e2f:30313d35:4a0268e7
Events : 22
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
4 8 48 2 active sync /dev/sdd
3 8 64 – spare /dev/sde
第二步:模拟/dev/sdd磁盘损坏
[root@ken ~]# mdadm /dev/md5 -f /dev/sdd
mdadm: set /dev/sdd faulty in /dev/md5
第三步:查看阵列状态
[root@ken ~]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Wed May 15 19:08:06 2019
Raid Level : raid5
Array Size : 41908224 (39.97 GiB 42.91 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Wed May 15 19:13:23 2019
State : clean, degraded, recovering
Active Devices : 2
Working Devices : 3
Failed Devices : 1
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Rebuild Status : 9% complete
Name : ken:5 (local to host ken)
UUID : 118db989:9ac48e2f:30313d35:4a0268e7
Events : 25
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
3 8 64 2 spare rebuilding /dev/sde
4 8 48 – faulty /dev/sdd
Centos7系统启动流程
1.uefi或BIOS初始化,开始post(power on self test)开机自检
2.加载MBR到内存
3.GRUB阶段
(grub第1.5和第2阶段,信息默认存放在扇区中,如果使用grub-install生成的第2阶段的文件是存放在/boot分区中的。)
(第1.5阶段:mbr之后的扇区,识别stage2所在的分区上的文件系统。)
4.加载内核和initramfs模块
5.内核开始初始化,使用systemd来代替centos6以前的init程序
6.Systemd执行multi-user.target下的getty.target及登录服务
7.systemd执行graphical需要的服务
版权声明:本文为zp-1996原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。