Redis Cluster on Windows

레디스 서버 교육 신청 레디스 정기점검/기술지원
Redis Technical Support
레디스 엔터프라이즈 서버
Redis Enterprise Server

Redis Cluster : Tporadowski 버전 레디스 5.0.14

준비

  • 레디스 서버 6대를 설치할 것입니다. 포트는 8000~8005을 사용합니다.
  • "C:\app\redis"에 8000~8005 폴더를 만듭니다.
  • 클러스터용 redis.conf 파일은 6000\redis.conf 파일을 복사해서 사용합니다.
    bind 127.0.0.1
    port 8000
    logfile "c:\\app\\redis\\8000\\redis.log"
    dir "c:\\app\\redis\\8000"
    cluster-enabled yes
    cluster-config-file nodes.conf
    cluster-node-timeout 5000
    cluster-require-full-coverage no

서비스 등록하고 시작하기

  • 서비스 등록하기: [명령 프롬프트]에서 다음 명령을 입력합니다. 서비스 이름은 redis-cluster-8000,...,8005로 합니다.
  • 레디스 서버 시작하기: [명령 프롬프트]에서 다음 명령을 입력해서 시작하거나, [작업 관리자] [서비스]에서 해당 서비스를 우클릭해서 시작할 수 있습니다.

레디스 클러스터 구성하기

  • redis-cli로 구성(생성)합니다. 8000~8002번은 마스터로, 나머지는 복제로 구성합니다.
  • 클러스터 구성 상태를 조회합니다.
  • 8000번 마스터 로그
    [12352] 11:06:53.421 # Server initialized -> 레디스 서버 시작
    [12352] 11:08:21.784 # configEpoch set to 1 via CLUSTER SET-CONFIG-EPOCH -> 클러스터 생성
    [12352] 11:08:24.221 * Replica 127.0.0.1:8005 asks for synchronization -> 복제 요청 받음
    [12352] 11:08:26.760 # Cluster state changed: ok -> 클러스터 정상
  • 8005번 복제 로그
    [14444] 11:07:04.296 # Server initialized -> 레디스 서버 시작
    [14444] 11:08:21.801 # configEpoch set to 6 via CLUSTER SET-CONFIG-EPOCH -> 클러스터 생성
    [14444] 11:08:23.854 # Cluster state changed: ok -> 클러스터 정상
    [14444] 11:08:24.211 * Connecting to MASTER 127.0.0.1:8000 -> 복제 요청
    [14444] 11:08:24.577 * Background append only file rewriting started 3440 -> AOF rewirte 시작
    [14444] 11:08:24.881 * Background AOF rewrite finished successfully -> AOF rewirte 성공
  • 레디스 클러스터가 잘 구성되었습니다.

장애복구(failover) 테스트

  • 8000번 마스터: 다운
    [12352] 14:33:11.030 # User requested shutdown...
  • 8005번 복제 로그
    [14444] 14:33:11.033 # Connection with master lost. -> 8000 Master Down
    [14444] 14:33:17.127 * Marking node 4689bb094c4d76...403 as failing (quorum reached).
    [14444] 14:33:17.234 # Start of election delayed for 509 milliseconds (rank #0, offset 1918).
    [14444] 14:33:27.838 # Currently unable to failover: Failover attempt expired.
    [14444] 14:33:38.895 # Starting a failover election for epoch 8. -> 장애복구 시작
    [14444] 14:33:38.912 # Failover election won: I'm the new master.
    [14444] 14:33:38.912 # configEpoch set to 8 after successful failover -> 장애복구 성공(완료)
  • 8000번 마스터가 다운되고, 8005번 복제가 마스터로 승격되었습니다.
    장애복구(failover)가 잘 처리되었습니다.
  • 주의: 레디스 클러스터 내 레디스 서버(마스터/복제)가 다운되면 나머지 모든 레디스 서버 로그 파일에 아래와 같이 2초 마다 기록됩니다.
    8001번 마스터 로그
    [8692] 14:33:13.059 # Error writing to socket fd 9
    [8692] 14:33:15.098 # Error writing to socket fd 29
    [8692] 14:33:17.234 # Error writing to socket fd 12

8000번 서버 다시 시작

  • 다시 시작하면 마스터로 시작했다가 클러스터에 의해 복제로 변경됩니다.
    [25256] 14:37:53.511 # Server initialized -> 서버 시작
    [25256] 14:37:53.515 # Cluster state changed: ok -> 클러스터 상태 OK
    [25256] 14:37:54.583 * Connecting to MASTER 127.0.0.1:8005 -> Master -> Replica
    [25256] 14:37:54.723 * Background append only file rewriting started by pid 1976 -> AOF rewrite
    [25256] 14:37:55.044 * Background AOF rewrite finished successfully -> AOF rewrite 성공
  • ROLE 명령으로 확인
  • 8001번 Master Log, 다른 서버의 로그도 같다.
    [8692] 14:37:47.876 # Error writing to socket fd 9 -> 8000번 서버가 다운된 동안 발생한다.
    [8692] 14:37:50.012 # Error writing to socket fd 14
    [8692] 14:37:52.123 # Error writing to socket fd 12
    [8692] 14:37:53.764 * Clear FAIL state for node 4689bb094c4d7669d80340a1627e698addff3403: master without slots is reachable again.

원상복구: 8000번 서버를 마스터로 변경

  • 명령으로 8000번 서버를 마스터로 변경합니다.
  • 8000번 서버 Log
    [25256] 15:07:55.725 # Manual failover user request accepted. -> 명령 받음
    [25256] 15:07:55.772 # Starting a failover election for epoch 9. -> 장애복국 시작
    [25256] 15:07:55.779 # Failover election won: I'm the new master.
    [25256] 15:07:55.780 # configEpoch set to 9 after successful failover
    [25256] 15:07:55.954 * Replica 127.0.0.1:8005 asks for synchronization -> 동기화 요청 받음 (부분동기화로 완료)
  • 8000번 서버가 마스터로 변경되었을 확인합니다.
  • 8005번 서버 Log: 마스터에서 복제로 변경됩니다.
    [14444] 15:07:55.726 # Manual failover requested by replica 4689bb094c4d7669d80340a1627e698addff3403. -> 명령 전달 받음
    [14444] 15:07:55.950 * Connecting to MASTER 127.0.0.1:8000 -> 8000번 서버에 동기화 요청
    [14444] 15:07:55.956 * MASTER <-> REPLICA sync: Master accepted a Partial Resynchronization. -> 동기화 완료

정리

  • Tporadowski 버전 레디스 5.0.14: 레디스 클러스터 구성(생성) 시작, 장애복구 등 모두 문제없이 실행됩니다. 사용하는데 문제없습니다. 테스트: 2024년 2월

Redis Cluster : Microsoft 버전 레디스 3.0.5

Ruby 설치

  • redis-trib.rb를 이용하기 위해 아래와 같이 ruby를 설치하고 redis-trib.rb 파일을 받는다.
  • Ruby 파일을 받아 설치 -> rubyinstaller-2.2.4-x64.exe
    설치 후 ruby.exe가 있는 디렉토리를 path에 추가한다. 예) D:\Ruby22-x64\bin
  • Redis Ruby 라이브러리 설치
    > gem install redis
    에러가 발생할 경우 아래처럼 수정해서 실행하세요.
    D:\Ruby22-x64\bin>gem sources --remove https://rubygems.org/
    https://rubygems.org/ removed from sources
    D:\Ruby22-x64\bin>gem sources -a http://rubygems.org/
    https://rubygems.org is recommended for security over http://rubygems.org/
    Do you want to add this insecure source? [yn] y
    http://rubygems.org/ added to sources
    D:\Ruby22-x64\bin>gem install redis
    Fetching: redis-4.0.1.gem (100%)
    Successfully installed redis-4.0.1
    Parsing documentation for redis-4.0.1
    Installing ri documentation for redis-4.0.1
    Done installing documentation for redis after 1 seconds
    1 gem installed
  • redis-trib.rb 받기 -> redis-trib.rb
    스크립트를 redis-trib.rb로 저장. 예) D:\2_Redis_on_Windows\redis-trib.rb

redis-trib.rb를 이용한 클러스터 생성

  • redis-trib.rb 실행 -> 리눅스와 다르게 윈도우에서는 ruby로 시작한다.   redis-trib.rb의 사용방법은 리눅스와 동일하다.
    D:\2_Redis_on_Windows>ruby redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.:7004 127.0.0.1:7005

Cluster 기능

  • Get/Set 같은 DB 저장/조회 명령, Pub/Sub 기능 그리고 클러스터에서 가장 중요한 Failover 관련 기능은 리눅스 버전과 동일하게 잘 동작한다.
  • 단, cluster mode로 실행했을 경우 redis.log에 아래와 같은 에러가 지속적으로 발생한다.   아래 로그는 1초 안에 발생한 것으로 몇 개월 지속되면 로크 파일이 수 기가바이트로 커지게 된다.
    [24720] 10 Jan 17:38:46.042 # WSA_IO_PENDING writing to socket fd 22
    [24720] 10 Jan 17:38:46.043 # clusterWriteDone written 2520 fd 22
    [24720] 10 Jan 17:38:46.211 # WSA_IO_PENDING writing to socket fd 23
    [24720] 10 Jan 17:38:46.211 # clusterWriteDone written 2520 fd 23
    [24720] 10 Jan 17:38:46.887 # WSA_IO_PENDING writing to socket fd 18
    [24720] 10 Jan 17:38:46.889 # clusterWriteDone written 2520 fd 18
  • Microsoft 버전 레디스 3.0.5를 사용할 경우 위 로그 발생 문제에 주의하시기 바랍니다.

<< Sentinel Cluster

Email 답글이 올라오면 이메일로 알려드리겠습니다.