Raid是廉价冗余磁盘阵列(Redundant Array of Inexpensive Disk)的简称, 有时也简称磁盘阵列(Disk Array)。
raid 作用:
把一块或多块独立的物理磁盘按照不同的方式组合起来形成一个磁盘,
级别:0 1 5 10
RAID分类:
软raid 软raid 系统层面是吸纳的,性能差
硬raid 硬件层面实现的,性能好
主板载raid :功能弱,0,1
独立raid卡:功能强,0,1,5,10 工作中选择
LVM全称(Logic Volume Management (Manager))逻辑卷管理,它的最大用途是可以【灵活的管理磁盘的容量】,让磁盘分区可以随意放大或缩小,便于更好的应用磁盘的剩余空间,如果过于强调性能与备份,那么还是应该使用RAID功能,而不是LVM。
LVM是软件层面实现的,性能太低。性能降低5-10%。
买服务器插满磁盘,分区规划好,永远都不需要LVM。
为什么需要Raid:
1,提升数据性能
2,提成数据读写性能
3,提升更大的单一逻辑磁盘数据容量存储
RAID1又称为Mirror或Mirroring(镜像),
它的宗旨是最大限度的保证用户数据的可用性和可修复性。
RAID1的操作方式是把用户写入一个磁盘的数据百分之百地自动复制到另外
一个磁盘上,从而实现存储双份的数据。
Raid 5 :是一种存储性能,数据安全和存储成本兼顾的存储解决方案
它需要三块或以上的物理磁盘,可以提供热备盘实现数据恢复
最好只选择三到四块磁盘来做。
它是RAID 0和RAID 1 的折中方案。写入数据的时候多了个奇偶校验信息
性能:和RIAID 0 相近似得数据读取速度,只是多了个奇偶校验信息
冗余:可损失一块盘
场合:Raid 5可以理解为是Raid 0和Raid 1的折中方案
特点:容量损失一块盘,写入数据通过奇偶校验,RAID 0和RAID 1的折中方案
磁盘的分区
什么是分区:
磁盘分区就相当于给磁盘打隔断
磁盘在linux里的命名:
IDE /dev/hda hdb
SCSI sda sdb
分区:sda1 sda2 sda3 分区是用数字表示
磁盘分区类型:分为三种
(1)主分区 (primary)p
它是系统中必须要存在的分区,系统盘选择主分区安装
是以数字编号的只能是1-4,sda1 sda2 sda3 sda4
主分区最多四个,最少一个
(2)扩展分区 (extend)E
相当于一个独立的小磁盘,独立的分区表,不能独立存在
有独立的分区表
不能独立存在,既不能直接存放数据
要想独立存在,必须在扩展分区上建立逻辑分区才能存放数据
它也会占用主分区的编号(主分区+扩展分区)之和要小于等于4
扩展分区可以不存在,但不能超过一个
(3)逻辑分区(logic)L
数字编号只能是从5开始
存放于扩展分区之上
存放任意普通数据
磁盘分区注意事项要点
一块硬盘的分区方式只能为如下组合之一:
(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
磁盘分区的工作原理:
1,磁盘分区按柱面分区。
2,磁盘分区登记地点叫做磁盘分区表。
磁盘分区表的作用是用来存放分区结果信息的,位置在,0磁道0磁头1扇区(512字节)
占用1扇区的前446字节(存放系统引导信息的)后面的64字节(分区表)
剩下的2字节存放分区结束标志
磁盘分区表的容量是有限的,64字节,一个分区固定占16字节
64/16=4分区(主分区+扩展分区)
磁盘分区实战
磁盘分区的核心本质就是修改这64字节的分区表而已
磁盘分区常用命令 fdisk ,修改MBR分区表,也叫MBR格式。
有一个缺陷,被修改的磁盘大小不能大于2T。
如果大于2T就用parted命令 gpt分区格式,即能修改小于2T也能修改大于2T的磁盘
建议使用:小于2T就用fdisk
大于2T就用parted
[root@zhangxiangyu-58 ~]# fdisk -l
磁盘 /dev/sda:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000bacdd
设备Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 4507647 2048000 82 Linux swap / Solaris
/dev/sda3 4507648 41943039 18717696 83 Linux
[root@zhangxiangyu-58 ~]# 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):
开始实践:
问题:如果给一个磁盘分6个分区有哪些方案,同时写出分区/dev/sda(数字)。
3P+1E(3L) 1 2 3 5 6 7
2P+1E(4L) 12 5678
1P+1E(5L) 1 56789
用下面方案:
3P+1E(3L) 1 2 3 5 6 7 每个150M
[root@zhangxiangyu-58 ~]# 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 0x827687e9.
Command (m for help): ^C
[root@zhangxiangyu-58 ~]# 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.
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): 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
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
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
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
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.
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
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
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
Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (1234944-2097151, default 1234944):
Using default value 1234944
Last sector, +sectors or +size{K,M,G} (1234944-2097151, default 2097151): +150M
Partition 6 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
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.