redis 主从
docker-compose.yml
version: '3.7'
services:
master:
image: redis
container_name: redis-master
restart: always
command: redis-server --appendonly yes
ports:
- 6379:6379
volumes:
- ./data1:/data
slave1:
image: redis
container_name: redis-slave-1
restart: always
command: redis-server --slaveof redis-master 6379 --appendonly yes
ports:
- 6380:6379
volumes:
- ./data2:/data
slave2:
image: redis
container_name: redis-slave-2
restart: always
command: redis-server --slaveof redis-master 6379 --appendonly yes
ports:
- 6381:6379
volumes:
- ./data3:/data
sudo docker-compose -f docker-compose.yml up -d
哨兵
docker-compose.yml
version: '3.7'
services:
sentinel1:
image: redis
container_name: redis-sentinel-1
restart: always
ports:
- 26379:26379
command: redis-sentinel /usr/local/etc/redis/sentinel.conf
volumes:
- ./sentinel1.conf:/usr/local/etc/redis/sentinel.conf
sentinel2:
image: redis
container_name: redis-sentinel-2
restart: always
ports:
- 26380:26379
command: redis-sentinel /usr/local/etc/redis/sentinel.conf
volumes:
- ./sentinel2.conf:/usr/local/etc/redis/sentinel.conf
sentinel3:
image: redis
container_name: redis-sentinel-3
ports:
- 26381:26379
command: redis-sentinel /usr/local/etc/redis/sentinel.conf
volumes:
- ./sentinel3.conf:/usr/local/etc/redis/sentinel.conf
networks:
default:
external:
name: redis_default
配置文件
port 26379
dir /tmp
sentinel monitor mymaster 172.19.0.3 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
解释: 172.19.0.3 redis master ip
sentinel1.conf
sentinel2.conf
sentinel3.conf
复制3份文件和docker-compose.yml 同一级目录