Sovelluspohjainen RAID
HUOM! Sovelluspohjaisen RAID:n hallinnointiin käytämme mdadm-sovellusta. Sen käyttäminen on vaarallista, jos et tiedä mitä teet. Voit menettää palvelimella olevat tiedostosi. Suosittelemme sinua varmuuskopioimaan tiedostosi.
Jos palvelimesi kovalevy vaihdettiin juuri, se on tyhjä eikä sitä ole partitioitu. Sinun täytyy kopioida toisen kovalevyn partitiointi uudelle levylle.
Jos kyseessä on SDA:
sfdisk -d /dev/sdb | sfdisk /dev/sda
Jos kyseessä on SDB:
sfdisk -d /dev/sda | sfdisk /dev/sdb
Partitioinnit näet komennolla:
fdisk -l
mdadm
Sovellus on asennettuna useaan distribuutioon valmiina. Sen käytöstä voit lukea tarkemmin sovelluksen man-sivuilta:
man mdadm
Tai lisäkomennolla --help:
lauri@ovh:~$ mdadm --misc --help
Usage: mdadm misc_option devices...
This usage is for performing some task on one or more devices, which
may be arrays or components, depending on the task.
The --misc option is not needed (though it is allowed) and is assumed
if the first argument in a misc option.
Options that are valid with the miscellaneous mode are:
--query -Q : Display general information about how a
device relates to the md driver
--detail -D : Display details of an array
--examine -E : Examine superblock on an array component
--examine-bitmap -X: Display contents of a bitmap file
--zero-superblock : erase the MD superblock from a device.
--run -R : start a partially built array
--stop -S : deactivate array, releasing all resources
--readonly -o : mark array as readonly
--readwrite -w : mark array as readwrite
--test -t : exit status 0 if ok, 1 if degrade, 2 if dead, 4 if missing
--wait -W : wait for resync/rebuild/recovery to finish
RAID:n tilasta saat lisätietoa käyttämällä lisäkomentoa --misc:
lauri@ovh:~# mdadm --misc --detail /dev/md1
/dev/md1:
Version : 00.90.00
Creation Time : Tue Nov 7 22:01:16 2009
Raid Level : raid1
Array Size : 3068288 (2.93 GiB 3.14 GB)
Device Size : 3068288 (2.93 GiB 3.14 GB)
Raid Devices : 2
Total Devices : 1
Preferred Minor : 1
Persistence : Superblock is persistent
Update Time : Wed Nov 8 15:42:35 2009
State : active, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 0
Spare Devices : 0
UUID : 4a9a446d:af55e24b:b311aa61:8dc74ed4
Events : 0.12
Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1
1 0 0 1 removed
Ylläolevasta esimerkistä näemme, että meillä on 3 GB:n RAID 1, joka on degraded-tilassa, koska sdb1 puuttuu.
Tässä esimerkkejä komennoista, miten lisäämme kovalevyn RAID:iin degraded-tilassa:
# mdadm /dev/md1 --manage --add /dev/sdb1
mdadm: hot added /dev/sdb1
RAID rakentuu uudestaan:
# cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid5]
read_ahead 1024 sectors
md1 : active raid1 sdb1[2] sda1[0]
3068288 blocks [2/1] [U_]
[=>...................] recovery = 5.4% (167028/3068288) finish=0.8min speed=55676K/sec
md2 : active raid1 sda2[0]
240597376 blocks [2/1] [U_]
Muutaman minuutin kuluttua uudelleenrakentaminen on valmis:
# mdadm --misc --detail /dev/md1
/dev/md1:
Version : 00.90.00
Creation Time : Tue Nov 7 22:01:16 2009
Raid Level : raid1
Array Size : 3068288 (2.93 GiB 3.14 GB)
Device Size : 3068288 (2.93 GiB 3.14 GB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 1
Persistence : Superblock is persistent
Update Time : Wed Nov 8 16:01:02 2009
State : active
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
UUID : 4a9a446d:af55e24b:b311aa61:8dc74ed4
Events : 0.14
Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1
1 8 17 1 active sync /dev/sdb1
Teemme saman md2:lla:
# mdadm /dev/md2 --manage --add /dev/sdb2
mdadm: hot added /dev/sdb2
RAID rakentuu uudestaan:
# mdadm --misc --detail /dev/md2
/dev/md2:
Version : 00.90.00
Creation Time : Tue Nov 7 22:01:16 2009
Raid Level : raid1
Array Size : 240597376 (229.45 GiB 246.37 GB)
Device Size : 240597376 (229.45 GiB 246.37 GB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 2
Persistence : Superblock is persistent
Update Time : Wed Nov 8 16:06:43 2009
State : active, degraded, recovering
Active Devices : 1
Working Devices : 2
Failed Devices : 0
Spare Devices : 1
Rebuild Status : 0% complete
UUID : e8754328:26f28599:8b834aba:ade37773
Events : 0.10
Number Major Minor RaidDevice State
0 8 2 0 active sync /dev/sda2
1 0 0 1 removed
2 8 18 2 spare /dev/sdb2
# cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid5]
read_ahead 1024 sectors
md1 : active raid1 sdb1[1] sda1[0]
3068288 blocks [2/2] [UU]
md2 : active raid1 sdb2[2] sda2[0]
240597376 blocks [2/1] [U_]
[>....................] recovery = 0.2% (655104/240597376) finish=73.2min speed=54592K/sec
unused devices:
Lopuksi tarkastamme Swapin koon:
cat /proc/swaps
Filename Type Size Used Priority
/dev/sdb3 partition 522104 43984 -1
Ja lisäämme Swapin uudelle kovalevylle:
mkswap /dev/sda3
swapon -a