磁盘阵列-RAID1

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/sdcWelcome 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 tableBuilding a new DOS disklabel with disk identifier 0x23f3010b.Command (m for help): pDisk /dev/sdc: 1073 MB, 1073741824 bytes, 2097152 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x23f3010bDevice Boot Start End Blocks Id SystemCommand (m for help): nPartition type:p primary (0 primary, 0 extended, 4 free)e extendedSelect (default p): pPartition number (1-4, default 1):First sector (2048-2097151, default 2048):Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151):Using default value 2097151Partition 1 of type Linux and of size 1023 MiB is setCommand (m for help): tSelected partition 1Hex code (type L to list all codes): fdChanged type of partition 'Linux' to 'Linux raid autodetect'Command (m for help): pDisk /dev/sdc: 1073 MB, 1073741824 bytes, 2097152 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x9d695fd1Device Boot Start End Blocks Id System/dev/sdc1 2048 2097151 1047552 fd Linux raid autodetectCommand (m for help): w
2. mdadm创建RAID1
选项:-C 专用选项:-l 级别 -n 设备个数 -a {yes|no} 自动为其创建设备文件 -c 指定数据块大小(chunk) -x 指定空闲盘(热备磁盘)个数,空闲盘(热备磁盘)能在工作盘损坏后自动顶替 注意:创建阵列时,阵列所需磁盘数为-n参数和-x参数的个数和[root@localhost dev]# cat /partitioncat: /partition: No such file or directory[root@localhost dev]# cat partitioncat: 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 1969mdadm: partition table exists on /dev/sdb but will be lost ormeaningless after creating arraymdadm: Note: this array has metadata at the start andmay not be suitable as a boot device. If you plan tostore '/boot' on this device please ensure thatyour boot-loader understands md/v1.x metadata, or use--metadata=0.90mdadm: /dev/sdc appears to be part of a raid array:level=raid0 devices=0 ctime=Wed Dec 31 16:00:00 1969mdadm: partition table exists on /dev/sdc but will be lost ormeaningless after creating arrayContinue creating array? ymdadm: Defaulting to version 1.2 metadatamdadm: array /dev/md1 started.格式化为xfs[root@localhost mnt]# mkfs.xfs /dev/md1meta-data=/dev/md1 isize=512 agcount=4, agsize=65472 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0, sparse=0data = bsize=4096 blocks=261888, imaxpct=25= sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal log bsize=4096 blocks=855, version=2= sectsz=512 sunit=0 blks, lazy-count=1realtime =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.2Creation Time : Thu Jan 20 23:55:34 2022Raid Level : raid1Array Size : 1047552 (1023.00 MiB 1072.69 MB)Dev Size : 1047552 (1023.00 MiB 1072.69 MB)Raid Devices : 2Total Devices : 2: Superblock is persistentUpdate Time : Fri Jan 21 19:43:39 2022: cleanActive Devices : 2Working Devices : 2Failed Devices : 0Devices : 0Name : localhost.localdomain:1 (local to host localhost.localdomain)UUID : 1ead9519:d85d9376:4dec83a6:754470a6: 17Number Major Minor RaidDevice State0 8 16 0 active sync /dev/sdb1 8 32 1 active sync /dev/sdc
评论
