클러스터 설정 파일 이해하기

클러스터 설정 파일


클러스터 구성해보기

  1. 레디스 설치

    brew install redis

  2. 클러스터로 돌아갈 노드를 미리 띄우기 - master 3개, replica 3개

    1. directory 생성

      mkdir 7000

      cp redis.conf 7000/redis-7000.conf

    2. conf 파일 수정

      Untitled

      Untitled

    3. redis server 띄우기

      redis-server ./redis-7000.conf

      Untitled

    4. 7000 ~ 7005 반복

      Untitled

      → 로컬 머신에서 6개의 redis 노드가 돌아가고 있는 상태 (cluster 모드)

  3. cluster 구성하기

    redis-cli --cluster create localhost:7000 localhost:7001 localhost:7002 localhost:7003 localhost:7004 localhost:7005 --cluster-replicas 1

    Untitled

  4. cluster 사용하기

    1. 7000 접속

      redis-cli -p 7000

      127.0.0.1:7000> cluster nodes

      Untitled

    2. aa key 로 세팅 → 성공

    3. aaa key로 세팅 → 실패 → 7001에 해야함

      Untitled

    4. 7001 접속하여 세팅 → 성공

      Untitled

    5. replica 확인

      7001의 node Id를 replicate하고 있는 slave는 7004임 (3. 이미지에서 확인 가능)

    6. 7004에 접속하여 get, set 명령어 수행

      Untitled

      : 모두 master에서 수행하도록 함

    7. readonly 명령어로 값을 가져오게 할 수 있음

      Untitled

  5. fail-over 수행해보기

    1. 7001 노드 종료시키기 (Control + C)

      Untitled

    2. 아무 노드 들어가서 노드 정보 확인해보기

      Untitled

      : 7001가 fail되어 slave였던 7004가 master가 됨

    3. 7001이 담당하던 hash slot들을 7004가 담당하게 됨

      Untitled

  6. 7001 노드 되살리기

    1. redis-server ./redis-7001.conf

    2. 노드 정보 확인

      Untitled

      : 7001은 이제 slave가 됨

  7. 추가 노드 생성

    mkdir 7006

    cp redis.conf 7006/redis-7006.conf

    redis-server ./redis-7006.conf

    Untitled

  8. cluster에 노드 추가하기

    redis-cli --cluster add-node localhost:7006 localhost:7000

    add-node의 두 번째 인자에는 기존 cluster의 아무 노드나 명시하면 됨

    Untitled