개발 기록

> [Redis] Spring Boot 3 Redis Sentinel 환경 구성 및 구현 - 1. Sentinel 개념, Master-Replica-sentinel Node 구축 본문

SQL&NoSQL

> [Redis] Spring Boot 3 Redis Sentinel 환경 구성 및 구현 - 1. Sentinel 개념, Master-Replica-sentinel Node 구축

1z 2024. 1. 8. 17:50

 

 

1. Redis Sentinel 란? 

 

Redis 가 제공하는 고가용성 솔루션이다. Redis 클러스터에 장애가 발생하는 경우 Sentinel은 장애 지점을 자동으로 감지하고 사람의 개입 없이 클러스터를 다시 안정 모드로 되돌린다. 즉, Redis Sentinel은 사람의 개입 없이 Redis 배포에 저항할 수 있는 시스템.

sentinel , master, replica 로 구성  

master :데이터 읽기와 쓰기가 모두 가능

replica : 기본적으로 데이터를 읽을 수 있고, 인식할 수 없다.  Master로부터의 데이터를 수락
sentinel : 모니터링, 알림, 자동 장애 조치, 구성 공급

레디스 센티넬은 레디스 서버들(마스터와 레플리카)을 관리하며, 마스터가 서비스 할 수 없는 상태면   replica를 마스터 서버로 변경한다. 
과반수 이상의 Sentinel이 동의(Quorum based)가 있어야 Failover 진행 (Sentinel  최소 3개 이상, 홀수 권장)

 

HA( High Availability )

- 가용성: 서버와 네트워크 또는 프로그램 등의 다양한 시스템이 원격으로 사용 가능한 정도를 의미한다.

- 고가용성 : 시스템에 장애가 발생하더라도 찰나의 순간에 감지하고 복구하거나 미리 백업된 시스템이 재사용되어 사용자에게 연결적인 서비스를 제공하게 하는 것을 의미한다.

 


 

2. Redis Master + Replica 구성 

 

 

1.  Master Node 설정

$ cp redis.conf redis_6379.conf
$ vim redis_6379.conf
# redis_6379.conf for MASTER
port 6379
daemonize yes
logfile logs/redis_6379.log
requirepass asdf

 

 

2. Replica Redis 설정

$ cp redis.conf redis_6380.conf
$ vim redis_6380.conf
# redis_6380.conf for REPLICA
port 6380
daemonize yes
logfile logs/redis_6380.log
requirepass asdf
replicaof 127.0.0.1 6379
masterauth asdf

 

3. 실행 

$ src/redis-server redis_6379.conf
$ src/redis-server redis_6380.conf

 

 

4. node 정보 확인

--row : 한글 인코딩 옵션

1. master

$ src/redis-cli -h 127.0.0.1 -p 6379
$ auth asdf

 

 

2. replica

$ src/redis-cli -h 127.0.0.1 -p 6380
$ auth asdf

 

 

2. Sentinel 구성

$ cp sentinel.conf sentinel_{portNo}.conf
$ vim sentinel_{portNo}.conf

 

2. 설정파일 변경

 

* 기타 속성 

protected-mode Redis를 보호하기 위한 모드.
이 옵션의 영향을 받는 옵션이 없을 경우 localhost만 접속을 허용.
bind  요청을 수락할 IP를 명시.
protected-mode가 yes일 경우 localhost 외에는 명시적으로 IP를 입력해야 함.
appendfilename dir 경로에 저장될 aof파일의 이름을 지정

 

# port
port {port}

# Redis를 데몬 프로세스로 동작할 지 선택
daemonize yes 

# log를 저장할 파일의 경로와 파일 이름을 지정
logfile "/var/log/redis/redis-sentinel_{port}.log"

# Redis의 db 파일과 appendonly파일의 경로를 지정
dir "/home/{user}/redis"

sentinel monitor mymaster 127.0.0.1 6379 2 # 여기서 마지막 2는 quorum 값 지정
sentinel down-after-milliseconds mymaster 3000

# master pwd
sentinel auth-pass mymaster asdf

 

3. 실행

$ src/redis-sentinel sentinel_5000.conf
$ src/redis-sentinel sentinel_5001.conf
$ src/redis-sentinel sentinel_5002.conf

 

 

 

 

 

 

 

 

 

참고

https://medium.com/javarevisited/caching-with-spring-boot-3-lettuce-and-redis-sentinel-5f6fab7e58f8

https://velog.io/@bambookim/Redis-Replication-with-Sentinel