Raid implementation:
Raid: cheap redundant disk array, which turns several hard disks into a whole
Later, because it lost its original cheap purpose and became very expensive, it changed its name
Independent redundant disk array
Although we cannot implement raid on hardware, we can still implement raid because of our limited strength and we didn't buy those devices.
Next we will look at how to implement soft RAID:
1. Implementation of soft RAID 0:
First, we will introduce the principle of RAID 0. RAID 0 divides a data stream into two copies and stores them on two disks to achieve doubled performance.
Not only that, but it also provides a large throughput. Next we will implement soft RAID 0.
First, you must create two partitions (RAID 0 can be created if there are more than two partitions). When creating a raid with a size of 2 GB, you must
The two shards are 1 GB in size. After the shards are created, repeat the partition table in the kernel,
partprobe /dev/sda[root@server56 raid10]# fdisk /dev/sdaCommand (m for help): nFirst cylinder (7011-15665, default 7011): Using default value 7011Last cylinder or +size or +sizeM or +sizeK (7011-15665, default 15665): +1GCommand (m for help): tPartition number (1-6): 5Hex code (type L to list codes): fdChanged system type of partition 5 to fd (Linux raid autodetect)Command (m for help): tPartition number (1-6): 6Hex code (type L to list codes): fdChanged system type of partition 6 to fd (Linux raid autodetect) Device Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83 Linux/dev/sda2 14 5235 41945715 8e Linux LVM/dev/sda3 5236 5300 522112+ 82 Linux swap / Solaris/dev/sda4 5301 15665 83256862+ 5 Extended/dev/sda5 5301 5423 987966 fd Linux raid autodetect/dev/sda6 5424 5546 987966 fd Linux raid autodetect
In Linux, raid autodetect is used to establish soft RAID. The system type is required. Remember to divide the two raid files when partitioning.
The partition is specified to this type. The following lists all the numbers of the system type and system type that can be specified for the partition.
You only need to enter the preceding number.
0 Empty 1e Hidden W95 FAT1 80 Old Minix bf Solaris 1 FAT12 24 NEC DOS 81 Minix / old Lin c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 82 Linux swap / So c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 83 Linux c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c7 Syrinx 5 Extended 41 PPC PReP Boot 85 Linux extended da Non-FS data 6 FAT16 42 SFS 86 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set de Dell Utility 8 AIX 4e QNX4.x 2nd part 88 Linux plaintext df BootIt 9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi ee EFI GPT f W95 Ext'd (LBA) 54 OnTrackDM6 a5 FreeBSD ef EFI (FAT-12/16/10 OPUS 55 EZ-Drive a6 OpenBSD f0 Linux/PA-RISC b11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f1 SpeedStor 12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f4 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f2 DOS secondary 16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot 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 auto1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
After the partition is created, enter W to save and exit. If Q is used to exit, all the partitions above will be unavailable.
After the partition is created, remember to format it and create the file system ext2 or ext3 for it. No matter what type of file system you specify
The file system type of the partition must be the same to ensure consistency and synchronization.
mkfs.ext2 /dev/sda5mkfs.ext2 /dev/sda6
After formatting is complete, you can proceed to the next step and create a soft RAID 0
mdadm -C /dev/md0 -a yes -l 0 -n 2 /dev/sda5 /dev/sda6
[This command is used to create/dev/md0. If not, create/dev/md0 directly. The raid level is 0 and
/Dev/SD6 components]
After the partition is created, the entire partition is formatted because the two partitions belong to one hard disk logically,
mke2fs /dev/md0
Now you can take a look at/proc/mdstat
md0 : active raid0 sda6[1] sda5[0] 1975680 blocks 64k chunks
The Chunks here is the minimum data unit for disk read/write. The unit is K. The default value is 64 K.
The default data block size is 4096 kb. Therefore, each time the kernel calculates the number of chunks read
However
mk2tfs -b 2048 -E stride=32 /dev/md0
You can directly tell the kernel the number of chunks to be read, which can greatly
Saves CPU space.-B is the size of a data block.
Next, you need to specify a mount point for RAID 0.
mkdir /mnt/raid0mount /dev/nd0 /mnt/raid0
You can mount and use it,
Use fdisk-L to view
Mdadm-D/dev/md0 to View Details
In this case, you should save the configuration information of RAID 0 in case of a fault. You can recover it next time,
mdadm -D --scan /dev/md0 >> /etc/mdadm.conf
You can use it directly next time.
Mdadm-A -- Scan direct mounting
How to detach RAID 0 should first detach the mount point of RAID 0, that is
umount /mnt/raid0
Then use the command
mdadm -S /dev/md0
Stop it
In this case, you can use fdisk-L to unmount it.
Directly
mdadm -A --scan
The kernel will automatically read/etc/mdadm. conf to mount all the soft RAID
In case of an accident, if a disk with RAID 0 breaks down, all the data will be lost, so RAID 1 appears.
First, we will introduce the principle of RAID 1. Raid 1 stores data streams on two disks at the same time, just like a mirror.
Data, even if one of them is unfortunately down, there is still complete data, but the two disks have the same data
The space of one disk is wasted, but it still provides powerful read capability, although the write speed will be the same as the original
Living is not as good as before, but there is still a strong Throughput
To create a RAID 1 with a size of 2 GB, it takes so long for two disks with the same size as 2 GB, that is, two partitions with the same size as 2 GB.
Implement soft RAID 1
First, two partitions with a size of 2 GB are required. The system type is still
Linux raid autodetect
Repeat the partition
partprobe /dev/sda
Partition and format
mkfs.ext3 /dev/sda7 mkfs.ext3 /dev/sda8
Then you can create soft RAID 1.
mdadm -C /dev/md1 -a yes -l 1 -n 2 /dev/sda7 /dev/sda8
Then, format the entire file.
Mkfs. ext3 note that the format must be consistent
Create a mount point
mkdir /mnt/raid1
Mount raid1
mount /dev/md1 /mnt/raid1
Now you can use
You can check the LS-L in CD, MNT, and raid1.
drwx------ 2 root root 16384 07-30 17:00 lost+found
You can also see fdisk-l
Remember to save the relevant information.
mdadm -D --scan /dev/md1 >> /etc/mdadm.conf
The steps for detaching a RAID 0 are the same as those for detaching a RAID 0,
You only need
Mdadm-A -- scan to mount all RAID Devices
Even if an unexpected raid occurs, it can work normally, but it is working in a lame State. At this time, it is easy to cause another disk.
If the disk is damaged, you need to add a backup disk. The same is true for Soft Raid. A backup partition is required for reserve.
Then, the system type is still FD, which is the same as the first two shards.
After the partition is complete, re-read the partition table and format it into the same file system as RAID 1. Then
We will simulate a partition failure and use the command
Mdadm -- fail/dev/md1/dev/sda7. The sda7 in md1 is crashed.
Now we need to use the partition just now,
Install a good disk and then a bad disk to avoid secondary harm.
Mdadm -- add/dev/md1/dev/sda9 [after installation, it will automatically synchronize with another disk]
Remove a bad Disk:
mdadm --remove /dev/md1 /dev/sda7
Because RAID 0 and RAID 1 both have shortcomings and all have certain risks, the combination of the two methods will reduce the number
Risks, and provides excellent read/write performance. with powerful throughput, RAID 0 is used as the middle layer to improve read/write performance.
Capability. Raid 1 is used as the underlying layer to provide Fault Tolerance capabilities, which reduces the risk of data loss.
To implement soft RAID 10, ensure that RAID 0 and RAID 1 are not mounted and are in the unmounted status.
mdadm -C /dev/md10 -a yes -l 10 -n 2 /dev/md0 /dev/md1
In this way, soft RAID 10 can be implemented.
No formatting is required.
You can mount it directly.
Create a mount point first
mkdir /mnt/raid10
Mount
mount/dev/md10 /mnt/raid10
That is, soft RAID 10 is implemented.
In this case, save the configuration information
mdadm -D /dev/md10 >> /etc/mdadm.conf
The uninstall method is the same as the first two methods.
Reload is the same as before
Mdadm-A -- scan can
In this way, the above three types of soft RAID are implemented.
Raid is a topic for interviews, so you need to be familiar with it !!!
Next, let's try RAID 5.
The method is similar.