우선 저는 master node 3개, slave node 3개로 해서 redis cluster를 구성할 계획입니다.
일단, docker-compose.yaml 파일을 소개해드리겠습니다
🔨 docker-compose.yaml
version: '3'
services:
redis-master-1:
container_name: redis-master-1
image: redis:6.2.3
command: redis-server /etc/redis.conf
volumes:
- ./redis-master-1.conf:/etc/redis.conf
restart: always
ports:
- 7001:7001
- 17001:17001
redis-master-2:
container_name: redis-master-2
image: redis:6.2.3
command: redis-server /etc/redis.conf
volumes:
- ./redis-master-2.conf:/etc/redis.conf
restart: always
ports:
- 7002:7002
- 17002:17002
redis-master-3:
container_name: redis-master-3
image: redis:6.2.3
command: redis-server /etc/redis.conf
volumes:
- ./redis-master-3.conf:/etc/redis.conf
restart: always
ports:
- 7003:7003
- 17003:17003
redis-slave-1:
container_name: redis-slave-1
image: redis:6.2.3
command: redis-server /etc/redis.conf
volumes:
- ./redis-slave-1.conf:/etc/redis.conf
restart: always
ports:
- 7004:7004
- 17004:17004
redis-slave-2:
container_name: redis-slave-2
image: redis:6.2.3
command: redis-server /etc/redis.conf
volumes:
- ./redis-slave-2.conf:/etc/redis.conf
restart: always
ports:
- 7005:7005
- 17005:17005
redis-slave-3:
container_name: redis-slave-3
image: redis:6.2.3
command: redis-server /etc/redis.conf
volumes:
- ./redis-slave-3.conf:/etc/redis.conf
restart: always
ports:
- 7006:7006
- 17006:17006
여기서 각 master는 7001~7003번으로 할당하였고, 각 slave는 7004~7006번으로 할당하였습니다.
그리고 각각의 설정파일을 루트폴더에 같이 넣어줍니다.
🔨 redis-master-1.conf
port 7001
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 3000
appendonly yes
bind 0.0.0.0
cluster-announce-ip [Your Server IP]
여기서 각각마다 파일 이름을 변경해가며 port만 바꿔주면됩니다.
우선 docker, docker-compose를 설치한 뒤, 아래의 커맨드를 이용해 실행합니다
🔨 명령어
$ sudo docker-compose up -d
# 성태 확인
$ sudo docker container list # or, enter the "docker ps -a"
🔨 결과
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a82090d275d9 redis:6.2.3 "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 0.0.0.0:7005->7005/tcp, :::7005->7005/tcp, 6379/tcp, 0.0.0.0:17005->17005/tcp, :::17005->17005/tcp redis-slave-2
a67dbc2851f5 redis:6.2.3 "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 0.0.0.0:7003->7003/tcp, :::7003->7003/tcp, 6379/tcp, 0.0.0.0:17003->17003/tcp, :::17003->17003/tcp redis-master-3
048342623a20 redis:6.2.3 "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 0.0.0.0:7006->7006/tcp, :::7006->7006/tcp, 6379/tcp, 0.0.0.0:17006->17006/tcp, :::17006->17006/tcp redis-slave-3
0656ab24599a redis:6.2.3 "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 0.0.0.0:7001->7001/tcp, :::7001->7001/tcp, 6379/tcp, 0.0.0.0:17001->17001/tcp, :::17001->17001/tcp redis-master-1
4d6d103c6651 redis:6.2.3 "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 0.0.0.0:7002->7002/tcp, :::7002->7002/tcp, 6379/tcp, 0.0.0.0:17002->17002/tcp, :::17002->17002/tcp redis-master-2
45f6714613e0 redis:6.2.3 "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 0.0.0.0:7004->7004/tcp, :::7004->7004/tcp, 6379/tcp, 0.0.0.0:17004->17004/tcp, :::17004->17004/tcp redis-slave-1
그 다음에 redis container에 접속해서 클러스터를 생성해줍시다
🔨 커맨드
# redis container에 접속
$ sudo docker exec -it redis-master-1 bash
# 클러스터 생성 커맨드
$ redis-cli --cluster create [public IP]:7001 [public IP]:7002 [public IP]:7003 \
[public IP]:7004 [public IP]:7005 [public IP]:7006 \
--cluster-replicas 1
🔨 결과
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica [public IP]:7005 to [public IP]:7001
Adding replica [public IP]:7006 to [public IP]:7002
Adding replica [public IP]:7004 to [public IP]:7003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 19cb61048d943cfe358807d268c7526b62225e00 [public IP]:7001
slots:[0-5460] (5461 slots) master
M: 6253cb11bc85b1b14c2a30348c98b7ef870199fe [public IP]:7002
slots:[5461-10922] (5462 slots) master
M: 42ef61c80dd8c0dfe6e992e8ede0f7efb9d1d7ea [public IP]:7003
slots:[10923-16383] (5461 slots) master
S: 5a467eaec7f55b67231abb4a84ea8fc4a00a7664 [public IP]:7004
replicates 19cb61048d943cfe358807d268c7526b62225e00
S: c8472a1713fbd21275c14142e75d034598090ab1 [public IP]:7005
replicates 6253cb11bc85b1b14c2a30348c98b7ef870199fe
S: 226ec80769946caf681ce5db37ad3eec0ab2095b [public IP]:7006
replicates 42ef61c80dd8c0dfe6e992e8ede0f7efb9d1d7ea
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
.
>>> Performing Cluster Check (using node [public IP]:7001)
M: 19cb61048d943cfe358807d268c7526b62225e00 [public IP]:7001
slots:[0-5460] (5461 slots) master
1 additional replica(s)
M: 6253cb11bc85b1b14c2a30348c98b7ef870199fe [public IP]:7002
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 5a467eaec7f55b67231abb4a84ea8fc4a00a7664 [public IP]:7004
slots: (0 slots) slave
replicates 19cb61048d943cfe358807d268c7526b62225e00
S: 226ec80769946caf681ce5db37ad3eec0ab2095b [public IP]:7006
slots: (0 slots) slave
replicates 42ef61c80dd8c0dfe6e992e8ede0f7efb9d1d7ea
M: 42ef61c80dd8c0dfe6e992e8ede0f7efb9d1d7ea [public IP]:7003
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: c8472a1713fbd21275c14142e75d034598090ab1 [public IP]:7005
slots: (0 slots) slave
replicates 6253cb11bc85b1b14c2a30348c98b7ef870199fe
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
datagrip이나 dbeaver 와 같은툴에서는 어떻게 붙을 수 있나요?
redis-cli --cluster create [public IP]:7001 [public IP]:7002 [public IP]:7003 \
[public IP]:7004 [public IP]:7005 [public IP]:7006 \
--cluster-replicas 1
명령어에서 public IP 부분에는 어떤값을 넣어야 하는지 알수있을까용?