磁盘阵列

RAID类型最低磁盘个数空间利用率各自的优缺点

级 别说 明

RAID0 条带卷 2+ 100% 读写速度快,不容错

RAID1 镜像卷 2  50% 读写速度一般,容错

RAID5 带奇偶校验的条带卷 3+  (n-1)/n   读写速度快,容错,允许坏一块盘

RAID10   RAID1的安全+RAID0的高速   4   50%    读写速度快,容错



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)开机自检

检测:CPU, 内存,硬盘等硬件信息


2. 加载MBR到内存


3.GRUB阶段


4.加载内核和initramfs模块


5.内核开始初始化,使用systemd来代替centos6以前的init程序

0 ==> runlevel0.target, poweroff.target   –>关机

1 ==> runlevel1.target, rescue.target     –> 单人用户模式

2 ==> runlevel2.target, multi-user.target   –> 无网络的多用户模式

3 ==> runlevel3.target, multi-user.target    –> 多用户模式

4 ==> runlevel4.target, multi-user.target   –> 保留位

5 ==> runlevel5.target, graphical.target   –>图形界面

6 ==> runlevel6.target, reboot.target      –> 重启


centos6系统中使用 /etc/inittab 管理运行级别,但是在centos7中已经废弃了该文件


使用方式:

init 0    —》关机

init 3    —》多用户模式

init5    —》图形界面

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容