리눅스 / RAID / Linear RAID, RAID0, RAID1, RAID5, RAID6

RAID 뜻과 종류

RAID

  • Redundant Array of Inexpensive Disk or Redundant Array of Independent Disk
  • 여러 개의 하드디스크를 하나처럼 사용하게 하는 기술. 예를 들어 1TB 하드디스크 두 개를 묶어서 2TB 하드디스크처럼 사용할 수 있다.
  • 크게 하드웨어 RAID와 소프트웨어 RAID로 구분할 수 있다.
  • 하드웨어 RAID는 성능이 좋으나 비싸다.
  • 소프트웨어 RAID는 운영체제에서 지원하는 것으로 OS RAID라고도 한다.

Linear RAID

  • 두 개 이상의 하드디스크를 하나처럼 사용하는 가장 단순한 RAID.
  • 1TB + 2TB + 3TB = 6TB
  • 순차적으로 하드디스크 사용. 예를 들어 A, B, C 하드디스크로 Linear RAID를 구성했다면 A에 먼저 데이터를 저장하고 A가 꽉 차면 B에 저장.
  • RAID에 속한 디스크가 손상되어도, 손상되지 않은 디스크에 있는 데이터는 살아 있음.

RAID0

  • 두 개 이상의 하드디스크를 하나처럼 사용하는데, 저장은 디스크에 분배하여 저장한다. 예를 들어 A, B, C 디스크에 파일을 저장하면 1/3씩 나누어 각각의 디스크에 저장.
  • 하나의 디스크가 꽉 차면 분배가 불가능하므로 작은 크기의 하드디스크 용량에 맞춰진다.
  • 1TB + 2TB + 3TB = 3TB (각 디스크마다 1TB 만큼만 사용 가능)
  • Linear RAID에 비하여 속도가 빠르지만, 하나의 디스크만 고장 나도 모든 데이터가 손실된다.

RAID1

  • 데이터를 하드디스크 여러 디스크에 중복하여 저장하는 것으로 데이터 보존에 중점을 둔 방식.
  • 하나의 디스크가 꽉 차면 동시 저장이 불가능하므로 작은 크기의 하드디스크 용량에 맞춰진다.
  • 1TB + 2TB = 1TB
  • 하나의 하드디스크만 정상이어도 데이터 손실이 없음.

RAID5

  • 세 개 이상의 하드디스크를 묶는 RAID.
  • 모든 하드디스크에 분배하여 저장하고, Parity 한 개 사용.
  • 한 개의 하드디스크가 고장 나도 데이터 손실이 없음.
  • 1TB + 1TB + 1TB + 1TB = 3TB

RAID6

  • 네 개 이상의 하드디스크 필요.
  • 모든 하드디스크에 분배하여 저장하고, Parity 두 개 사용.
  • 두 개의 하드디스크가 고장 나도 데이터 손실이 없음.
  • 1TB + 1TB + 1TB + 1TB + 1TB = 3TB
  • RAID5에 비하여 성능이 떨어짐.

RAID용 파티션 만들기

  • fdisk 명령어로 디스크에 파티션을 만든다. 파티션의 Hex code는 fd로 한다.
  • 예를 들어 /dev/sdb에 파티션을 만든다면 다음과 같이 한다.
  • n → 엔터 4번 → t → fd → w
# fdisk /dev/sdb
Welcome 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.


Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-209715199, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
  • RAID에 사용할 디스크는 모두 위와 같이 작업한다.
  • 아래는 RAID 구성에 사용할 디스크 9개를 장착하고 파티션을 만든 결과이다.
# ls -l /dev/sd*
brw-rw----. 1 root disk 8,   0 Oct 12 19:13 /dev/sda
brw-rw----. 1 root disk 8,   1 Oct 12 19:13 /dev/sda1
brw-rw----. 1 root disk 8,   2 Oct 12 19:13 /dev/sda2
brw-rw----. 1 root disk 8,  16 Oct 12 19:33 /dev/sdb
brw-rw----. 1 root disk 8,  17 Oct 12 19:33 /dev/sdb1
brw-rw----. 1 root disk 8,  32 Oct 12 19:34 /dev/sdc
brw-rw----. 1 root disk 8,  33 Oct 12 19:34 /dev/sdc1
brw-rw----. 1 root disk 8,  48 Oct 12 19:34 /dev/sdd
brw-rw----. 1 root disk 8,  49 Oct 12 19:34 /dev/sdd1
brw-rw----. 1 root disk 8,  64 Oct 12 19:36 /dev/sde
brw-rw----. 1 root disk 8,  65 Oct 12 19:36 /dev/sde1
brw-rw----. 1 root disk 8,  80 Oct 12 19:34 /dev/sdf
brw-rw----. 1 root disk 8,  81 Oct 12 19:34 /dev/sdf1
brw-rw----. 1 root disk 8,  96 Oct 12 19:34 /dev/sdg
brw-rw----. 1 root disk 8,  97 Oct 12 19:34 /dev/sdg1
brw-rw----. 1 root disk 8, 112 Oct 12 19:35 /dev/sdh
brw-rw----. 1 root disk 8, 113 Oct 12 19:35 /dev/sdh1
brw-rw----. 1 root disk 8, 128 Oct 12 19:35 /dev/sdi
brw-rw----. 1 root disk 8, 129 Oct 12 19:35 /dev/sdi1
brw-rw----. 1 root disk 8, 144 Oct 12 19:35 /dev/sdj
brw-rw----. 1 root disk 8, 145 Oct 12 19:35 /dev/sdj1

RAID 만들기

목표는 아래와 같이 RAID를 구성하는 것.

  • 다음과 같이 명령하여 Linear RAID를 만든다.
  • /dev/md1 : 접근할 수 있는 이름. 이름은 /dev/md9처럼 md 뒤에 숫자를 붙여서 만든다.
  • --level=linear : Linear RAID를 만들겠다는 뜻. linear 대신 0, 1, 5, 6을 쓰면 RAID0, RAID1, RAID5, RAID6을 만든다.
  • --raid-devices=2 : 두 개의 디스크를 사용하겠다는 뜻.
# mdadm --create /dev/md1 --level=linear --raid-devices=2 /dev/sdb1 /dev/sdc1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
  • 레이드 정보는 mdadm 명령어의 --detail 옵션으로 볼 수 있다.
# mdadm --detail /dev/md1
/dev/md1:
           Version : 1.2
     Creation Time : Wed Oct 13 19:00:59 2021
        Raid Level : linear
        Array Size : 314437632 (299.87 GiB 321.98 GB)
      Raid Devices : 2
     Total Devices : 2
       Persistence : Superblock is persistent

       Update Time : Wed Oct 13 19:00:59 2021
             State : clean
    Active Devices : 2
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 0

          Rounding : 0K

Consistency Policy : none

              Name : centos-7-01:1  (local to host centos-7-01)
              UUID : 2fbd4f18:2ba78530:0688808c:ce3614dd
            Events : 0

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       33        1      active sync   /dev/sdc1
  • 다음과 같이 명령하여 RAID0를 만든다.
# mdadm --create /dev/md2 --level=0 --raid-devices=2 /dev/sdd1 /dev/sde1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md2 started.
# mdadm --detail /dev/md2
/dev/md2:
           Version : 1.2
     Creation Time : Wed Oct 13 19:01:48 2021
        Raid Level : raid0
        Array Size : 209580032 (199.87 GiB 214.61 GB)
      Raid Devices : 2
     Total Devices : 2
       Persistence : Superblock is persistent

       Update Time : Wed Oct 13 19:01:48 2021
             State : clean
    Active Devices : 2
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 0

        Chunk Size : 512K

Consistency Policy : none

              Name : centos-7-01:2  (local to host centos-7-01)
              UUID : 042ff5cb:d504b4ea:d5bfdceb:8f639b76
            Events : 0

    Number   Major   Minor   RaidDevice State
       0       8       49        0      active sync   /dev/sdd1
       1       8       65        1      active sync   /dev/sde1
  • 다음과 같이 명령하여 RAID1을 만든다.
# mdadm --create /dev/md3 --level=1 --raid-devices=2 /dev/sdf1 /dev/sdg1
mdadm: Note: this array has metadata at the start and
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md3 started.
# mdadm --detail /dev/md3
/dev/md3:
           Version : 1.2
     Creation Time : Wed Oct 13 19:02:53 2021
        Raid Level : raid1
        Array Size : 104790016 (99.94 GiB 107.30 GB)
     Used Dev Size : 104790016 (99.94 GiB 107.30 GB)
      Raid Devices : 2
     Total Devices : 2
       Persistence : Superblock is persistent

       Update Time : Wed Oct 13 19:13:32 2021
             State : clean, resyncing
    Active Devices : 2
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 0

Consistency Policy : resync

     Resync Status : 55% complete

              Name : centos-7-01:3  (local to host centos-7-01)
              UUID : e562257d:8aea50ad:d1c94c37:4bd39d94
            Events : 10

    Number   Major   Minor   RaidDevice State
       0       8       81        0      active sync   /dev/sdf1
       1       8       97        1      active sync   /dev/sdg1
  • 다음과 같이 명령하여 RAID5를 만든다.
# mdadm --create /dev/md4 --level=5 --raid-devices=3 /dev/sdh1 /dev/sdi1 /dev/sdj1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md4 started.
# mdadm --detail /dev/md4
/dev/md4:
           Version : 1.2
     Creation Time : Wed Oct 13 19:03:29 2021
        Raid Level : raid5
        Array Size : 209580032 (199.87 GiB 214.61 GB)
     Used Dev Size : 104790016 (99.94 GiB 107.30 GB)
      Raid Devices : 3
     Total Devices : 3
       Persistence : Superblock is persistent

       Update Time : Wed Oct 13 19:34:40 2021
             State : clean
    Active Devices : 3
   Working Devices : 3
    Failed Devices : 0
     Spare Devices : 0

            Layout : left-symmetric
        Chunk Size : 512K

Consistency Policy : resync

              Name : centos-7-01:4  (local to host centos-7-01)
              UUID : 7136aaa7:624fb41e:07dc4a32:b24b605b
            Events : 1156

    Number   Major   Minor   RaidDevice State
       0       8      113        0      active sync   /dev/sdh1
       1       8      129        1      active sync   /dev/sdi1
       3       8      145        2      active sync   /dev/sdj1
  • RAID 목록은 다음과 같이 명령하여 볼 수 있다.
# ls -l /dev/md*
brw-rw----. 1 root disk 9, 1 Oct 13 19:00 /dev/md1
brw-rw----. 1 root disk 9, 2 Oct 13 19:01 /dev/md2
brw-rw----. 1 root disk 9, 3 Oct 13 19:02 /dev/md3
brw-rw----. 1 root disk 9, 4 Oct 13 19:03 /dev/md4

포맷하고 마운트 하기

  • 일반 파티션과 마찬가지 방식으로 포맷한다.
  • 아래는 /dev/md1을 ext4 형식으로 포맷하는 것. 마찬가지 방식으로 /dev/md2, /dev/md3, /dev/md4를 포맷한다.
# mkfs.ext4 /dev/md1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
19652608 inodes, 78609408 blocks
3930470 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2227175424
2399 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
  • 마운트할 폴더를 만든다.
mkdir /RAIDL /RAID0 /RAID1 /RAID5
  • 마운트 한다.
# mount /dev/md1 /RAIDL
# mount /dev/md2 /RAID0
# mount /dev/md3 /RAID1
# mount /dev/md4 /RAID5
  • 아래는 마운트 한 결과. 사이즈를 주의 깊게 보자.
# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  9.4M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   50G  4.3G   46G   9% /
/dev/mapper/centos-home  969G   37M  969G   1% /home
/dev/sda1               1014M  239M  776M  24% /boot
tmpfs                    379M   12K  379M   1% /run/user/42
tmpfs                    379M     0  379M   0% /run/user/0
/dev/md1                 296G   65M  280G   1% /RAIDL
/dev/md2                 197G   61M  187G   1% /RAID0
/dev/md3                  99G   61M   94G   1% /RAID1
/dev/md4                 197G   61M  187G   1% /RAID5

장애 발생 시 복구하는 방법

  • 예를 들어 /dev/md3에 속한 /dev/sdg가 망가져서 제거했다고 하자. 그래도 여전히 데이터는 사용할 수 있다.
  • RAID 정보에는 파티션이 제거되었다고 나온다.
# mdadm --detail /dev/md3
/dev/md3:
           Version : 1.2
     Creation Time : Wed Oct 13 19:02:53 2021
        Raid Level : raid1
        Array Size : 104790016 (99.94 GiB 107.30 GB)
     Used Dev Size : 104790016 (99.94 GiB 107.30 GB)
      Raid Devices : 2
     Total Devices : 1
       Persistence : Superblock is persistent

       Update Time : Wed Oct 13 19:43:12 2021
             State : clean, degraded
    Active Devices : 1
   Working Devices : 1
    Failed Devices : 0
     Spare Devices : 0

Consistency Policy : resync

              Name : centos-7-01:3  (local to host centos-7-01)
              UUID : e562257d:8aea50ad:d1c94c37:4bd39d94
            Events : 850

    Number   Major   Minor   RaidDevice State
       -       0        0        0      removed
       1       8       81        1      active sync   /dev/sdf1
  • 새 디스크를 장착하고, 레이드용 파티션을 만든다.
  • 파티션이 /dev/sdj1이라면, 아래와 같이 명령하여 /dev/md3에 추가한다.
# mdadm /dev/md3 --add /dev/sdj1
mdadm: added /dev/sdj1
  • RAID 정보를 보면 리빌딩 한다고 나오고, 충분한 시간이 지나면 RAID 복구가 완료된다.
# mdadm --detail /dev/md3
/dev/md3:
           Version : 1.2
     Creation Time : Wed Oct 13 19:02:53 2021
        Raid Level : raid1
        Array Size : 104790016 (99.94 GiB 107.30 GB)
     Used Dev Size : 104790016 (99.94 GiB 107.30 GB)
      Raid Devices : 2
     Total Devices : 2
       Persistence : Superblock is persistent

       Update Time : Wed Oct 13 23:08:02 2021
             State : clean, degraded, recovering
    Active Devices : 1
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 1

Consistency Policy : resync

    Rebuild Status : 5% complete

              Name : centos-7-01:3  (local to host centos-7-01)
              UUID : e562257d:8aea50ad:d1c94c37:4bd39d94
            Events : 875

    Number   Major   Minor   RaidDevice State
       2       8      145        0      spare rebuilding   /dev/sdj1
       1       8       81        1      active sync   /dev/sdf1

RAID 제거하기

예를 들어 /dev/md1로 레이드를 만들었다면, 다음과 같이 제거한다.

  • 마운트가 되어 있다면 해제한다.
# umount /dev/md1
  • 레이드를 정지한다.
# mdadm --stop /dev/md1
  • 레이드에 속해있던 파티션에 있는 레이드 정보를 제거한다. 예를 들어 /dev/sdb1에 있는 레이드 정보를 제거하려면 다음과 같이 명령한다.
# mdadm --zero-superblock /dev/sdb1
같은 카테고리의 다른 글

리눅스 / crontab 사용법

cron & crontab cron은 특정 시간에 특정 작업을 수행하게 하는 시스템 대몬이다. 백업, 캐시 메모리 비우기 등 주기적으로 어떤 작업을 해야할 때 유용하다. crontab은 시간과 작업을 적은 텍스트 파일이다. 사용자별로 파일이 존재한다. cron은 모든 사용자의 crontab 파일을 찾아서, 적혀진 일정대로 작업을 수행한다. 작업 목록 보기 예약 작업 목록을 보고 싶다면 다음과 같이 명령한다. 사용자의 crontab ...

리눅스 / 명령어 / cp - 복사하는 명령어, mv - 이동하는 명령어

cp는 copy의 약자로 복사하는 명령어, mv는 move의 약자로 이동하는 명령어이다. 복사하기 abc.txt 파일을 def.txt로 이름을 바꾸어 복사한다. cp abc.txt def.txt xyz라는 디렉토리가 없다면 abc.txt 파일을 xyz 파일로 복사한다. xyz라는 디렉토리가 있다면 xyz 디렉토리 안에 abc.txt 파일을 복사한다. cp abc.txt xyz abc.txt 파일을 xyz 디렉토리 안에 def.txt라는 이름으로 복사한다. cp abc.txt xyz/def.txt abc가 디렉토리이고 xyz라는 디렉토리가 없다면, abc 디렉토리를 xyz로 ...

리눅스 / chown, chmod / 파일 또는 디렉토리 소유자, 소유그룹, 권한 설정

ls -l ls 명령어에 -l 옵션을 붙여서 파일 또는 디렉토리의 권한과 소유자(그룹)을 확인할 수 있습니다. 제일 앞에 있는 문자는 디렉토리인지 파일인지는 나타냅니다. d는 디렉토리라는 뜻이고, -는 파일이라는 뜻입니다. 그 다음 3개의 문자열은 소유자의 권한을, 그 다음 3개의 문자열은 소유그룹의 권한을, 그 다음 3개의 문자열은 소유자(그룹) 이외의 권한을 나타냅니다. 처음 나오는 jb는 소유자, 그 다음 ...

리눅스 / 캐시 메모리 삭제하는 방법

free 명령어로 메모리 사용 현황을 볼 수 있다. 아래의 경우 free에 여유가 있는데, 만약 buff/cache 사용량이 많아 free에 공간이 없다면 시스템이 느려진다. 그런 경우 메모리 캐시를 삭제하여 속도를 향상 시킬 수 있다. # free total ...

리눅스 / 명령어 / alias / 명령어 별칭 만들기

긴 명령어 또는 복잡한 명령어를 자주 사용한다면 alias를 사용하자. 시간을 많이 절약할 수 있다. alias 목록 보기 alias를 실행하면 현재 등록된 alias를 출력한다. alias 예를 들어 ll을 실행한다는 것은 ls -alF를 실행하는 것과 같다. alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l='ls -CF' alias la='ls -A' alias ll='ls -alF' alias ls='ls --color=auto' alias 만들기 alias는 다음과 같이 만든다. abc를 실행하는 ...

리눅스 / 명령어 / history / 이전에 실행했던 명령어 목록 출력하는 명령어

history는 이전에 실행했던 명령어 목록 출력하는 명령어이다. history 이전에 실행했던 명령어 목록을 일련번호와 함께 출력한다. # history history n 최근 n개의 명령어 목록을 출력한다. 다음과 같이 명령하면 최근 실행한 10개의 명령어를 출력한다. # history 10 !! !!를 입력하고 엔터를 누르면 직전에 실행했던 명령어를 다시 실행한다. !n 일련번호가 n인 명령어를 실행한다. 다음과 같이 명령하면 번호가 202인 명령어를 실행한다. # !202

리눅스 / 명령어 / cd / 다른 디렉토리로 이동하는 명령어

cd는 change directory의 약자로, 다른 디렉토리로 이동하는 명령어이다. cd 현재 로그인한 사용자의 홈 디렉토리로 이동한다. 일반적으로 root 계정이라면 /root로, 사용자 jb 계정이라면 /home/jb로 이동한다. cd ~user user의 홈 디렉토리로 이동한다. 다음과 같이 명령하면 jb 사용자의 홈 디렉토리로 이동한다. # cd ~jb cd 디렉토리명 지정한 디렉토리로 이동한다. 절대경로, 상대경로 다 사용할 수 있다. 다음과 같이 명령하면 /etc 디렉토리로 이동한다. # cd /etc 현재 ...

리눅스 / LVM / 만드는 방법, 수정하는 방법, 삭제하는 방법

1TB 디스크와 2TB 디스크를 추가했다고 하자. 디스크 크기에 맞게 그대로 사용할 수도 있지만, 3TB 하나인 것처럼 사용하거나 1.5TB 두 개인 것처럼 사용하고 싶을 수도 있다. 즉, 물리적인 디스크 크기와 무관하게 자유롭게 볼륨을 만들고 싶은 것이다. 이럴 때 사용하는 것이 LVM(Logical Volume Manager)이다. 여러 개의 볼륨을 하나로 묶은 후 다시 배분하여 사용한다.(이렇게 ...

리눅스 / 명령어 / cal / 달력을 출력하는 명령어

cal은 달력을 출력하는 명령어이다. 아무 옵션 없이 사용하면 현재 날짜가 속한 달의 달력을 출력한다. cal October 2022 Su Mo Tu We Th Fr Sa 1 2 3 4 5 ...

리눅스 / 명령어 / touch / 빈 파일 만들기, 최종 수정 시간 변경하기

touch는 빈 파일 만들거나 파일의 최종 수정 시간을 현재 시간으로 바꾸는 명령어이다. abc.txt 파일이 없다면, 내용이 없는 abc.txt 파일을 만듭니다. abc.txt 파일이 있다면, 파일의 최종 수정 시간을 현재로 변경합니다. # touch abc.txt