프로그램/LINUX

[Redis] 레디스 클러스터 세팅 및 설정하기 (redis cluster)

프뚜 2023. 1. 8. 10:00
728x90
반응형
SMALL

안녕하세요! 프뚜입니다.

새해 복 많이 받으세요 !

 

우분투에 redis 설치하는 방법은 링크를 통해 참고하시면 됩니다.

Redis 3개를 Cluster 구성을 합니다.

Redis7000은 port 7000을 사용하고 있습니다. Slot은 0에서 5460을 사용합니다.

Redis7001은 port 7001을 사용하고 있습니다. Slot은 5461에서 10922을 사용합니다.

Redis7002은 port 7002을 사용하고 있습니다. Slot은 10923에서 16383을 사용합니다.

 


[개발환경]

 - OS: Ubuntu 22.04.1 LTS


# redis.conf를 복사해서 redis-7000.conf 생성하기

# 2023.01.03[프뚜]: 모든 IP 접속 허용
bind 0.0.0.0 ::1

# 2023.01.03[프뚜]: 접속 PORT 지정
port 7000

# 2023.01.03[프뚜]: 클러스터 여부
cluster-enabled yes

# 2023.01.03[프뚜]: conf
cluster-config-file nodes_7000.conf

# 2023.01.03[프뚜]: 클러스터 timeout
cluster-node-timeout 3000

# 2023.01.03[프뚜]: cluster 일부가 다운했을 때, 운영 여부
cluster-require-full-coverage no

/etc/redis/redis.conf 파일을 복사해서 /etc/redis/redis-7000.conf를 생성합니다. 위 내용을 찾아서 주석 해제 및 내용 수정을 합니다. 


# redis.conf를 복사해서 redis-7001.conf 생성하기

# 2023.01.03[프뚜]: 모든 IP 접속 허용
bind 0.0.0.0 ::1

# 2023.01.03[프뚜]: 접속 PORT 지정
port 7001

# 2023.01.03[프뚜]: 클러스터 여부
cluster-enabled yes

# 2023.01.03[프뚜]: conf
cluster-config-file nodes_7001.conf

# 2023.01.03[프뚜]: 클러스터 timeout
cluster-node-timeout 3000

# 2023.01.03[프뚜]: cluster 일부가 다운했을 때, 운영 여부
cluster-require-full-coverage no

/etc/redis/redis.conf 파일을 복사해서 /etc/redis/redis-7001.conf를 생성합니다. 위 내용을 찾아서 주석 해제 및 내용 수정을 합니다. 


# redis.conf를 복사해서 redis-7002.conf 생성하기

# 2023.01.03[프뚜]: 모든 IP 접속 허용
bind 0.0.0.0 ::1

# 2023.01.03[프뚜]: 접속 PORT 지정
port 7002

# 2023.01.03[프뚜]: 클러스터 여부
cluster-enabled yes

# 2023.01.03[프뚜]: conf
cluster-config-file nodes_7002.conf

# 2023.01.03[프뚜]: 클러스터 timeout
cluster-node-timeout 3000

# 2023.01.03[프뚜]: cluster 일부가 다운했을 때, 운영 여부
cluster-require-full-coverage no

/etc/redis/redis.conf 파일을 복사해서 /etc/redis/redis-7002.conf를 생성합니다. 위 내용을 찾아서 주석 해제 및 내용 수정을 합니다. 


# Redis(7000, 7001, 7002) 구동하기

redis-server redis-7000.conf
redis-server redis-7001.conf
redis-server redis-7002.conf

 

redis 3개가 [cluster]로 구동됨을 확인할 수 있습니다.


# Redis cluster 연결하기

redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002


# Cluster Info 확인하기

# 2023.01.03[프뚜]: -c는 클러스터로 접속, -p는 port 번호
redis-cli -c -p 7000

cluster info

cluster_state: 클러스터가 정상인 상태입니다.
cluster_slots_assigned: 클러스터에 할당된 슬롯 개수 입니다.
cluster_slots_ok: 현재 구동된 클러스터에 할당된 슬롯 개수 입니다. (특정 노드 다운 시, 해당 노드의 슬롯 개수가 빠지게 됩니다.)
cluster_slots_fail: 인식하지 못하는 슬롯 개수입니다.
cluster_known_nodes: 클러스터에 구성된 모든 노드 수 입니다.
cluster_size: 클러스터 마스터 노드 수 입니다.


# Cluster 테스트하기

# 2023.01.03[프뚜]: -c는 클러스터로 접속, -p는 port 번호
redis-cli -c -p 7000

 

 

Redis7000에서 tistory(ssjeong) key를 추가합니다.

 

 

tistory라는 key는 8018 slot에 저장되었으며, 8018 slot은 Redis7001이기때문에 Redis7001으로 이동됨을 확인할 수 있습니다.

 

 

Redis7000에서 tistory key를 조회하면 8018 slot에 있는 Redis7001에 조회됨을 확인할 수 있습니다.


클러스터 세팅이 완료되었습니다. 현재 master로 클러스터링을 구성했기 때문에 백업 서버(replica)를 구성해야합니다. 다음 포스팅에는 레플리카(replica) 세팅을 포스팅하겠습니다.

 

docker pull ghcr.io/jeongseongsoo/redis:1.0

https://github.com/users/JeongSeongSoo/packages/container/package/redis

728x90
반응형
LIST