Day21 课堂笔记
1. Raid介绍
1.1 Raid的概念
Raid是廉价冗余磁盘阵列(Redundant Array of Inexpensive Disk)的简称, 有时也简称磁盘阵列(Disk Array)。
Raid是一种把多块独立的物理磁盘按不同的技术方式组合起来形成一个磁盘组,在逻辑上(做完Raid,装完系统后)看起来就是一块大的磁盘,可以提供比单个物理磁盘更大的存储容量或更高的存储性能,同时又能提供不同级别数据冗余备份的一种技术。
1.2 Raid的级别(主要级别)
Raid级别 | 关键优点 | 关键缺点 | 实际应用场景 |
---|---|---|---|
Raid 0 | 读写速度最快 | 没有任何冗余 | MySQL Slave,集群的节点RS |
Raid 1 | 100%冗余,镜像 | 读写性能一般,成本高 | 单独的,数据重要且不能宕机的业务 |
Raid 5 | 具备一定性能和冗余,可以坏一块盘,读性能不错 | 写入性能不高 | 一般的业务都可以用 |
Raid 10/01 | 读写速度很快 | 成本高 | 性能和冗余要求都很好的业务,数据库主库和存储的主节点 |
1.3 Raid技术分类
-
软RAID,系统层面实现的,性能差。
-
硬RAID,硬件层面实现的,性能好。
主板板载RAID:功能弱,RAID 0,RAID 1
独立RAID卡:功能强,RAID 0,RAID 1,RAID 5,RAID 10 (工作选择)。
用Raid的最直接的好处是:
-
1)提升数据安全性
-
2)提升数据读写性能
-
3)提供更大的单一逻辑磁盘数据容量存储
1.4 常用Raid级别细节说明
1.) Raid 0
图:3块盘形成Raid 0 的结构图
Raid 0的结构图应用场景:
-
负载均衡集群下面的多个相同RS节点服务器
-
分布式文件存储下面的主节点或CHUNK SERVER
-
MySQL主从复制的多个Slave服务器
-
对性能要求很高,对冗余要求很低的相关业务
2. )Raid 1
图:2块盘形成Raid 1 的结构图
Raid 1的结构图
应用场景:
- 存放重要数据,例如:
服务器系统分区和对性能要求很高的数据库存储
3.) Raid 5
图:3块盘形成Raid 5 的结构图
Raid 5的结构图
采用奇偶校验的方式存储数据
应用场景:
-
文件与应用服务器
-
数据库服务器
-
Web、E-mail以及新闻服务器
4.) Raid 10
图:4块盘形成Raid 10 的结构图
Raid 10的结构图
1.5 Dell R710使用6块盘实践Raid制作结论
Raid 0: 支持1块盘到多块盘,容量是所有盘之和
Raid 1:只支持2块盘,容量损失1块盘
Raid 5:最少三快盘,不管硬盘数量多少,只损失一块盘
Raid 6:最少4块盘,5块盘也可以,损失2块盘,不管硬盘多少,只损失两块盘容量
Raid 10:最少4块盘,必须偶数硬盘,不管硬盘多少,都损失一半容量,不支持虚拟磁盘
2. 磁盘分区
2.1 什么是磁盘分区?
磁盘分区就是相当于给磁盘打隔断
2.2 磁盘和分区在Linux里的命名。
-
IDE 第一块hda、第二块hdb
-
SCSI 第一块sda、第二块sdb
2.3 磁盘分区类型和特点。
-
主分区(primary)P
1)系统中必须要存在的分区,系统盘选择主分区安装。
2)数字编号只能是1-4.sda1、sda2、sda3、sda4。
3)主分区最多四个,最少一个。 -
扩展分区(extend)E
1)相当于一个独立的小磁盘。
2)有独立的分区表。
3)不能独立存在,即不能直接存放数据。
4)必须在扩展分区上建立逻辑分区才能存放数据。
5)占用主分区的编号(主分区+扩展分区)之和最多4个。
6)扩展分区可以没有,最多只能有一个。 -
逻辑分区(logic)L
2)数字编号只能是从5开始。
3)存放于扩展分区之上。
4)存放任意普通数据。 -
磁盘分区注意事项要点
一块硬盘的分区方式只能为如下组合之一:
(1)任意多个主分区,但要求1≤主分区数量≤4。
例如:一个硬盘可以分为4个主分区3个主分区2个主分区或1个主分区。
(2)扩展分区可以和主分区组合,但要求2≤(主分区+扩展分区)数量≤4)。
例如:3个主分区+1个扩展分区或2个主分区+1个扩展分区或1个主分区+1个扩展分区。
当总分区的数量大于4个的时候,必须提前分一个扩展分区,扩展分区最多只能有一个。
(3)如果要分成四个磁盘分区的话,那么最多就是可以:
P + P + P + P
P + P + P + E
2.4 磁盘分区工作原理。
-
磁盘是按柱面分区的。
-
磁盘分区登记的地点,磁盘分区表。
-
磁盘分区表存放分区结果信息的。
-
磁盘分区表位置,0磁道0磁头1扇区(512字节)
-
占用1扇区的前446字节(系统引导信息的)后面的64字节(分区表),
-
剩下2个字节分区结束标志。
-
磁盘分区表的容量是有限的,64字节,一个分区固定占16字节。
-
64/16=4分区(主分区+扩展分区)
2.5 磁盘分区实战
-
磁盘分区关键就是修改64字节的的分区表而已。
-
磁盘分区常用命令fdisk,修改MBR分区表,MBR格式。
-
缺陷,被修改的磁盘大小不能大于2T。
-
磁盘分区其他命令parted,gpt分区格式,既能修改小于2T也能修改大于2T的磁盘。
小于2T就用fdisk
大于2T就用parted
实践案例:
1)fdisk 命令
a、列出系统磁盘信息: fdisk -l
[root@oldboyedu ~]# fdisk -l
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000cd234
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 526335 262144 83 Linux
/dev/sda2 526336 2099199 786432 82 Linux swap / Solaris
/dev/sda3 2099200 41943039 19921920 83 Linux
b、fdisk查看帮助
[root@oldboyedu ~]# fdisk /dev/sdb #<==开始给sdb磁盘分区
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xbc9b0906.
Command (m for help): m <-->查看分区的帮助信息。
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition <-->删除一个分区。
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu <-->查看分区的帮助信息。
n add a new partition <-->添加一个新分区。
o create a new empty DOS partition table
p print the partition table <-->查看分区结果信息。
q quit without saving changes <-->退出不保存。
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit #<==保存并退出。
x extra functionality (experts only)
Command (m for help):
c、开始分区实践:
[root@oldboyedu ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xbc9b0906.
=================================================================
******开始分第1块主分区******
=================================================================
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-2097151, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +150M
Partition 1 of type Linux and of size 150 MiB is set
=================================================================
********查看的结果********
=================================================================
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbc9b0906
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
=================================================================
******开始分第2块主分区******
=================================================================
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (309248-2097151, default 309248):
Using default value 309248
Last sector, +sectors or +size{K,M,G} (309248-2097151, default 2097151): +150m
Unsupported suffix: 'm'. <-->严格区分大小写
Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte)
2^N: K (KibiByte), M (MebiByte), G (GibiByte)
Last sector, +sectors or +size{K,M,G} (309248-2097151, default 2097151): +150M
Partition 2 of type Linux and of size 150 MiB is set
=================================================================
********查看的结果********
=================================================================
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbc9b0906
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
=================================================================
******开始分第3块主分区******
=================================================================
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3):
First sector (616448-2097151, default 616448):
Using default value 616448
Last sector, +sectors or +size{K,M,G} (616448-2097151, default 2097151): +150M
Partition 3 of type Linux and of size 150 MiB is set
=================================================================
********查看的结果********
=================================================================
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbc9b0906
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
=================================================================
******开始分第4块主分区******
=================================================================
Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): p
Selected partition 4
First sector (923648-2097151, default 923648):
Using default value 923648
Last sector, +sectors or +size{K,M,G} (923648-2097151, default 2097151): +150M
Partition 4 of type Linux and of size 150 MiB is set
=================================================================
********查看的结果********
=================================================================
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbc9b0906
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
/dev/sdb4 923648 1230847 153600 83 Linux
=================================================================
******无法分第5块主分区******
=================================================================
Command (m for help): n
If you want to create more than four partitions, you must replace a
primary partition with an extended partition first.
=================================================================
******将第4块主分区删除******
=================================================================
Command (m for help): d
Partition number (1-4, default 4): 4
Partition 4 is deleted
=================================================================
********查看的结果********
=================================================================
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbc9b0906
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
=================================================================
******开始分第4块扩展分区******
=================================================================
Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): e
Selected partition 4
First sector (923648-2097151, default 923648):
Using default value 923648
Last sector, +sectors or +size{K,M,G} (923648-2097151, default 2097151):
Using default value 2097151
Partition 4 of type Extended and of size 573 MiB is set
=================================================================
********查看的结果********
=================================================================
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbc9b0906
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
/dev/sdb4 923648 2097151 586752 5 Extended
=================================================================
******开始分第1块逻辑分区******
=================================================================
Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (925696-2097151, default 925696):
Using default value 925696
Last sector, +sectors or +size{K,M,G} (925696-2097151, default 2097151): +150M
Partition 5 of type Linux and of size 150 MiB is set
=================================================================
********查看的结果********
=================================================================
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbc9b0906
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
/dev/sdb4 923648 2097151 586752 5 Extended
/dev/sdb5 925696 1232895 153600 83 Linux
=================================================================
******开始分第2块逻辑分区******
=================================================================
Command (m for help): n
All primary partitions are in use
Adding logical partition 7
First sector (1544192-2097151, default 1544192):
Using default value 1544192
Last sector, +sectors or +size{K,M,G} (1544192-2097151, default 2097151): +150M
Partition 7 of type Linux and of size 150 MiB is set
=================================================================
********查看的结果********
=================================================================
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbc9b0906
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
/dev/sdb4 923648 2097151 586752 5 Extended
/dev/sdb5 925696 1232895 153600 83 Linux
/dev/sdb6 1234944 1542143 153600 83 Linux
/dev/sdb7 1544192 1851391 153600 83 Linux
=================================================================
********保存并退出********
=================================================================
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
此外,还可指定文件系统:
[root@oldboyedu ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
=================================================================
********查看文件系统类型********
=================================================================
Command (m for help): l
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
=================================================================
********指定分区文件系统类型********
=================================================================
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbc9b0906
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
/dev/sdb4 923648 2097151 586752 5 Extended
/dev/sdb5 925696 1232895 153600 83 Linux
/dev/sdb6 1234944 1542143 153600 83 Linux
/dev/sdb7 1544192 1851391 153600 83 Linux
Command (m for help): t
Partition number (1-7, default 7): 7
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
=================================================================
********查看的结果********
=================================================================
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbc9b0906
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
/dev/sdb4 923648 2097151 586752 5 Extended
/dev/sdb5 925696 1232895 153600 83 Linux
/dev/sdb6 1234944 1542143 153600 83 Linux
/dev/sdb7 1544192 1851391 153600 8e Linux LVM
Command (m for help):
2)parted 命令(见《作业-第05周--课堂-Day22-磁盘管理 -Ⅲ》)
网友评论