Detailed tutorial on creating a Linux environment soft RAID 5

Source: Internet
Author: User
Tags disk usage

1: Raid Definition
Raid, full name: Redundant Array of Inexpensive Disks. The Chinese name is a Redundant Array of cheap disks. raid can be divided into soft RAID and hard raid. Soft Raid achieves redundancy of multiple hard disks through software. however, hard raid uses raid cards to implement raid. the former has simple configuration and flexible management. it is the best choice for small and medium-sized enterprises. hard raid is often expensive. however, it has some advantages in performance.
2: Raid Classification
Raid can be divided into the following types:
RAID 0 provides the fastest access speed and no fault tolerance
Raid 1 has high fault tolerance costs and low hard disk usage.
RAID 3 has better write performance than multi-task functions.
Raid 4 has multi-task and fault tolerance functions. Parity disk drives cause performance bottlenecks.
RAID 5 has multi-task and fault tolerance functions. overhead is available when writing data.
RAID 0 + 1 fast, full fault tolerance, high cost

 

3: Linux RAID 5 experiment details
Suppose I have four hard disks (a friend without any conditions can use a virtual machine to set up four hard disks ). they are/dev/SDA/dev/sdb/dev/SDC/dev/SDD. the first step is partitioning.
[Root @ localhost/] # fdisk/dev/SDA
Device contains neither a valid DOS partition table, Nor Sun, SGI or OSF disklabel
Building a new dos disklabel. changes will remain in memory only,
Until you decide to write them. After that, of course, the previous
Content won't be recoverable.
Warning: Invalid flag 0x0000 of Partition Table 4 will be corrected by W (RITE)
Command (M for help): N # create a new partition by N
Command action
E extended
P primary partition (1-4) # input P to create the primary Partition
P
Partition Number (1-4): 1 # input 1 to create the first primary Partition
First cylinder (1-130, default 1): # Press enter. Select the start partition and start from 1.
Using default value 1
Last cylinder or + size or + sizem or + sizek (1-102, default 130 ):
Using default value 130
Command (M for help): W # Then enter W to write the disk
The partition table has been altered!
Calling IOCTL () to re-read partition table.
Syncing disks.
Other partitions are divided into one partition as follows:
[Root @ localhost/] # fdisk-l
Disk/dev/SDA: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 Cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device boot start end blocks ID system
/Dev/sda1 1 130 1044193 + 83 Linux
Disk/dev/SDB: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 Cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device boot start end blocks ID system
/Dev/sdb1 1 130 1044193 + 83 Linux
Disk/dev/SDC: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 Cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device boot start end blocks ID system
/Dev/sdc1 1 130 1044193 + 83 Linux
Disk/dev/SDD: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 Cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device boot start end blocks ID system
/Dev/sdd1 1 130 1044193 + 83 Linux

The next step is to create a raid.
[Root @ localhost ~] # Mdadm-create/dev/md0-level = 5-raid-devices = 3-Spare-devices = 1/dev/SD [a-d] 1 # create a RAID device the name is md0, level: RAID 5
Mdadm: array/dev/md0 started. Use three devices to create a raid and spare one for backup.
OK. We have initially established raid. Let's take a look at the specific situation.
[Root @ localhost ~] # Mdadm-Detail/dev/md0
/Dev/md0:
Version: 00.90.01
Creation Time: Fri Aug 3 13:53:34 2007
Raid level: RAID5
Array size: 2088192 (2039.25 MIB 2138.31 MB)
Device size: 1044096 (1019.63 MIB 1069.15 MB)
Raid devices: 3
Total devices: 4
Preferred minor: 0
Persistence: superblock is persistent
Update Time: Fri Aug 3 13:54:02 2007
State: clean
Active devices: 3
Working devices: 4
Failed devices: 0
Spare devices: 1
Layout: left-lateral ric
Chunk Size: 64 K
Number major minor raiddevice state
0 8 1 0 Active Sync/dev/sda1
1 8 17 1 Active Sync/dev/sdb1
2 8 33 2 Active Sync/dev/sdc1
3 8 49-1 spare/dev/sdd1
UUID: e62a8ca6: 2033f8a1: f333e527: 78b0278a
Events: 0.2
Enable raid boot. configure the RIAD configuration file. the default name is mdadm. conf. This file does not exist by default. You need to create it yourself. this configuration file is mainly used to automatically load soft RAID at system startup and facilitate future management.
Description: mdadm. the conf file consists of the following parts: the devices option is used to specify all RAID devices. The array option specifies the device name of the array, the raid level, the number of active devices in the array, and the uuid of the device.
[Root @ localhost ~] # Mdadm-detail-scan>/etc/mdadm. conf
[Root @ localhost ~] # Cat/etc/mdadm. conf
Array/dev/md0 level = RAID5 num-devices = 3 UUID = e62a8ca6: 2033f8a1: f333e527: 78b0278a
Devices =/dev/sda1,/dev/sdb1,/dev/sdc1,/dev/sdd1
# The default format is incorrect. You need to modify the format as follows:
[Root @ localhost ~] # Vi/etc/mdadm. conf
[Root @ localhost ~] # Cat/etc/mdadm. conf
Devices/dev/sda1,/dev/sdb1,/dev/sdc1,/dev/sdd1
Array/dev/md0 level = RAID5 num-devices = 3 UUID = e62a8ca6: 2033f8a1: f333e527: 78b0278a

Create a file system in/dev/md0,
[Root @ localhost ~] # Mkfs. ext3/dev/md0
Mke2fs 1.35 (28-feb-2004)
Filesystem label =
OS type: Linux
Block size = 4096 (log = 2)
Fragment size = 4096 (log = 2)
261120 inodes, 522048 Blocks
26102 blocks (5.00%) reserved for the Super User
First data block = 0
Maximum filesystem blocks = 536870912
16 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks:
32768,983 04, 163840,229 376, 294912
Writing inode tables: Done
Creating Journal (8192 blocks): Done
Writing superblocks and filesystem accounting information: Done
This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first. Use tune2fs-C or-I to override. Content
Mount/dev/md0 to the system. Is the experiment available:
[Root @ localhost ~] # Cd/
[Root @ localhost/] # mkdir mdadm
[Root @ localhost/] # Mount/dev/md0/mdadm/
[Root @ localhost/] # cd/mdadm/
[Root @ localhost mdadm] # ls
Lost + found
[Root @ localhost mdadm] # cp/etc/services.
[Root @ localhost mdadm] # ls
Lost + found services
Okay. What if one of the hard disks breaks down? The system will automatically stop the work of this hard disk, and then let the backup hard disk work on top. We can experiment with it.
[Root @ localhost mdadm] # mdadm/dev/md0-fail/dev/sdc1
Mdadm: Set/dev/sdc1 faulty in/dev/md0
[Root @ localhost mdadm] # Cat/proc/mdstat
Personalities: [RAID5]
Md0: Active RAID5 sdc1 [3] (f) sdd1 [2] sdb1 [1] sda1 [0] # F label to this disk as fail.
2088192 blocks level 5, 64 K chunk, algorithm 2 [3/3] [uuu]
Unused devices:
What if I want to remove a bad hard disk or add a hard disk?
# Deleting a hard disk
[Root @ localhost mdadm] # mdadm/dev/md0-Remove/dev/sdc1
Mdadm: Hot removed/dev/sdc1
[Root @ localhost mdadm] # Cat/proc/mdstat
Personalities: [RAID5]
Md0: Active RAID5 sdd1 [2] sdb1 [1] sda1 [0]
2088192 blocks level 5, 64 K chunk, algorithm 2 [3/3] [uuu]
Unused devices:
# Add a hard disk
[Root @ localhost mdadm] # mdadm/dev/md0-Add/dev/sdc1
Mdadm: Hot added/dev/sdc1
[Root @ localhost mdadm] # Cat/proc/mdstat
Personalities: [RAID5]
Md0: Active RAID5 sdc1 [3] sdd1 [2] sdb1 [1] sda1 [0]
2088192 blocks level 5, 64 K chunk, algorithm 2 [3/3] [uuu]
Unused devices:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.