클러스터 설정 파일
cluster-enabled <yes/no>
cluster-config-file <filename>
cluster-node-timeout <milliseconds>
cluster-replica-validity-factor <factor>
cluster-migration-barrier <count>
cluster-require-full-coverage <yes/no>
cluster-allow-reads-when-down <yes/no>
클러스터가 정상 상태가 아닐 때도 read 요청은 받도록 할지 여부 (default: no)
어플리케이션에서 read 동작의 consistency가 중요치 않은 경우에 yes로 설정할 수 있다.
→ 일관성보다 가용성이 중요한 경우에 사용
레디스 설치
brew install redis
클러스터로 돌아갈 노드를 미리 띄우기 - master 3개, replica 3개
directory 생성
mkdir 7000
cp redis.conf 7000/redis-7000.conf
conf 파일 수정
redis server 띄우기
redis-server ./redis-7000.conf
7000 ~ 7005 반복
→ 로컬 머신에서 6개의 redis 노드가 돌아가고 있는 상태 (cluster 모드)
cluster 구성하기
redis-cli --cluster create localhost:7000 localhost:7001 localhost:7002 localhost:7003 localhost:7004 localhost:7005 --cluster-replicas 1
cluster 사용하기
7000 접속
redis-cli -p 7000
127.0.0.1:7000> cluster nodes
aa key 로 세팅 → 성공
aaa key로 세팅 → 실패 → 7001에 해야함
7001 접속하여 세팅 → 성공
replica 확인
7001의 node Id를 replicate하고 있는 slave는 7004임 (3. 이미지에서 확인 가능)
7004에 접속하여 get
, set
명령어 수행
: 모두 master에서 수행하도록 함
readonly
명령어로 값을 가져오게 할 수 있음
fail-over 수행해보기
7001 노드 종료시키기 (Control + C)
아무 노드 들어가서 노드 정보 확인해보기
: 7001가 fail되어 slave였던 7004가 master가 됨
7001이 담당하던 hash slot들을 7004가 담당하게 됨
7001 노드 되살리기
redis-server ./redis-7001.conf
노드 정보 확인
: 7001은 이제 slave가 됨
추가 노드 생성
mkdir 7006
cp redis.conf 7006/redis-7006.conf
redis-server ./redis-7006.conf
cluster에 노드 추가하기
redis-cli --cluster add-node localhost:7006 localhost:7000
add-node의 두 번째 인자에는 기존 cluster의 아무 노드나 명시하면 됨