본문 바로가기

Software Engineering/Redis

[Redis] 운영을 위한 redis, sentinel config 파일 샘플

사진: Unsplash 의 Steve Johnson

 

Redis 서버를 Replica 형태로 구성하고, sentinel을 사용하여 HA를 제공하도록 confing 파일 샘플을 작성해보았습니다.

예상 운영 환경

  • VM x 3대
  • Redis: master - replica1 - replica2 
  • Sentinel: sentinel - sentinel - sentinel

redis.conf 예제

RDB, AOF, Replica를 설정하고, TLS, ACL는 사용하지 않도록 설정하였습니다.

################################## NETWORK #####################################

bind 0.0.0.0
protected-mode yes
port 6379

tcp-backlog 511
timeout 0
tcp-keepalive 300

################################# GENERAL #####################################

daemonize yes
supervised auto
pidfile /run/redis/redis-server.pid
loglevel notice
logfile /var/log/redis/redis-server.log

databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"

################################ SNAPSHOTTING  ################################

save 900 1000000
save 300 500000
save 60 100000
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/lib/redis

stop-writes-on-bgsave-error yes
rdb-del-sync-files no

################################# REPLICATION #################################

# replicaof <masterip> <masterport>
# masterauth <master-password>
# masteruser <username>

replica-serve-stale-data yes
replica-read-only yes
repl-backlog-size 16mb
repl-backlog-ttl 3600
replica-priority 100

repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no

################################## SECURITY ###################################

# requirepass foobared
acllog-max-len 128

################################### CLIENTS ####################################

maxclients 10000

############################## MEMORY MANAGEMENT ################################

maxmemory 5gb
maxmemory-policy allkeys-lru

############################# LAZY FREEING ####################################

lazyfree-lazy-eviction yes
lazyfree-lazy-expire yes

lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no

################################ THREADED I/O #################################

io-threads 4

############################ KERNEL OOM CONTROL ##############################

oom-score-adj no
oom-score-adj-values 0 200 800

#################### KERNEL transparent hugepage CONTROL ######################

disable-thp yes

############################## APPEND ONLY MODE ###############################

appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes

aof-use-rdb-preamble yes

################################ LUA SCRIPTING  ###############################

lua-time-limit 5000

################################## SLOW LOG ###################################

slowlog-log-slower-than 10000
slowlog-max-len 128

################################ LATENCY MONITOR ##############################

latency-monitor-threshold 0

############################# EVENT NOTIFICATION ##############################

notify-keyspace-events ""

############################### ADVANCED CONFIG ###############################

hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes

########################### ACTIVE DEFRAGMENTATION #######################

activedefrag yes
active-defrag-ignore-bytes 50mb
active-defrag-threshold-lower 10
active-defrag-threshold-upper 100
active-defrag-cycle-min 1
active-defrag-cycle-max 25

jemalloc-bg-thread yes

sentinel 예제

################################## GENERAL ####################################
bind 0.0.0.0
protected-mode yes
port 26379
daemonize yes
supervised auto
pidfile "/run/sentinel/redis-sentinel.pid"
logfile "/var/log/redis/redis-sentinel.log"
dir "/var/lib/redis"
requirepass mysentinelpassword

################################## CLUSTER ####################################

sentinel monitor mymaster 127.0.0.1 6379 2
sentinel auth-pass mymaster mypassword
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 180000
sentinel parallel-syncs mymaster 1

acllog-max-len 128

sentinel deny-scripts-reconfig yes
sentinel resolve-hostnames no
sentinel announce-hostnames no