部署Redis Sentinel集群
使用Docker-compose 单机部署Sentinel集群说明
- sentinel集群部署至少需要3台服务器,分别部署redis和sentinel,
- sentinel和redis都配置了账号密码认证
- 使用docker来部署sentinel 需要创建网格模型来隔离
- sentinel的配置文件都需要指向到redis的Master节点
- 以下为 master redis 的配置文件
- slave 的配置文件需要添加主节点的IP地址和密码
redis 主配置文件
#####################################
bind 0.0.0.0
protected-mode no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 0
################################# GENERAL #####################################
daemonize no
supervised no
pidfile "/var/run/redis_6379.pid"
loglevel notice
logfile "redis.log"
databases 64
################################ SNAPSHOTTING ################################
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum 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-rewrite-incremental-fsync yes
################################# REPLICATION #################################
masterauth Sf2023reDis
# slaveof 192.168.3.2 6379 # 做为从节点,需要配置此项
################################## SECURITY ###################################
requirepass "Sf2023reDis"
################################### LIMITS ####################################
maxmemory 7812500kb
maxmemory-policy noeviction
################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 128
# 以下内容为sentinel自动生成的配置,每次master变更此配置会发生变化
# Generated by CONFIG REWRITE
latency-tracking-info-percentiles 50 99 99.9
dir "/data"
replicaof 192.168.3.4 6379
user default on #d596ea9d5a8e30181a5da34fa9dacc815b413922f54d786f58f4d2974565a58a ~* &* +@all
sentinel 配置文件
# sentinel monitor <master-group-name> <ip> <port> <quorum>
port 26379
daemonize no
logfile "sentinel.log"
dir "/data"
sentinel monitor mymaster 192.168.3.4 6379 2
sentinel auth-pass mymaster Sf2023reDis
sentinel sentinel-pass Sf2023reDis
sentinel down-after-milliseconds mymaster 1000
sentinel failover-timeout mymaster 18000
# 以下内容为系统自动生成,有可能会不一样
# Generated by CONFIG REWRITE
latency-tracking-info-percentiles 50 99 99.9
user default on nopass sanitize-payload ~* &* +@all
sentinel myid cfbf29e148d50b2114ea7a744a615086b78d64de
sentinel config-epoch mymaster 1
sentinel leader-epoch mymaster 1
sentinel current-epoch 1
sentinel known-sentinel mymaster 192.168.3.13 26379 8724eebeea8e30144cda27f010755458df02a6f7
sentinel known-replica mymaster 192.168.3.2 6379
sentinel known-replica mymaster 192.168.3.3 6379
sentinel known-sentinel mymaster 192.168.3.14 26379 3e0f37e6567e5073e67f8d0da65a15b828f74ae9
docker-compose YAML文件
version: "3.6"
networks:
redis-test:
driver: bridge
ipam:
config:
- subnet: "192.168.3.0/24"
services:
redis-master:
image: redis
container_name: "redis-master"
ports:
- "6380:6379"
volumes:
- ./redis-1/conf:/etc/redis/
- ./redis-1/data:/data
command: redis-server /etc/redis/redis.conf
networks:
redis-test:
ipv4_address: 192.168.3.2
redis-slave1:
image: redis
container_name: "redis-slave1"
ports:
- "6381:6379"
volumes:
- ./redis-2/conf:/etc/redis/
- ./redis-2/data:/data
command: redis-server /etc/redis/redis.conf
networks:
redis-test:
ipv4_address: 192.168.3.3
redis-slave2:
image: redis
container_name: "redis-slave2"
ports:
- "6382:6379"
volumes:
- ./redis-3/conf:/etc/redis/
- ./redis-3/data:/data
command: redis-server /etc/redis/redis.conf
networks:
redis-test:
ipv4_address: 192.168.3.4
redis-sentinel1:
image: redis
container_name: "redis-sentinel1"
ports:
- "26380:26379"
volumes:
- ./sentinel-1/conf:/etc/redis/
- ./sentinel-1/data:/data
command: redis-sentinel /etc/redis/sentinel.conf
networks:
redis-test:
ipv4_address: 192.168.3.12
redis-sentinel2:
image: redis
container_name: "redis-sentinel2"
ports:
- "26381:26379"
volumes:
- ./sentinel-2/conf:/etc/redis/
- ./sentinel-2/data:/data
command: redis-sentinel /etc/redis/sentinel.conf
networks:
redis-test:
ipv4_address: 192.168.3.13
redis-sentinel3:
image: redis
container_name: "redis-sentinel3"
ports:
- "26382:26379"
volumes:
- ./sentinel-3/conf:/etc/redis/
- ./sentinel-3/data:/data
command: redis-sentinel /etc/redis/sentinel.conf
networks:
redis-test:
ipv4_address: 192.168.3.14