jimtse
网站页面
关于 Redis 哨兵的介绍:
sentinel/
├── docker-compose.yml
├── master
│ ├── data/
│ └── redis.conf
├── slave1
│ ├── data/
│ └── redis.conf
├── slave2
| ├── data/
| └── redis.conf
├── sentinel1
│ └── sentinel.conf
├── sentinel2
│ └── sentinel.conf
└── sentinel3
└── sentinel.conf
version: "3"
networks:
redis-replication:
driver: bridge
ipam:
config:
- subnet: 172.25.0.0/24
services:
master:
image: redis
container_name: redis-master
ports:
- "6380:6379"
volumes:
- "./master/redis.conf:/etc/redis.conf"
- "./master/data:/data"
command: ["redis-server", "/etc/redis.conf"]
restart: always
networks:
redis-replication:
ipv4_address: 172.25.0.101
slave1:
image: redis
container_name: redis-slave-1
ports:
- "6381:6379"
volumes:
- "./slave1/redis.conf:/etc/redis.conf"
- "./slave1/data:/data"
command: ["redis-server", "/etc/redis.conf"]
restart: always
networks:
redis-replication:
ipv4_address: 172.25.0.102
slave2:
image: redis
container_name: redis-slave-2
ports:
- "6382:6379"
volumes:
- "./slave2/redis.conf:/etc/redis.conf"
- "./slave2/data:/data"
command: ["redis-server", "/etc/redis.conf"]
restart: always
networks:
redis-replication:
ipv4_address: 172.25.0.103
sentinel1:
image: redis
container_name: redis-sentinel-1
ports:
- "26380:26379"
volumes:
- "./sentinel1/sentinel.conf:/etc/sentinel.conf"
command: ["/bin/bash", "-c", "cp /etc/sentinel.conf /sentinel.conf && redis-sentinel /sentinel.conf"]
restart: always
networks:
redis-replication:
ipv4_address: 172.25.0.201
sentinel2:
image: redis
container_name: redis-sentinel-2
ports:
- "26381:26379"
volumes:
- "./sentinel2/sentinel.conf:/etc/sentinel.conf"
command: ["/bin/bash", "-c", "cp /etc/sentinel.conf /sentinel.conf && redis-sentinel /sentinel.conf"]
restart: always
networks:
redis-replication:
ipv4_address: 172.25.0.202
sentinel3:
image: redis
container_name: redis-sentinel-3
ports:
- "26382:26379"
volumes:
- "./sentinel3/sentinel.conf:/etc/sentinel.conf"
command: ["/bin/bash", "-c", "cp /etc/sentinel.conf /sentinel.conf && redis-sentinel /sentinel.conf"]
restart: always
networks:
redis-replication:
ipv4_address: 172.25.0.203
port 6379
pidfile /var/run/redis_6379.pid
protected-mode no
timeout 0
tcp-keepalive 300
loglevel notice
################################# REPLICATION #################################
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
##################################### RDB #####################################
dbfilename dump.rdb
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dir ./
##################################### AOF #####################################
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
aof-load-truncated yes
aof-use-rdb-preamble no
port 6379
pidfile /var/run/redis_6379.pid
protected-mode no
timeout 0
tcp-keepalive 300
loglevel notice
################################# REPLICATION #################################
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
#slaveof 172.25.0.101 6379
replicaof 172.25.0.101 6379
##################################### RDB #####################################
dbfilename dump.rdb
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dir ./
##################################### AOF #####################################
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
aof-load-truncated yes
aof-use-rdb-preamble no
# 所有哨兵端口都一致,因为使用 Docker 桥接网络映射
port 26379
# 哨兵设置,所有哨兵皆一致,都指向 Master
sentinel monitor mymaster 172.25.0.101 6379 2
sentinel parallel-syncs mymaster 1
sentinel down-after-milliseconds mymaster 30000
sentinel failover-timeout mymaster 180000
bind 0.0.0.0
protected-mode no
daemonize no
pidfile /var/run/redis-sentinel.pid
logfile ""
dir /tmp
docker-compose up -d
docker stop redis-master redis-slave-1 redis-slave-2 redis-sentinel-1 redis-sentinel-2 redis-sentinel-3
docker logs --tail 100 redis-master