Linux raid1 environment setup and usage instructions
-
Why should I build the linuxraid1 environment?
Linux raid1 is the most common Hard Disk redundancy backup solution for Linux servers. It can ensure the security of hard disk data when the hard disk is damaged. Of course, the premise is that at least one hard disk is good. It is often used together with the reiserfs software to fully ensure the stability of the Linux Server (raid1 physically performs real-time hot backup of hard disk data, and reiserfs logically backs up the file system ).
-
How to build a Linux raid1 Environment
-
Prepare at least two hard disks for RAID 1, preferably two hard disks of the same type and capacity.
-
Use fdisk to partition the hard disk (use SDA as an example)
# Fdisk/dev/SDA
# M (you can enter the M command to obtain help information)
# N (Add a new partition, select the primary partition type, and then select the start and end positions of the partition. if you want
If the disk is divided into one partition, select default for all partitions)
# T (to change the partition type, enter the letter L to obtain the list of types. Here we select FD, that is, linuxraid
Auto type)
# W (save and Exit)
-
Download and install the disk array management tool mdadm
# Yum install mdadm
-
Use mdadm to create and manage Disk Arrays
# Mdadm -- create -- Auto = Yes/dev/md0 -- level = 1 -- raid-devices = 2 -- spare-devices = 1
/Dev/sda1/dev/sdb1/dev/sdc1
The number of disks is 1. If any of the disk arrays is damaged, the backup disk automatically
You can also use a backup disk instead of a backup disk,
Let's change and synchronize the data manually)
# Mkfs-T ext3/dev/md0 (create a file system and use a disk array like a hard disk)
# Mount/dev/md0/mnt (Mount disk array)
-
You can use the following command to view the disk array status
# Cat/proc/mdstat (or the following command can also be used)
# Mdadm -- detail/dev/md0
-
Set the disk array to auto-mount upon startup
# Mdadm-d-s>/etc/mdadm. conf (Save the disk array information to the configuration file first, otherwise the system starts
/Dev/md127)
# Vi/etc/fstab (edit the fstab file and add the following script)
/Dev/MD5/mnt ext3 defaults 00
-
How do I delete a disk array?
# Mdadm/dev/md0 -- f ail/dev/sda1 -- remove/dev/sda1
# Mdadm/dev/md0 -- f ail/dev/sdb1 -- remove/dev/sdb1 (Mark sda1 disk as bad disk and
Remove)
# Mdadm -- stop/dev/md0
# Mdadm -- zero-superblock/dev/sda1
# Mdadm -- zero-superblock/dev/sdb1 (clear the raid flag in the disk)
-
If a hard disk breaks down, how can we manually replace and synchronize data?
# Mdadm/dev/md0 -- f ail/dev/sda1 -- remove/dev/sda1 (Mark sda1 disk as bad disk and
Remove)
# Mdadm/dev/md0 -- add/dev/sdc1
New Hard Disk Partition. After the partition is completed, the data is automatically synchronized from sda1
Step to sdc1)
# Cat/proc/mdstat (check the MD status, which can be sync or Resync)
-
If one hard disk breaks down, how can we take the remaining hard disk to another machine and read the data?
# Mdadm -- create -- Auto = Yes/dev/md0 -- level = 1 -- force -- raid-devices = 1/dev/sda1 (directly obtain
This hard disk is used to create a disk array with only one hard disk.
However, the first step is to install the hard disk on the machine)
# Mount/dev/md0/mnt
To see our data in the MNT directory)