CLOUD/IaC

[Redis] Master - Slave

alsruds 2023. 3. 24. 16:43

◎ 가상머신 2대 준비 CentOS 8

→ Master : 200.200.200.134

Slave : 200.200.200.135

 

 

[ 공통 설정 ]

● 설치 + 설정

# 설치
yum -y install redis

# 파일 설정
vi /etc/redis.conf
	# 69번 라인 : bind 0.0.0.0
    
# 재시작
systemctl restart redis

 

 

[ Master 설정 ]

/etc/redis.conf  파일 설정 (주석 해제)

daemonize yes			# daemon process 로 동작
min-replicas-to-write 1		# 최소 복제본 수
min-replicas-max-lag 10		# 복제 성공 시간
requirepass [password]		# 패스워드 설정

 

● 재시작

systemctl restart redis

 

 

[ Slave 설정 ]

 /etc/redis.conf  파일 설정 (주석 해제)

daemonize yes	
replicaof [master ip] [port]	# redis port = 6379
masterauth [master password]
replica-read-only yes

 

● 재시작

systemctl restart redis

 

 

☞ 확인 ☜

① Redis 정보로 확인

》 Redis 접속

info Replication 입력 시 정보 출력

master

 

slave

 

② Django 에서 로그인 해보기

》 settings.py 수정

SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
CACHES = {
	'default': {
		'BACKEND': 'django.core.cache.backends.redis.RedisCache',
		'LOCATION': 'redis://redis:[master password]@[master ip]:6379',
	}
}

 

》 로그인 기능 수행

 

Redis Master 서버 Cache 확인

master

 

Redis Slave 서버 Cache 확인

slave