磁盘阵列-RAID1
joke7164
共 5282字,需浏览 11分钟
·
2022-01-27 08:40
RAID1是将一个两块硬盘所构成RAID磁盘阵列,其容量仅等于一块硬盘的容量,因为另一块只是当作数据“镜像”。RAID1通过磁盘数据镜像实现数据冗余,在成对的独立磁盘上产生互为备份的数据。当原始数据繁忙时,可直接从镜像拷贝中读取数据,因此RAID1可以提高读取性能,下面是操作方法安排。
1.建立RAID1至少需要两块磁盘。
1.添加磁盘
[root@localhost dev]# blkid
/dev/sda1: UUID="594f1893-d32b-48d6-88d9-83032584eeb3" TYPE="xfs"
/dev/sda2: UUID="a9ccc925-f46d-453a-a11d-72b52cc75355" TYPE="swap" PTTYPE="dos"
/dev/sda3: UUID="eddbe0b6-358c-4ac4-8681-008948ed9c73" TYPE="xfs"
2.创建相同格式磁盘分区
[root@localhost dev]# fdisk /dev/sdc
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 0x23f3010b.
Command (m for help): p
Disk /dev/sdc: 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: 0x23f3010b
Device Boot Start End Blocks Id System
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):
Using default value 2097151
Partition 1 of type Linux and of size 1023 MiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): p
Disk /dev/sdc: 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: 0x9d695fd1
Device Boot Start End Blocks Id System
/dev/sdc1 2048 2097151 1047552 fd Linux raid autodetect
Command (m for help): w
2. mdadm创建RAID1
选项:-C 专用选项:-l 级别 -n 设备个数 -a {yes|no} 自动为其创建设备文件 -c 指定数据块大小(chunk) -x 指定空闲盘(热备磁盘)个数,空闲盘(热备磁盘)能在工作盘损坏后自动顶替 注意:创建阵列时,阵列所需磁盘数为-n参数和-x参数的个数和
[root@localhost dev]# cat /partition
cat: /partition: No such file or directory
[root@localhost dev]# cat partition
cat: partition: No such file or directory
[root@localhost dev]# mdadm -C /dev/md1 -a yes -l 1 -n 2 /dev/sd{b,c}
mdadm: /dev/sdb appears to be part of a raid array:
level=raid0 devices=0 ctime=Wed Dec 31 16:00:00 1969
mdadm: partition table exists on /dev/sdb but will be lost or
meaningless after creating array
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
mdadm: /dev/sdc appears to be part of a raid array:
level=raid0 devices=0 ctime=Wed Dec 31 16:00:00 1969
mdadm: partition table exists on /dev/sdc but will be lost or
meaningless after creating array
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
格式化为xfs
[root@localhost mnt]# mkfs.xfs /dev/md1
meta-data=/dev/md1 isize=512 agcount=4, agsize=65472 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=261888, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
文件系统管理:
重新创建文件系统会损坏原有的文件
创建文件系统
mkfs:
-t 文件系统 创建的磁盘
mkfs.xfs -f /dev/磁盘
首先先查看系统的适合格式
cat /proc/filesystems
[root@localhost mnt]# mount -o rw /dev/md1 /mnt/md1
挂载:
挂载:将新的系统关联到新的系统----如果挂载点原有文件将会被隐藏(解除挂载后显示)
mount
用法:mount 设备 挂载点
-a:表示挂载/etc/fstab 所有文件系统
-n :默认情况下,mount命令挂载时会写入设备信息,使用这个选项将不会被写入/etc/mtab
-t fstable:指定挂载文件系统类型,默认会调用blkid获取文件系统类型
-r:只读挂载
-w:读写挂载
-o:指定额外的挂载权限
-noexec :挂载时禁止里面的二进制文件自动运行。
-nosuid :不允许获得管理权限
卸载:解除关联
umount
用法:mount 挂载点或者设备
注意事项:挂载点没有被进程使用
当无法卸载的时候
fuser --验证或者查看该文件正在被使用
-v:查看文件上正在运行的进程
-mk:杀死正在使用的所有进程
查看是否挂载
[root@localhost mnt]# mount |grep md1
/dev/md1 on /mnt/md1 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
3.查看创建的RAID1
md1]# mdadm -D /dev/md1
:
1.2 :
Creation Time : Thu Jan 20 23:55:34 2022
Raid Level : raid1
Array Size : 1047552 (1023.00 MiB 1072.69 MB)
Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
Raid Devices : 2
Total Devices : 2
Superblock is persistent :
Update Time : Fri Jan 21 19:43:39 2022
clean :
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Devices : 0
Name : localhost.localdomain:1 (local to host localhost.localdomain)
UUID : 1ead9519:d85d9376:4dec83a6:754470a6
17 :
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
评论