Install

์ •์˜

  • Remote Dictionary Server์˜ ์•ฝ์ž๋กœ, ๋ฉ”๋ชจ๋ฆฌ ๊ธฐ๋ฐ˜์˜ key-value ๊ตฌ์กฐ ๋ฐ์ดํ„ฐ ๊ด€๋ฆฌ ์‹œ์Šคํ…œ์ด๋‹ค.

  • ์˜คํ”ˆ์†Œ์Šค์ด๋ฉฐ, ์†๋„๊ฐ€ ๋น ๋ฅด๋‹ค๋Š” ์žฅ์ ์ด ์žˆ๋‹ค.

ํƒ€์ž…

  • Redis

    • 1 main node : no redundancy

    • replication (main-secondary) : 1 main node + 1 or more secondary node

  • Redis Sentinel

    • 1 main node + 1 or more secondary node + 3 or more sentinel node

  • Redis Cluster

    • 3 or more main node + 3 or more secondary node with replication

https://architecturenotes.co/content/images/size/w2400/2022/08/Redis-v2-01-1.jpg

alt text

Redis ์„ค์น˜

์ฃผ์˜ : redis docker image๋Š” ์œ ๋ช…ํ•œ๊ฒƒ์ด 2๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.

๋‘˜๋‹ค ์จ๋„ ๋ฌด๋ฐฉํ•˜๋‹ค.

  • redis๋Š” ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ์ง€์›์„ ์•ˆํ•˜๊ณ  conf ํŒŒ์ผ์„ ์ง€์›ํ•œ๋‹ค.

  • bitnami/redis๋Š” ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ์ง€์›ํ•œ๋‹ค.

bitnami/redis๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๋ฒ„์ „์€ ๋‹ค์Œ์—์„œ ์ฐพ์„์ˆ˜ ์žˆ๋‹ค. https://hub.docker.com/r/bitnami/redis/tags

single main node

cd redis/single-node

cat > docker-compose.yaml <<EOF
version: '3'
services:
  redis:
    image: 'bitnami/redis:7.2'
    container_name: redis
    ports:
      - 6379:6379
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
EOF

docker-compose up -d

docker ps -a
# test
docker run -it --rm bitnami/redis:7.2 redis-cli -h host.docker.internal

set mykey myvalue
> OK

get mykey
> "myvalue"

๋™์ž‘ํ™•์ธ๋ซ๋‹ค ์ด๋ฐฉ์‹์€ redundancy๊ฐ€ ์—†๋‹ค. ๊ทธ๋ฆฌ๊ณ  ํŠธ๋ž˜ํ”ฝ์ด ๋งŽ์•„์ง€๋ฉด 1๊ฐœ์˜ ์„œ๋ฒ„๊ฐ€ ๋ชจ๋“  ํŠธ๋ž˜ํ”ฝ์„ ๋ฐ›์•„์•ผํ•œ๋‹ค. ๊ทธ๋ž˜์„œ replication์„ ์‚ฌ์šฉํ•œ๋‹ค.

replication (main-secondary)

cd replica-multi-node
cat > docker-compose.yaml <<EOF
version: '3'
services:
  redis-main:
    image: 'bitnami/redis:7.2'
    container_name: redis-main
    hostname: redis-main
    ports:
      - 6379:6379
    environment:
      - REDIS_REPLICATION_MODE=main
      - ALLOW_EMPTY_PASSWORD=yes

  redis-replica:
    image: 'bitnami/redis:7.2'
    deploy:
      replicas: 2
    depends_on:
      - redis-main
    environment:
      - REDIS_REPLICATION_MODE=Secondary
      - ALLOW_EMPTY_PASSWORD=yes
EOF

docker-compose up -d

docker ps
alt text
# test
docker run -it --rm bitnami/redis:7.2 redis-cli -h host.docker.internal #access to main
alt text

์ด์ œ replica-1์—์„œ ํ™•์ธํ•ด๋ณด์ž.

docker exec -it replica-multi-node-redis-replica-1 redis-cli  # access to replica-1

get mykey
> "myvalue"

๋งˆ์Šคํ„ฐ์—์„œ ์ž…๋ ฅํ•œ ๊ฐ’์„ Secondary๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.

ํ”„๋กœ๊ทธ๋žจ์€ Secondary ์—ฐ๊ฒฐํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ๊ฐˆ์ˆ˜ ์žˆ๋‹ค.

๋ฐ์ดํ„ฐ์˜ ๋ณต์ œ๊ฐ€ ์ž‡์–ด์„œ ํ•œ๋…ธ๋“œ๊ฐ€ ๋ง๊ฐ€์ง€๋”๋ผ๋„ ๋ฐ์ดํ„ฐ๊ฐ€ ์œ ์‹ค๋˜์ง€ ์•Š๋Š”๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ˆ˜๋™์œผ๋กœ main๋ฅผ ๋ณ€๊ฒฝํ•ด์•ผํ•œ๋‹ค. ์ด๊ฑธ ์ž๋™์œผ๋กœ ํ•ด์ฃผ๋Š” ๊ฒƒ์ด Redis Sentinel์ด๋‹ค.

Redis Sentinel ์„ค์น˜

cd sentinel
cat > docker-compose.yaml <<EOF

EOF

docker-compose up -d

docker ps
alt text

ํ™•์ธํ•ด๋ณด์ž.

docker exec -it replica-multi-node-sentinel-redis-sentinel-1 redis-cli -p 26379

info sentinel

>
# Sentinel
sentinel_mains:1
sentinel_tilt:0
sentinel_tilt_since_seconds:-1
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
main0:name=mymain,status=ok,address=192.168.128.2:6379,Secondarys=2,sentinels=3

Redis Cluster ์„ค์น˜

cd redis-cluster
cat > docker-compose.yaml <<EOF
version: '3'
services:
  redis-node-0:
    image: 'bitnami/redis-cluster:7.2'
    container_name: redis-node-0
    ports:
      - 6371:6379
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

  redis-node-1:
    image: 'bitnami/redis-cluster:7.2'
    container_name: redis-node-1
    ports:
      - 6372:6379
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

  redis-node-2:
    image: 'bitnami/redis-cluster:7.2'
    container_name: redis-node-2
    ports:
      - 6373:6379
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

  redis-node-3:
    image: 'bitnami/redis-cluster:7.2'
    container_name: redis-node-3
    ports:
      - 6374:6379
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

  redis-node-4:
    image: 'bitnami/redis-cluster:7.2'
    container_name: redis-node-4
    ports:
      - 6375:6379
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

  redis-node-5:
    image: 'bitnami/redis-cluster:7.2'
    container_name: redis-node-5
    ports:
      - 6379:6379
    depends_on:
      - redis-node-0
      - redis-node-1
      - redis-node-2
      - redis-node-3
      - redis-node-4
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
      - REDIS_CLUSTER_REPLICAS=1
      - REDIS_CLUSTER_CREATOR=yes
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
EOF

docker-compose up -d

docker ps -a
alt text
# test
docker exec -it redis-node-1 redis-cli -c -p 6379 #cluster์ ‘์†์‹œ -c ์˜ต์…˜ ์‚ฌ์šฉ

cluster info

>
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:2
cluster_stats_messages_ping_sent:228
cluster_stats_messages_pong_sent:227
cluster_stats_messages_meet_sent:1
cluster_stats_messages_sent:456
cluster_stats_messages_ping_received:227
cluster_stats_messages_pong_received:229
cluster_stats_messages_received:456
total_cluster_links_buffer_limit_exceeded:0

3 master ์™€ 3 secondary๋กœ ๊ตฌ์„ฑ๋˜์—ˆ๋‹ค.

alt text

cluster_state : ํด๋Ÿฌ์Šคํ„ฐ๊ฐ€ ์ •์ƒ์ธ ์ƒํƒœ์ž…๋‹ˆ๋‹ค. cluster_slots_assigned : ํด๋Ÿฌ์Šคํ„ฐ์— ํ• ๋‹น๋œ ์Šฌ๋กฏ ๊ฐœ์ˆ˜ ์ž…๋‹ˆ๋‹ค. cluster_slots_ok : ํ˜„์žฌ ๊ตฌ๋™๋œ ํด๋Ÿฌ์Šคํ„ฐ์— ํ• ๋‹น๋œ ์Šฌ๋กฏ ๊ฐœ์ˆ˜ ์ž…๋‹ˆ๋‹ค. (ํŠน์ • ๋…ธ๋“œ ๋‹ค์šด ์‹œ, ํ•ด๋‹น ๋…ธ๋“œ์˜ ์Šฌ๋กฏ ๊ฐœ์ˆ˜๊ฐ€ ๋น ์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.) cluster_slots_fail : ์ธ์‹ํ•˜์ง€ ๋ชปํ•˜๋Š” ์Šฌ๋กฏ ๊ฐœ์ˆ˜์ž…๋‹ˆ๋‹ค. cluster_known_nodes : ํด๋Ÿฌ์Šคํ„ฐ์— ๊ตฌ์„ฑ๋œ ๋ชจ๋“  ๋…ธ๋“œ ์ˆ˜ ์ž…๋‹ˆ๋‹ค. cluster_size : ํด๋Ÿฌ์Šคํ„ฐ ๋งˆ์Šคํ„ฐ ๋…ธ๋“œ ์ˆ˜ ์ž…๋‹ˆ๋‹ค.

cluster nodes
alt text

์ด์ œ ์•„๋ฌด ๋…ธ๋“œ๋‚˜ ์ ‘์†ํ•ด์„œ ํ…Œ์ŠคํŠธํ•ด๋ณด์ž.

docker exec -it redis-node-1 redis-cli -p 6379 -c
set mykey myvalue
> OK
get mykey
> "myvalue"

์ž˜ ๋œ๋‹ค.

Type๋ณ„ ํŠน์ง•

Redis - standalone

  • simple

  • no redundancy

  • no failover

Redis - replication

  • HA(High Availability)๋ฅผ ์œ„ํ•œ ๊ตฌ์กฐ

  • Read Performance(์ฝ๊ธฐ ์„ฑ๋Šฅ) ํ–ฅ์ƒ

  • Fault tolerance

  • Main instance๋Š” ๋ณต์ œ ID์™€ offset์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.(Replication ID, offset)

  • Main๊ณผ Secondary ๊ฐ€ ๊ฐ™์€ replication ID๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ  offset์ด ๋‹ค๋ฅธ ๊ฒฝ์šฐ ๋™๊ธฐํ™”๊ฐ€ ํ•„์š”

  • offset ๊ฐ’์€ main Redis๊ฐ€ deployment(๋ฐฐํฌ)๋  ๋•Œ๋งˆ๋‹ค ์ผ์–ด๋‚œ๋‹ค

  • ๋‘ ์š”์†Œ๋Š” ๋ณต์ œ๊ฐ€ ๊ณ„์†๋  ์ˆ˜ ์žˆ๋Š” ์‹œ์ ์„ ์ฐพ๋Š”๋ฐ๋„ ๋„์›€์ด ๋˜๋ฉฐ, Secondary main instance ๊ฐ„ ๋™๊ธฐํ™”๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

  • RDB snapshot์ด๋‚˜, ๋ณต์ œ๋ณธ์„ ๋ณด๋‚ด์–ด ๋™๊ธฐํ™”๋ฅผ ํ•˜๋Š” ๋“ฑ Main๊ณผ secondary๋ฅผ syncํ•  ์ž‘์—…์ด ๋ฐœ์ƒํ•œ๋‹ค.

  • Replication ID: instance๊ฐ€ Main์œผ๋กœ ์Šน๊ฒฉ๋˜๊ฑฐ๋‚˜ Main์œผ๋กœ์„œ ๋‹ค์‹œ ์ฒ˜์Œ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด, replication ID ๋ณ€๊ฒฝ

  • ํด๋ผ์ด์–ธํŠธ ์š”์ฒญ์‹œ Zookeeper์ฒ˜๋Ÿผ ํ˜„์žฌ ๊ธฐ๋ณธ ์ธ์Šคํ„ด์Šค๊ฐ€ ๋ฌด์—‡์ธ์ง€๋ฅผ ์•Œ๋ ค์ค€๋‹ค.ํด๋ผ์–ธํŠธ๋Š” ์ด์ •๋ณด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์‹œ ์ •๋ณด ์š”์ฒญํ•œ๋‹ค.

  • Redis์˜ ๋ณต์ œ๋Š” ๋น„๋™๊ธฐ์‹

Redis - sentinel

  • Main/Secondary ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜๋Š”์ง€ ์ง€์†์  Monitoring

  • Automatic Failover

  • Notification : failover๋˜์—ˆ์„ ๋•Œ Notification ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋‹ค

  • ๊ณผ๋ฐ˜ ์ˆ˜ ์ด์ƒ์˜ sentinel์ด Master ์žฅ์• ๋ฅผ ๊ฐ์ง€ํ•˜๋ฉด Slave ์ค‘ ํ•˜๋‚˜๋ฅผ Master๋กœ ์Šน๊ฒฉ์‹œํ‚ค๊ณ  ๊ธฐ์กด์˜ Master๋Š” Slave๋กœ ๊ฐ•๋“ฑ์‹œํ‚จ๋‹ค

  • Slave๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ ์žˆ์„ ๊ฒฝ์šฐ Slave๊ฐ€ ์ƒˆ๋กœ์šด Master๋กœ๋ถ€ํ„ฐ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์„ ์ˆ˜ ์žˆ๋„๋ก ์ž๋™์œผ๋กœ ์žฌ๊ตฌ์„ฑ๋œ๋‹ค.

  • Quorum : ๋ช‡ ๊ฐœ์˜ Sentinel์ด Redis์˜ ์žฅ์•  ๋ฐœ์ƒ์„ ๊ฐ์ง€ํ•ด์•ผ ์žฅ์• ๋ผ๊ณ  ํŒ๋ณ„ํ•˜๋Š”์ง€๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ๊ธฐ์ค€ ๊ฐ’. redis replica์˜ ๊ณผ๋ฐ˜ ์ˆ˜ ์ด์ƒ์œผ๋กœ ์„ค์ •ํ•œ๋‹ค.

  • Sentinel์€ 1์ฐจ ๋ณต์ œ๋งŒ Master ํ›„๋ณด์— ์˜ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค. (๋ณต์ œ ์„œ๋ฒ„์˜ ๋ณต์ œ ์„œ๋ฒ„๋Š” ๋ถˆ๊ฐ€๋Šฅ)

  • 1์ฐจ ๋ณต์ œ ์„œ๋ฒ„ ์ค‘ replica-priority ๊ฐ’์ด ๊ฐ€์žฅ ์ž‘์€ ์„œ๋ฒ„๊ฐ€ ๋งˆ์Šคํ„ฐ์— ์„ ์ •๋œ๋‹ค. 0์œผ๋กœ ์„ค์ •ํ•˜๋ฉด master๋กœ ์Šน๊ฒฉ ๋ถˆ๊ฐ€๋Šฅํ•˜๊ณ  ๋™์ผํ•œ ๊ฐ’์ด ์žˆ์„ ๋• ์—”์ง„์—์„œ ์„ ํƒํ•œ๋‹ค.

  • ์•ˆ์ •์  ์šด์˜์„ ์œ„ํ•ด 3๊ฐœ ์ด์ƒ์˜ sentinel์„ ๋งŒ๋“œ๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•˜๋Š”๋ฐ, ์„œ๋กœ ๋ฌผ๋ฆฌ์ ์œผ๋กœ ์˜ํ–ฅ๋ฐ›์ง€ ์•Š๋Š” ์ปดํ“จํ„ฐ๋‚˜ ๊ฐ€์ƒ ๋จธ์‹ ์— ์„ค์น˜๋˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

  • sentienl์€ ๋‚ด๋ถ€์ ์œผ๋กœ redis ์˜ Pub/Sub ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•ด์„œ ์„œ๋กœ ์ •๋ณด๋ฅผ ์ฃผ๊ณ  ๋ฐ›๋Š”๋‹ค.

  • ์„ผํ‹ฐ๋„ + ๋ ˆ๋””์Šค ๊ตฌ์กฐ์˜ ๋ถ„์‚ฐ ์‹œ์Šคํ…œ์€ ๋ ˆ๋””์Šค๊ฐ€ ๋น„๋™๊ธฐ ๋ณต์ œ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๋™์•ˆ ์ผ๋˜ ๋‚ด์šฉ๋“ค์ด ์œ ์ง€๋จ์„ ๋ณด์žฅํ•  ์ˆ˜ ์—†๋‹ค.

  • Sentinel์„ Redis์™€ ๋™์ผํ•œ Node์— ๊ตฌ์„ฑํ•ด๋„ ๋˜๊ณ , ๋ณ„๋„๋กœ ๊ตฌ์„ฑํ•ด๋„ ๋œ๋‹ค.

  • ํด๋ผ์ด์–ธํŠธ๋Š” ๋ ˆ๋””์Šค Main์˜ ์ฃผ์†Œ๋ฅผ ์•Œ์•„๋‚ด๊ธฐ ์œ„ํ•ด ์„ผํ‹ฐ๋„์— ์—ฐ๊ฒฐํ•œ๋‹ค. sentinel์ด Main ์ฃผ์†Œ๋ฅผ ๋ณด๋‚ด์ค€๋‹ค. ์žฅ์•  ์กฐ์น˜๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด sentinel์€ ์ƒˆ Main์ฃผ์†Œ๋ฅผ ์•Œ๋ ค์ค€๋‹ค.

  • ์ฟผ๋Ÿผ(Quorum) : ์„ผํ‹ฐ๋„์ด ์žฅ์• ๋ฅผ ๊ฐ์ง€ํ•˜๊ธฐ ์œ„ํ•œ ์ตœ์†Œํ•œ์˜ ์„ผํ‹ฐ๋„ ์ˆ˜

    number of server
    Quorum
    available Fail

    1

    1

    0

    2

    2

    0

    3

    2

    1

    4

    3

    1

    4

    3

    1

    5

    3

    2

5๊ฐœ์˜ ์„œ๋ฒ„๊ฐ€ ๋˜๋ฉด 2๊ฐœ๊ฐ€ failํ•ด๋„ ์ž‘๋™ํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ 5๊ฐœ๋ฅผ ์ถ”์ฒœํ•œ๋‹ค.

failover ๊ฐ์ง€ ๋ฐฉ๋ฒ•

  • SDOWN : Subjectively down(์ฃผ๊ด€์  ๋‹ค์šด) sentinel์—์„œ ์ฃผ๊ธฐ์ ์œผ๋กœ Master์—๊ฒŒ ๋ณด๋‚ด๋Š” PING๊ณผ INFO ๋ช…๋ น์˜ ์‘๋‹ต์ด 3์ดˆ ๋™์•ˆ ์˜ค์ง€ ์•Š์œผ๋ฉด ์ฃผ๊ด€์  ๋‹ค์šด์œผ๋กœ ์ธ์ง€ ์„ผํ‹ฐ๋„ ํ•œ ๋Œ€์—์„œ ํŒ๋‹จํ•œ ๊ฒƒ์œผ๋กœ, ์ฃผ๊ด€์  ๋‹ค์šด๋งŒ์œผ๋กœ๋Š” ์žฅ์• ์กฐ์น˜๋ฅผ ์ง„ํ–‰ํ•˜์ง€ ์•Š๋Š”๋‹ค.

  • ODOWN : Objectively down(๊ฐ๊ด€์  ๋‹ค์šด) ์„ค์ •ํ•œ quorum ์ด์ƒ์˜ sentinel์—์„œ ํ•ด๋‹น Master๊ฐ€ ๋‹ค์šด๋˜์—ˆ๋‹ค๊ณ  ์ธ์ง€ํ•˜๋ฉด ๊ฐ๊ด€์  ๋‹ค์šด์œผ๋กœ ์ธ์ •ํ•˜๊ณ  ์žฅ์•  ์กฐ์น˜๋ฅผ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

redis-cluster

  • Automatic Failover

  • sharding

  • main์ด ์ฃฝ์„ ๊ฒฝ์šฐ Secondary์ค‘ ํ•˜๋‚˜๊ฐ€ main๋กœ ์Šน๊ฒฉ๋œ๋‹ค โ†’ ์ค‘๋‹จ์—†๋Š” ์„œ๋น„์Šค ์ œ๊ณต

  • gossip Protocol : ๊ฐ Redis๋Š” ๋‹ค๋ฅธ Redis๋“ค๊ณผ ์ง์ ‘ ์—ฐ๊ฒฐํ•˜์—ฌ ์ƒํƒœ ์ •๋ณด๋ฅผ ํ†ต์‹ 

  • ๊ธฐ์กด main์ด ๋‹ค์‹œ ์‚ด์•„๋‚˜๋ฉด Secondary๊ฐ€ ๋œ๋‹ค

  • Multi-Main, Multi-Secondary ๊ตฌ์กฐ

  • ๋…ธ๋“œ๋ฅผ ์ถ”๊ฐ€/์‚ญ์ œํ•  ๋•Œ ์šด์˜ ์ค‘๋‹จ ์—†์ด Hash slot์„ ์žฌ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค

  • ๊ณผ๋ฐ˜์ˆ˜ ์ด์ƒ์˜ ๋…ธ๋“œ๊ฐ€ fail๋˜๋ฉด cluster๊ฐ€ ๋ง๊ฐ€์ง„๋‹ค

  • data ์ •ํ•ฉ์„ฑ์ด ๋งž์ง€์•Š์œผ๋ฉด Master์˜ Data๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ •ํ•ฉ์„ฑ์„ ๋งž์ถ˜๋‹ค.

  • cluster redis๋Š” 2๊ฐœ์˜ ํฌํŠธ๊ฐ€ ํ•„์š”ํ•˜๋‹ค (ํด๋ผ์ด์–ธํŠธ๋ฅผ ์œ„ํ•œ ํฌํŠธ, ๋…ธ๋“œ ๊ฐ„ ํ†ต์‹  ๋ฒ„์Šค ํฌํŠธ)

  • ํด๋ผ์ด์–ธํŠธ๊ฐ€ redis์— ๋ฐ์ดํ„ฐ๋ฅผ ์š”์ฒญํ–ˆ์„ ๋•Œ, ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์€ master node์— ์š”์ฒญํ•˜๋ฉด ํ•ด๋‹น ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ๋œ ์œ„์น˜๋ฅผ ์•Œ๋ ค์ฃผ๊ณ  client์—๊ฒŒ ์•Œ๋ ค์ฃผ๊ณ  client๋Š” ์ œ๋Œ€๋กœ ๋œ ์ฃผ์†Œ์— ๋‹ค์‹œ ์š”์ฒญํ•œ๋‹ค

  • 16K hashslot์„ ์ด์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๊ฐ€ cluster ์‚ฌ์ด์— ์ ์ ˆํžˆ ๋ถ„๋ฐฐ๋  ์ˆ˜ ์žˆ๋„๋ก ๋•๋Š”๋‹ค.

์˜์†์„ฑ

RDB Files

  • Snapshot

  • Snapshot ์ดํ›„ ๋ฐ์ดํ„ฐ๋Š” ์ƒ์‹ค

  • AOF ๋ณด๋‹ค๋ฉ”๋ชจ๋ฆฌ์— ๋กœ๋“œ๋˜๋Š” ์†๋„ ๋น ๋ฅด๋‹ค.

AOF (Append Only File)

  • ์„œ๋ฒ„ ์‹œ์ž‘ ์‹œ, ๋‹ค์‹œ ์žฌ์ƒ๋  ์„œ๋ฒ„๊ฐ€ ์ˆ˜์‹ ํ•˜๋Š” ๋ชจ๋“  ์“ฐ๊ธฐ ์ž‘์—…์„ ๊ธฐ๋กํ•˜์—ฌ ์›๋ณธ ๋ฐ์ดํ„ฐ ์„ธํŠธ๋ฅผ ์žฌ๊ตฌ์„ฑํ•œ๋‹ค.

  • ์ž‘์—…์ด ๋ฐœ์ƒํ•˜๋ฉด, ๋กœ๊ทธ์— ๋ฒ„ํผ๋ง๋œ๋‹ค.

  • ์••์ถ•๋˜์ง€ ์•Š์•„ RDB(Redis DataBase)๋ณด๋‹ค ํ›จ์”ฌ ๋” ๋งŽ์€ ๋””์Šคํฌ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค

  • ์„œ๋ฒ„ ์žฌ์‹œ์ž‘์‹œ์— ๊ธฐ์กด๋ฐ์ดํ„ฐ ๋ณด๊ด€์ด ํ•„์š”ํ•œ๊ฒฝ์šฐ์— ์ข‹์„๊ฑฐ๊ฐ™๋‹ค. replication์ด๋‚˜ sentinel์„ ์„ค์ •ํ•œ๊ฒฝ์šฐ ์žฌ๋ถ€ํŒ…ํ›„ ์ž๋™ ๋ณต์ œ ์ผ์–ด๋‚˜์„œ ํ•„์š”์—†์Œ.

Kubernetes ์—์„œ ๋ฐฐํฌ

์ด์ œ kubernetes์—์„œ ๋ฐฐํฌํ•ด๋ณด์ž.

argocd๋ฅผ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ subchart๋ฅผ ๋งŒ๋“ค์ž.

mkdir redis-helm
cd redis-helm
vi Chart.yaml
apiVersion: v2
name: redis
type: application
version: 1.0.0
appVersion: '1.0.0'
dependencies:
  - name: redis
    version: '17.1.4'
    repository: https://charts.bitnami.com/bitnami

helm chart versin์„ ์ •ํ™•์‹œ ์ ์–ด ์ค๋‹ˆ๋‹ค.

vi values.yaml
redis:
  image:
    registry: docker.io
    repository: bitnami/redis
    tag: 7.2

  architecture: replication

  auth:
    enabled: true
    sentinel: true
    password: 'xxxx'

  commonConfiguration: |-
    # Enable AOF https://redis.io/topics/persistence#append-only-file
    appendonly yes
    # Disable RDB persistence, AOF persistence already enabled.
    save ""
  existingConfigmap: ''
  master:
    count: 1
    persistence:
      enabled: true

  replica:
    replicaCount: 3
    persistence:
      enabled: true

  sentinel:
    enabled: true
    image:
      registry: docker.io
      repository: bitnami/redis-sentinel
      tag: 7.2
    quorum: 2

  metrics:
    enabled: true

argocd๋กœ ๋ฐฐํฌํ•˜์ž.

git add --all && git commit -am "update" && git push
vi add-redis-helm.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: redis
  namespace: argocd
spec:
  destination:
    name: ''
    namespace: web
    server: 'https://kubernetes.default.svc'
  source:
    path: apps/redis-heml
    repoURL: 'https://github.com/bbbb/ccc.git'
    targetRevision: HEAD
  project: default

replica๊ฐฏ์ˆ˜๋งŒํฐ pod๊ฐ€ ์ƒ์„ฑ์ด ๋ฉ๋‹ˆ๋‹ค ๊ทธ๋ฆฌ๊ณ  ์ด pod์—๋Š” redis์™€ sentinel์ด sidecar๋กœ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

replica๊ฐ€ 3๊ฐœ๋ฉด 3๊ฐœ์˜ pod๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ทธ์ค‘ ํ•˜๋‚˜๊ฐ€ master๊ฐ€ ๋˜๊ณ  ๋‚˜๋จธ์ง€ 2๊ฐœ๋Š” slave๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

์ „์ฒด pod์— sentinel๋„ ๋™์‹œ์— ์„ค์น˜๋˜๋ฏ€๋กœ quorum์„ 3๋กœ ์„ค์ •ํ•˜๋ฉด (2๊ฐœ์˜ pod๊ฐ€ ๋ง๊ฐ€์ ธ๋„ sentinel ํด๋Ÿฌ์Šคํ„ฐ ์œ ์ง€)ํ•˜๋ ค๋ฉด 5๊ฐœ์˜ replica๋ฅผ ์„ค์ •ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

์ถ”๊ฐ€ ์„ค์ •์€ ๋‹ค์Œ์—์„œ ํ™•์ธํ•˜์„ธ์š”.

https://artifacthub.io/packages/helm/bitnami/redis

์ฐธ๊ณ 

Last updated

Was this helpful?