[Practice] Redis Replication (Master-Slave)

2020. 10. 8. 17:49Database/Practice

1. Replication (Master-Slave)

1) VMware 설정

VMware IP
Redis Master 192.168.94.10
Redis Slave 192.168.94.20

2) Master 구성

// CentOS 6 epel 설치
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

// Redis 설치 
yum install redis

// CentOS 6 자동 실행 
chkconfig redis on 
service redis start

테스트용으로 구성하기 때문에 모든 IP 대역을 허용하도록 하고 Redis의 비밀번호와 Master 서버 동기화 주기 설정의 주석을 해제한다.

bind 0.0.0.0
requirepass test1234
masterauth test1234

repl-ping-slave-period 10
repl-timeout 60

※ Redis 설치 과정에서 'Cannot retrieve repository metadata (repomd.xml) for repository: epel. Please verify its path and try again' 에러가 발생할 경우, '/etc/yum.repos.d/epel.repo'의 mirrorlist를 주석처리하고 baseurl을 활성화를 해야한다. (enable=1)

3) Slave 구성

// CentOS 6 epel 설치
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

// Redis 설치 
yum install redis

// CentOS 6 자동 실행 
chkconfig redis on 
service redis start
bind 0.0.0.0
requirepass test1234
slaveof 192.168.94.10 6379
masterauth test1234

repl-ping-slave-period 10
repl-timeout 60

4) Replication 확인

Redis Master 서비스를 멈추고 다시 재시작하고 Master와 Slave의 Redis 로그를 확인한다. Master에서는 Slave와의 Sync 로그를 확인할 수 있고, Slave에서는 Sync가 정상적으로 완료되었다는 로그를 확인할 수 있다.

tail -n 16 /var/log/redis/redis.log

Replication 확인

5) Replication 테스트

Redis Master에서 데이터를 넣고 Slave 측에서 데이터를 확인한다.

redis-cli -a test1234

// Master
127.0.0.1:6379> set test "testing"

// Slave
127.0.0.1:6379> get test

Replication 테스트


[참고] crystalcube.co.kr/176?category=665742

[참고] ossian.tistory.com/37

728x90

'Database > Practice' 카테고리의 다른 글

[Practice] Redis Cluster  (0) 2020.10.08
[Practice] Redis Sentinel  (0) 2020.10.08
[Practice] 트리거  (0) 2020.09.30
[Practice] 저장 프로시저, 저장 함수  (0) 2020.09.30