본문 바로가기

리눅스

Docker를 사용하여 Redis 클러스터(predixy)를 설정하는 구성하는 방법

728x90

Docker를 사용하여 Redis 클러스터(predixy)를 설정하는 구성하는 방법

구성도

r1

predixy, redis-cluster 컨테이너로 구성

git clone

git clone https://github.com/anti1346/predixy-redis-cluster.git

레디스 네트워크 생성

docker network create --gateway 172.24.0.1 --subnet 172.24.0.0/16 redis-net

docker-compose up

cd predixy-redis-cluster
docker-compose up -d

로그 출력

docker-compose logs -f

레디스 클러스터 정보

(predixy) redis info

redis-cli -h localhost -c -p 7617 info
$ redis-cli -h localhost -c -p 7617 info
# Proxy
Version:1.0.4
Name:PredixyExample
Bind:0.0.0.0:7617
RedisMode:proxy
SingleThread:false
WorkerThreads:4
Uptime:1672207194
UptimeSince:2022-12-28 14:59:54

# SystemResource
UsedMemory:322264
MaxMemory:0
MaxRSS:6922240
UsedCpuSys:4.975
UsedCpuUser:1.819

# Stats
Accept:10
ClientConnections:1
TotalRequests:4411
TotalResponses:4410
TotalRecvClientBytes:322
TotalSendServerBytes:122459
TotalRecvServerBytes:5112904
TotalSendClientBytes:9410

# Servers
Server:172.24.0.11:6379
Role:master
Group:05baedca03d9e79de84cacd955fcafcca0a90343
DC:
CurrentIsFail:0
Connections:4
Connect:4
Requests:497
Responses:497
SendBytes:13803
RecvBytes:569196

Server:172.24.0.12:6379
Role:master
Group:a45d36d8d19b27aaa3b0736249f72aec601d30e4
DC:
CurrentIsFail:0
Connections:4
Connect:4
Requests:462
Responses:462
SendBytes:12840
RecvBytes:534817

Server:172.24.0.13:6379
Role:master
Group:08c71d79b8998af23a455c40003454a3157d20b4
DC:
CurrentIsFail:0
Connections:4
Connect:4
Requests:513
Responses:513
SendBytes:14268
RecvBytes:597463

Server:172.24.0.14:6379
Role:slave
Group:08c71d79b8998af23a455c40003454a3157d20b4
DC:
CurrentIsFail:0
Connections:4
Connect:4
Requests:493
Responses:493
SendBytes:13708
RecvBytes:573827

Server:172.24.0.15:6379
Role:slave
Group:05baedca03d9e79de84cacd955fcafcca0a90343
DC:
CurrentIsFail:0
Connections:4
Connect:4
Requests:470
Responses:470
SendBytes:13064
RecvBytes:546594

Server:172.24.0.16:6379
Role:slave
Group:05baedca03d9e79de84cacd955fcafcca0a90343
DC:
CurrentIsFail:0
Connections:4
Connect:4
Requests:503
Responses:503
SendBytes:13988
RecvBytes:585633

Server:172.24.0.17:6379
Role:slave
Group:a45d36d8d19b27aaa3b0736249f72aec601d30e4
DC:
CurrentIsFail:0
Connections:4
Connect:4
Requests:487
Responses:487
SendBytes:13540
RecvBytes:566138

Server:172.24.0.18:6379
Role:slave
Group:a45d36d8d19b27aaa3b0736249f72aec601d30e4
DC:
CurrentIsFail:0
Connections:4
Connect:4
Requests:493
Responses:493
SendBytes:13708
RecvBytes:573622

Server:172.24.0.19:6379
Role:slave
Group:08c71d79b8998af23a455c40003454a3157d20b4
DC:
CurrentIsFail:0
Connections:4
Connect:4
Requests:487
Responses:487
SendBytes:13540
RecvBytes:565614


# LatencyMonitor
LatencyMonitorName:all
<=          100                  207                3 21.43%
<=          200                  241                2 35.71%
<=          300                 1360                5 71.43%
<=          400                  706                2 85.71%
<=          500                  465                1 92.86%
<=          700                  644                1 100.00%
T           258                 3623               14

LatencyMonitorName:get
<=          300                 1360                5 71.43%
<=          400                  706                2 100.00%
T           295                 2066                7

LatencyMonitorName:set
<=          500                  465                1 50.00%
<=          700                  644                1 100.00%
T           554                 1109                2

LatencyMonitorName:blist
728x90

(nodes) redis cluster info

docker exec -it node1 redis-cli cluster info
$ docker exec -it node1 redis-cli cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:9
cluster_size:3
cluster_current_epoch:9
cluster_my_epoch:1
cluster_stats_messages_ping_sent:16552
cluster_stats_messages_pong_sent:16600
cluster_stats_messages_sent:33152
cluster_stats_messages_ping_received:16592
cluster_stats_messages_pong_received:16552
cluster_stats_messages_meet_received:8
cluster_stats_messages_received:33152

(nodes) redis cluster nodes

docker exec -it node1 redis-cli cluster nodes | sort -k2

docker exec -it node1 redis-cli cluster nodes | sort -k7

predixy를 통한 데이터 입출력

redis-cli -c -h 127.0.0.1 -p 7617 set hello world
$ redis-cli -c -h 127.0.0.1 -p 7617 set hello world
OK
redis-cli -c -h 127.0.0.1 -p 7617 get hello
$ redis-cli -c -h 127.0.0.1 -p 7617 get hello
"world"
redis-cli -c -h 127.0.0.1 -p 7617 set hey mister
$ redis-cli -c -h 127.0.0.1 -p 7617 set hey mister
OK
redis-cli -c -h 127.0.0.1 -p 7617 get hey
$ redis-cli -c -h 127.0.0.1 -p 7617 get hey
"mister"

컨테이너를 통한 데이터 조회

docker exec -it node1 redis-cli -c get hello
$ docker exec -it node1 redis-cli -c get hello
"world"
docker exec -it node1 bash
$ docker exec -it node1 bash
root@node1:/data$ redis-cli -c
127.0.0.1:6379> get hello
"world"
127.0.0.1:6379>
docker exec -it node2 bash
$ docker exec -it node2 bash
root@node2:/data$ redis-cli -c
127.0.0.1:6379> get hello
-> Redirected to slot [866] located at 172.24.0.11:6379
"world"
172.24.0.11:6379>

 

참고URL

- 레디스 클러스터 설정(redis cluster setup) : https://scbyun.com/1369

 

728x90