주:

Redis Cluster를 Oracle Cloud Infrastructure Cache로 이전

소개

이 자습서에서는 pyredis-dump 툴을 사용하여 샤딩된 Redis 클러스터 캐시를 이전하기 위한 단계별 프로세스를 제공합니다. pyredis-dump는 Redis 데이터의 덤프 및 복원을 단순화하도록 설계된 Python 기반 툴입니다. 이 절차는 다음 마이그레이션 시나리오 중 하나에 적용됩니다.

이 자습서는 주로 마스터-슬레이브 아키텍처 없이 온프레미스 Redis 클러스터를 OCI로 마이그레이션하는 데 중점을 두지만, Redis 마스터-슬레이브 설정을 사용하는 환경에도 동일한 접근 방식을 적용할 수 있습니다.

Redis 란 무엇입니까?

Redis Cluster 란 무엇입니까?

Redis Cluster는 고가용성과 수평 확장을 제공합니다. 데이터를 여러 노드에 분산된 샤드로 나눕니다. 각 샤드에는 내결함성을 위한 기본 노드와 복제본이 있습니다. 이를 통해 Redis Cluster는 더 큰 데이터 세트와 더 높은 쓰기 처리량을 처리할 수 있습니다.

다음 이미지는 3개의 노드가 기본 노드(M1, M2 및 M3)로 포함되고 각 노드는 슬레이브가 (S1, S2 및 S3)인 3노드 클러스터를 보여줍니다. 고가용성을 제공하기 위해 슬레이브 구성은 선택 사항입니다.

이미지

Redis Cluster는 일관된 해싱을 사용하지 않지만 모든 키가 개념적으로 해시 슬롯이라고 부르는 부분인 다른 형태의 샤딩을 사용합니다. Redis Cluster에는 16384개의 해시 슬롯이 있습니다. Redis 클러스터의 모든 노드는 해시 슬롯의 하위 세트를 담당하므로 예를 들어 노드가 3개인 클러스터가 있을 수 있습니다.

OCI 캐시란?

이미지

목표

필요 조건

작업 1: 온-프레미스(On-Premise) 설정에서 Source Redis 클러스터 설정

  1. 온프레미스 호스트를 구성합니다. RHEL8를 사용하여 3개의 온프레미스 VM(가상 머신) 또는 물리적 호스트를 생성합니다.

    • Redis_Node1: 10.0.0.151
    • Redis_Node2: 10.0.0.164
    • Redis_Node3: 10.0.0.205
  2. 모든 노드에서 포트를 엽니다.

    모든 Redis 클러스터 노드에는 구성에 따라 1~3개의 TCP 연결이 열려 있어야 합니다. 클라이언트를 서비스하는 데 사용되는 일반 Redis TCP 포트(예: 6379)와 데이터 포트에 10000을 추가하여 얻은 포트(클러스터의 경우 16379, Sentinel의 경우 26379)입니다. 방화벽의 모든 포트를 열어야 합니다. 그렇지 않으면 Redis 클러스터 노드가 통신할 수 없습니다. 다음 명령을 실행합니다.

    $firewall-cmd --permanent --add-port=6379/tcp  ( For master/slave replication and clint connection)
    $firewall-cmd --permanent --add-port=16379/tcp ( For Redis Cluster )
    $firewall-cmd --reload
    
  3. 모든 노드에 Redis 소프트웨어를 설치합니다. 다음 명령을 실행하여 RHEL8용 최신 Redis Community Edition 7.4를 다운로드합니다. root 사용자를 사용하여 세 노드 모두에 Redis 소프트웨어를 설치합니다.

    $mkdir /redis
    $wget http://download.redis.io/redis-stable.tar.gz
    $tar xvzf redis-stable.tar.gz
    $cd redis-stable
    $make redis-cli
    $make BUILD_TLS=yes
    $cp src/redis-cli /usr/local/bin/
    $cp redis-server /usr/local/bin/
    $redis-cli -v
    
  4. 모든 노드에서 Redis 구성 파일을 준비합니다.

    마스터당 하나 이상의 복제본(슬레이브)과 고가용성을 위해 Sentinel을 사용하는 3개의 노드 Redis Cluster를 설정하는 것이 좋습니다. 이 예에서는 복제본 없이 3개의 노드 클러스터를 만들었습니다. Redis 클러스터를 구성하려면 /redis 폴더 아래의 세 노드 모두에서 redis.conf이라는 클러스터 구성 파일을 준비해야 합니다.

    $cd /redis
    
    $vi redis.conf
    port 6379
    timeout 0
    protected-mode no
    tcp-keepalive 300
    pidfile "/redis/redis-server.pid"
    logfile "/redis/redis-server.log"
    requirepass "pass123"
    dbfilename "dump.rdb"
    appendonly no
    masterauth "pass123"
    cluster-enabled yes
    cluster-config-file /redis/nodes.conf
    cluster-node-timeout 5000
    
  5. 모든 노드에서 Redis 서버를 시작합니다. 다음 명령을 실행하여 세 노드 모두에서 Redis 서버를 시작합니다.

    [root@instance-20250224-0709 redis]# redis-server
    814355:C 16 Apr 2025 15:30:35.171 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
    814355:C 16 Apr 2025 15:30:35.171 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    814355:C 16 Apr 2025 15:30:35.171 * Redis version=7.4.2, bits=64, commit=00000000, modified=0, pid=814355, just started
    814355:C 16 Apr 2025 15:30:35.171 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
    814355:M 16 Apr 2025 15:30:35.171 * Increased maximum number of open files to 10032 (it was originally set to 1024).
    814355:M 16 Apr 2025 15:30:35.172 * monotonic clock: POSIX clock_gettime
                   _._
             _.-``__ ''-._
          _.-``    `.  `_.  ''-._           Redis Community Edition
    .-`` .-```.  ```\/    _.,_ ''-._     7.4.2 (00000000/0) 64 bit
    (    '      ,       .-`  | `,    )     Running in standalone mode
    |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
    |    `-._   `._    /     _.-'    |     PID: 814355
    `-._    `-._  `-./  _.-'    _.-'
    |`-._`-._    `-.__.-'    _.-'_.-'|
    |    `-._`-._        _.-'_.-'    |           https://redis.io
    `-._    `-._`-.__.-'_.-'    _.-'
    |`-._`-._    `-.__.-'    _.-'_.-'|
    |    `-._`-._        _.-'_.-'    |
    `-._    `-._`-.__.-'_.-'    _.-'
          `-._    `-.__.-'    _.-'
             `-._        _.-'
                `-.__.-'
    
    814355:M 16 Apr 2025 15:30:35.172 * Server initialized
    814355:M 16 Apr 2025 15:30:35.173 * Loading RDB produced by version 7.4.2
    814355:M 16 Apr 2025 15:30:35.173 * RDB age 9 seconds
    814355:M 16 Apr 2025 15:30:35.173 * RDB memory usage when created 2.18 Mb
    814355:M 16 Apr 2025 15:30:35.173 * Done loading RDB, keys loaded: 1, keys expired: 0.
    814355:M 16 Apr 2025 15:30:35.173 * DB loaded from disk: 0.000 seconds
    814355:M 16 Apr 2025 15:30:35.173 * Ready to accept connections tcp
    

    특정 구성 파일을 사용하여 Redis 서버를 시작하고 백그라운드에서 실행합니다.

    $redis-server /redis/redis.conf &
    
  6. Redis 클러스터 생성. 위에서 시작된 세 개의 Redis 서버 모두에서 Redis 클러스터를 만들려면 Node1에서 다음 명령을 실행합니다.

    # redis-cli --cluster create 10.0.0.151:6379 10.0.0.164:6379 10.0.0.205:6379 -a pass123
    
    output:
    
    >>> Performing hash slots allocation on 3 nodes...
    Master[0] -> Slots 0 - 5460
    Master[1] -> Slots 5461 - 10922
    Master[2] -> Slots 10923 - 16383
    
    M: a89cae61ea55xxxxxxxxxxx8ea31c70b0dc290 10.0.0.151:6379
       slots:[0-5460] (5461 slots) master
    M: b914e2031ceaxxxxxxxxxxxa6d7d5d67fa748 10.0.0.164:6379
       slots:[5461-10922] (5462 slots) master
    M: 9e71454df3f0cbexxxxxxxxxxx6ddc34177f7465 10.0.0.205:6379
       slots:[10923-16383] (5461 slots) master
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    

    노드에 대한 샤드 키를 확인할 수 있습니다.

    • 노드 1 (10.0.0.151) 0-5460
    • 노드 2 (10.0.0.164) 5461-10922
    • 노드 3 (10.0.0.205) 10923-16383
  7. Redis 클라이언트 유틸리티를 사용하여 Redis 클러스터에 연결하고 클러스터 노드를 검증합니다.

    Redis 명령줄 인터페이스(redis-cli라고도 함)는 Redis 서버에 명령을 보내고 Redis 서버에서 응답을 읽는 터미널 프로그램입니다. Redis-cli는 Redis 설치의 일부로 자동으로 설치됩니다.

    • $redis-cli -a pass123 -p 6379 -c 명령을 실행하여 로컬 호스트에 연결합니다.

    • $redis-cli -a pass123 -p 6379 -h 10.0.0.151 -c 명령을 실행하여 원격에서 연결합니다.

    127.0.0.1:6379> cluster nodes
    
    b914e2031cea8bxxxxxxxxxxxe9a6d7d5d67fa748 10.0.0.164:6379@16379 master - 0 1740409776706 2 connected 5461-10922
    a89cae61ea553420c7xxxxxxxxxxx8ea31c70b0dc290 10.0.0.151:6379@16379 myself,master - 0 1740409775000 1 connected 0-5460
    9e71454df3f0cbvxxxxxxxxxxx46ddc34177f7465 10.0.0.205:6379@16379 master - 0 1740409776000 3 connected 10923-16383
    
    127.0.0.1:6379>
    
  8. 클러스터에서 DML(데이터 조작어) 작업을 수행합니다.

    Redis Cluster 환경에서 데이터(읽기/쓰기 작업)는 샤드 키에서 파생된 해시 슬롯을 기반으로 적절한 노드로 자동으로 재지정됩니다.

    $redis-cli -a pass123 -p 6379 -c
    
    127.0.0.1:6379> ping
    PONG
    
    127.0.0.1:6379> set name Dharmesh
    -> Redirected to slot [5798] located at 10.0.0.164:6379
    OK
    
    10.0.0.164:6379> set age 40
    -> Redirected to slot [741] located at 10.0.0.151:6379
    OK
    
    10.0.0.151:6379> set gender M
    -> Redirected to slot [15355] located at 10.0.0.205:6379
    OK
    
    127.0.0.1:6379> KEYS *
    1) "name"
    2) "age"
    3) "gender"
    >SAVE
    10.0.0.205:6379> exit
    

    저장하여 /redis/dump.rdb 아래의 Redis 클러스터에서 데이터 지속성을 보장합니다. RDB(Redis Database) 스냅샷 또는 AOF(Append-Only Files)를 사용할 수 있습니다. RDB는 지정된 간격으로 인메모리 데이터베이스의 스냅샷을 생성하고, AOF는 모든 쓰기 작업을 기록하며, 실패 시 데이터베이스를 재구성할 수 있습니다.

작업 2: OCI 캐시에 Target Redis 클러스터 설정

  1. OCI 콘솔에 로그인하여 데이터베이스, OCI 캐시로 이동하고 클러스터를 누릅니다.

    이미지

  2. 각 컴파트먼트를 선택하고 클러스터 생성을 누릅니다.

  3. 클러스터 이름, 컴파트먼트에 생성OCI 캐시 엔진 버전을 선택합니다.

    이미지

  4. Cluster mode(클러스터 모드), Shard count(샤드 수), Node per Shard(샤드당 노드)Memory per node(노드당 메모리)를 선택합니다.

    이미지

  5. VCN서브넷을 선택합니다.

    이미지

  6. 검토 후 Create cluster를 누릅니다.

    이미지

    OCI 클러스터 프로비전이 완료되면 다음 이미지와 같아야 합니다. 세 개의 클러스터 노드와 프라이빗 끝점이 표시됩니다.

    이미지

작업 3: OCI 캐시 클러스터에 대한 접속 생성

OCI 캐시는 SaaS이며 Redis 호스트에 직접 액세스할 수 없습니다. OCI 캐시에 접속하려면 동일한 VCN 및 서브넷 내에서 클러스터에 안전하게 액세스하기 위해 퍼블릭 서브넷에 점프 인스턴스 또는 OCI 배스천 호스트를 생성해야 합니다.

이미지

OCI에서 배스천/점프 프로비전

  1. OCI 콘솔로 이동하여 ID 및 보안으로 이동하고 배스천을 누릅니다.

  2. 컴파트먼트, VCN, 서브넷, CIDR 블록 허용 목록을 선택하고 배스천 생성을 누릅니다.

    이미지

  3. 다음 명령을 실행하여 점프 호스트에 Redis를 설치합니다.

    sudo su -
    mkdir /redis
    wget http://download.redis.io/redis-stable.tar.gz
    tar xvzf redis-stable.tar.gz
    cd redis-stable
    make redis-cli
    make BUILD_TLS=yes
    cp src/redis-cli /usr/local/bin/
    cp redis-server /usr/local/bin/
    $redis-cli -v
    
  4. 점프 호스트에서 클러스터 노드 중 하나에 연결하고 노드를 검증합니다.

    Connect Cluster Node1
    $redis-cli -h aaantxkdlyarjuuzfc5qgic3xdbxxxxxxxxxxxo6aj65pokndqtnwa-1-1.redis.us-ashburn-1.oci.oraclecloud.com --tls -c
    
    Connect Cluster Node2
    $redis-cli -h aaantxkdlyarjuuzfc5qgic3xxxxxxxxxxxxa5vo6aj65pokndqtnwa-2-1.redis.us-ashburn-1.oci.oraclecloud.com --tls -c
    
    Connect Cluster Node3
    $redis-cli -h aaantxkdlyarjuuzfc5qgic3xxxxxxxxxxxfeaa5vo6aj65pokndqtnwa-3-1.redis.us-ashburn-1.oci.oraclecloud.com --tls -c
    
    
    Validate OCI cluster Nodes:
    
    > cluster nodes
    b89bf86956a0ce19e6b4xxxxxxxxxxxcd41d0b78dd 10.0.15.21:6379@16379,aaantxkdlyarjuuzfc5qgicxxxxxxxxxxxvo6aj65pokndqtnwa-2-1.redis.us-ashburn-1.oci.oraclecloud.com master - 0 1740462307292 2 connected 5462-10922
    ba2253bcdb56f2e5227xxxxxxxxxxx9672cb527eab 10.0.5.150:6379@16379,aaantxkdlyarjuuzfc5qgic3xdbxxxxxxxxxxxvo6aj65pokndqtnwa-3-1.redis.us-ashburn-1.oci.oraclecloud.com master - 0 1740462305276 0 connected 10923-16383
    b59af7d22e86c5600xxxxxxxxxxxe17bf34ca5aab 10.0.61.100:6379@16379,aaantxkdlyarjuuzfc5qgicxxxxxxxxxxxa5vo6aj65pokndqtnwa-1-1.redis.us-ashburn-1.oci.oraclecloud.com myself,master - 0 1740462305000 1 connected 0-5461
    

    샤드 키를 확인할 수 있습니다.

    • 클러스터 1 (1-1) 0-5461
    • 클러스터-2 (2-1) 5462-10922
    • 클러스터-3 (3-1) 5462-10922

작업 4: Pyredis-dump 유틸리티를 사용하여 온프레미스에서 OCI 클러스터로 데이터 이전

  1. 점프/배스천 호스트에 pyredis-dump 유틸리티를 설치합니다.

    $cd /redis/
    $yum install git
    $git clone https://github.com/tkote/pyredis-dump.git
    $cd /redis/pyredis-dump
    $python -m pip install redis
    $python3 pyredis-dump.py -h
    
  2. 점프/배스천 호스트에서 온프레미스 Redis 클러스터에 대한 접속을 확인하십시오.

    [root@jump ~]# redis-cli -a pass123 -p 6379 -h 10.0.0.151 -c
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    10.0.0.151:6379>
    
    [root@jump ~]# redis-cli -a pass123 -p 6379 -h 10.0.0.164 -c
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    10.0.0.164:6379>
    
    [root@jump ~]# redis-cli -a pass123 -p 6379 -h 10.0.0.205 -c
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    10.0.0.205:6379>
    
  3. 소스 클러스터에서 덤프를 내보냅니다. 점프 호스트에서 각 Redis 마스터 노드에 연결하고 원격 덤프를 만듭니다. 덤프가 제공된 위치의 점프 호스트에 생성됩니다.

    1. 마스터 Node1에서 덤프를 가져옵니다.

      # python3 pyredis-dump.py -H 10.0.0.151 dump -o /redis/dump/rdump1 -w pass123
      dumping to '/redis/dump/rdump1'
      connecting to {'db': 0, 'host': '10.0.0.151', 'port': 6379, 'ssl': None, 'password': 'pass123'}
      1 keys, bulk_size: 1000, watch_keys: False
      dumped 1 records
      elapsed time: 0.399 seconds
      
    2. 마스터 Node2에서 덤프를 가져옵니다.

      # python3 pyredis-dump.py -H 10.0.0.164 dump -o /redis/dump/rdump2 -w pass123
      dumping to '/redis/dump/rdump2'
      connecting to {'db': 0, 'host': '10.0.0.164', 'port': 6379, 'ssl': None, 'password': 'pass123'}
      1 keys, bulk_size: 1000, watch_keys: False
      dumped 1 records
      elapsed time: 0.004 seconds
      
    3. 마스터 Node3에서 덤프를 가져옵니다.

      # python3 pyredis-dump.py -H 10.0.0.205 dump -o /redis/dump/rdump3 -w pass123
      dumping to '/redis/dump/rdump3'
      connecting to {'db': 0, 'host': '10.0.0.205', 'port': 6379, 'ssl': None, 'password': 'pass123'}
      1 keys, bulk_size: 1000, watch_keys: False
      dumped 1 records
      elapsed time: 0.006 seconds
      
  4. 데이터를 임포트하기 전에 OCI 캐시에서 대상 클러스터를 정리하고 클러스터 노드 중 하나에 데이터가 없는지 확인하십시오.

    OCI Cluster Node1
    
    # redis-cli -h aaantxkdlyarjuuzfc5qgic3xdbckjxxxxxxxxxxxaj65pokndqtnwa-1-1.redis.us-ashburn-1.oci.oraclecloud.com --tls
    > flushall
    OK
    
    OCI Cluster Node2
    
    # redis-cli -h aaantxkdlyarjuuzfc5qgic3xdbckjxxxxxxxxxxxj65pokndqtnwa-2-1.redis.us-ashburn-1.oci.oraclecloud.com --tls
    > flushall
    OK
    
    OCI Cluster Node3
    
    # redis-cli -h aaantxkdlyarjuuzfc5qgic3xdbckjkxxxxxxxxxxx6aj65pokndqtnwa-3-1.redis.us-ashburn-1.oci.oraclecloud.com --tls
    > flushall
    OK
    
  5. OCI 캐시의 대상 클러스터로 덤프를 임포트합니다. 각 OCI 클러스터에 접속하고 소스 및 대상의 샤드 키를 기반으로 각 클러스터로 덤프를 임포트합니다. shard key 0-5460가 있는 마스터 Node1의 익스포트 덤프는 각각 대상 클러스터의 마스터 node1로 임포트해야 합니다.

    다음 단계에서 덤프를 임포트해야 합니다. 그렇지 않으면 실패합니다.

    1. Node1에서 OCI Cluster1-1로 덤프를 임포트합니다.

      # python3 pyredis-dump.py -S -H aaantxkdlyarjuuzfxxxxxxxxxxxk5bfeaa5vo6aj65pokndqtnwa-1-1.redis.us-ashburn-1.oci.oraclecloud.com restore -i /redis/dump/rdump1
      restore from '/redis/dump/rdump1'
      connecting to {'db': 0, 'host': 'aaantxkdlyarjuuzfcxxxxxxxxxxxkjk5bfeaa5vo6aj65pokndqtnwa-1-1.redis.us-ashburn-1.oci.oraclecloud.com', 'port': 6379, 'ssl': True}
      restored 1 records
      elapsed time: 0.023 seconds
      
    2. Node2에서 OCI Cluster2-1로 덤프를 임포트합니다.

      # python3 pyredis-dump.py -S -H aaantxkdlyarjuuzfc5xxxxxxxxxxxfeaa5vo6aj65pokndqtnwa-2-1.redis.us-ashburn-1.oci.oraclecloud.com restore -i /redis/dump/rdump2
      restore from '/redis/dump/rdump2'
      connecting to {'db': 0, 'host': 'aaantxkdlyarjuuzfc5xxxxxxxxxxxk5bfeaa5vo6aj65pokndqtnwa-2-1.redis.us-ashburn-1.oci.oraclecloud.com', 'port': 6379, 'ssl': True}
      restored 1 records
      elapsed time: 0.024 seconds
      
    3. Node3에서 OCI Cluster3-1로 덤프를 임포트합니다.

      # python3 pyredis-dump.py -S -H aaantxkdlyarjuuzfc5qgixxxxxxxxxxxfeaa5vo6aj65pokndqtnwa-3-1.redis.us-ashburn-1.oci.oraclecloud.com restore -i /redis/dump/rdump3
      restore from '/redis/dump/rdump3'
      connecting to {'db': 0, 'host': 'aaantxkdlyarjuuzfc5xxxxxxxxxxx5bfeaa5vo6aj65pokndqtnwa-3-1.redis.us-ashburn-1.oci.oraclecloud.com', 'port': 6379, 'ssl': True}
      restored 1 records
      elapsed time: 0.030 seconds
      [root@instance-20250223-1032 pyredis-dump]#
      
  6. OCI에서 데이터를 검증합니다. 각 클러스터 노드에서 데이터를 성공적으로 임포트한 후 OCI 클러스터 노드에 접속하고 데이터를 확인합니다.

    Connect Cluster Node1
    $redis-cli -h aaantxkdlyarjuuzfc5qgic3xdbckjk5bfxxxxxxxxxxx65pokndqtnwa-1-1.redis.us-ashburn-1.oci.oraclecloud.com --tls -c
    
    6379> get name
    -> Redirected to slot [5798] located at aaantxkdlyarjxxxxxxxxxxx3xdbckjk5bfeaa5vo6aj65pokndqtnwa-2-1.redis.us-ashburn-1.oci.oraclecloud.com:6379
    "Dharmesh"
    
    6379> get age
    -> Redirected to slot [741] located at aaantxkdlyarjuuxxxxxxxxxxxbckjk5bfeaa5vo6aj65pokndqtnwa-1-1.redis.us-ashburn-1.oci.oraclecloud.com:6379
    "40"
    
    6379> get gender
    -> Redirected to slot [15355] located at aaantxkdlyarjxxxxxxxxxxxxxdbckjk5bfeaa5vo6aj65pokndqtnwa-3-1.redis.us-ashburn-1.oci.oraclecloud.com:6379
    "M"
    
    6379>
    

확인

추가 학습 자원

docs.oracle.com/learn에서 다른 실습을 탐색하거나 Oracle Learning YouTube 채널에서 더 많은 무료 학습 콘텐츠에 액세스하세요. 또한 Oracle Learning Explorer가 되려면 education.oracle.com/learning-explorer을 방문하십시오.

제품 설명서는 Oracle Help Center를 참조하십시오.