리눅스 / 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
같은 카테고리의 다른 글
CentOS 7 / Apache / 하나의 서버에 여러 사이트 운영하기

CentOS 7 / Apache / 하나의 서버에 여러 사이트 운영하기

하나의 서버에 하나의 사이트만 운영하는 것이 가장 이상적일 것입니다. 하지만 사이트 접속자가 많지 않거나 서버 사양이 훌륭하다면 여러 사이트를 하나의 서버에서 운영하는 게 경제적입니다. CentOS에 Apache 웹서버를 설치하고 운영하는 경우 여러 사이트를 운영할 수 있게 설정하는 방법을 요약해보겠습니다. 네임 서버 설정 각 도메인의 네임 서버의 호스트 IP를 웹서버 아이피로 설정합니다. 디렉토리 만들기 한 서버에 aaa.com과 ...

리눅스 / 명령어

명령어 개요 adduser 사용자 추가하는 명령어. alias 명령어 별칭을 만든다. cal calendar. 달력을 출력하는 명령어. cat concatenate. 파일 내용 출력하는 명령어. cd change directory. 다른 디렉토리로 이동하는 명령어. chmod 파일 또는 디렉토리의 읽기, 쓰기, 실행 권한 설정하는 명령어 chown 파일 또는 디렉토리의 소유자(그룹) 설정하는 명령어 clear 터미널 화면의 내용을 다 지운다. cp copy. 파일 또는 디렉토리 복사. du disk usage. 디스크 사용량 출력. file 파일의 종류를 출력하는 명령어 find 파일 또는 디렉토리를 검색하는 명령어 free 메모리 사용량 ...

리눅스 / 로그아웃 명령어, 재부팅 명령어, 종료 명령어

로그아웃 명령어 # logout # exit 재부팅 명령어 즉시 재부팅 # reboot # shutdown -r now # init 6 일정 시간 또는 일정 시간 후 재부팅 10분 후 재부팅 # shutdown -r 10 12시에 재부팅 # shutdown -r 12:00 취소 # shutdown -c 종료 명령어 즉시 종료 # poweroff # shutdown -h now # shutdown -P now # halt -p # init 0 일정 시간 또는 일정 시간 후에 종료 10분 후에 종료 # ...

Ubuntu 18.04 Server / PHP 최신 버전으로 업그레이드하는 방법

Ubuntu 패키지로 설치한 PHP 버전보다 PHP 최신 버전이 더 높을 수 있습니다. 예를 들어 패키지로 설치한 PHP의 버전은 7.0, 최신 버전은 7.2일 수 있다는 것이죠. 만약 최신 버전의 PHP를 사용해야 한다면 다음의 방법으로 설치할 수 있습니다. PHP를 처음 설치하는 경우 저장소를 추가합니다. # add-apt-repository ppa:ondrej/php 패키지 정보를 업데이트합니다. # apt-get update PHP를 설치합니다. # apt-get install php PHP가 ...

Ubuntu 20.04 Server / Samba / 설치하고 공유 폴더 만드는 방법

Ubuntu 20.04 Server / Samba / 설치하고 공유 폴더 만드는 방법

Samba를 이용하여 Ubuntu Server에 공유 폴더를 만들고, Windows 클라이언트에서 접속하는 방법을 알아본다. Samba 설치 Samba를 설치한다. 설치하면 바로 시작하고, 재부팅을 해도 자동으로 시작한다. apt install samba 공유할 폴더를 만들고 권한을 777로 설정한다. mkdir /sharedfolder chmod 777 /sharedfolder 설정 파일은 /etc/samba/smb.conf이다. 텍스트 에디터로 열고 제일 밑에 다음 코드를 추가한다. 폴더 이름은 sharedfolder이지만, 네트워크에서는 Shared Folder로 보인다. comment = ...

Rocky Linux 9 / 설치

Rocky Linux 9 / 설치

다운로드 아래 링크에서 ISO 파일을 다운로드한다. https://rockylinux.org/download Boot, Minimal, DVD 세 가지가 있는데, 다음과 같이 설명되어 있다. Boot Used to install the operating system from another source (such as a HTTP repository of the binary files). Can also be used to enter Rescue Mode. Minimal Used to install the operating system from another source (such as a ...

리눅스 / 명령어 / find / 파일 또는 디렉토리를 찾는 명령어

find는 파일 또는 디렉토리를 찾는 명령어이다. 현재 디렉토리 안에 있는 모든 파일과 디렉토리를 출력한다. 숨긴 파일 또는 숨긴 디렉토리도 출력한다. # find /etc 디렉토리 안에 있는 모든 파일과 디렉토리를 출력한다. 숨긴 파일 또는 숨긴 디렉토리도 출력한다. # find /etc 현재 디렉토리 안에서 이름이 abc인 파일 또는 abc인 디렉토리를 검색한다. # find -name abc 현재 디렉토리 안에서 이름이 ...

리눅스 / 명령어 / 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를 실행하는 ...

Rocky Linux 9 / Apache, PHP, MariaDB 설치

Rocky Linux 9 / Apache, PHP, MariaDB 설치

Rocky Linux 9에 Apache, PHP, MariaDB를 설치하는 방법을 정리합니다.

다른 서버나 컴퓨터의 포트가 열렸는지 확인하는 방법

다른 서버의 특정 포트가 열려 있는지 알아야 할 때가 있습니다. 윈도우와 리눅스에서 확인하는 방법을 정리합니다. 윈도우 telnet 명령어 이용하는 방법 텔넷 클라이언트 기능을 추가합니다. 명령 프롬프트(CMD) 또는 PowerShell에서 다음과 같이 명령합니다. google.com의 443 포트가 열렸는지 확인하는 것입니다. C:\Users\JB>telnet google.com 443 포트가 열려 있다면 아무 내용 없는 창이 나옵니다. 만약 닫혀 있다면 아래와 같이 연결하지 못한다는 메시지가 나옵니다. C:\Users\JB>telnet ...