Docker-Compose搭建高可用redis哨兵集群

docker network create --subnet=172.10.0.0/24 docker-network


mkdir -p /data/docker/redis/master & vim /data/docker/redis/master/docker-compose.yml

version: '3'
services:
master:
image: redis
container_name: redis-master
command: redis-server --requirepass password --masterauth password
ports:
- 6380:6379
slave1:
image: redis
container_name: redis-slave-1
ports:
- 6381:6379
command: redis-server --slaveof redis-master 6379 --requirepass password --masterauth password
slave2:
image: redis
container_name: redis-slave-2
ports:
- 6382:6379
command: redis-server --slaveof redis-master 6379 --requirepass password --masterauth password
networks:
default:
external:
name: docker-network

cd /data/docker/redis/master
docker-compose up -d

Master节点的IP,通过docker inspect redis-master

mkdir -p /data/docker/redis/sentinel
cd /data/docker/redis/sentinel
vim docker-compose.yml

version: '3'
services:
sentinel1:
image: redis
container_name: redis-sentinel-1
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
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: docker-network

vim sentinel.conf
port 26379
dir /tmp
sentinel monitor mymaster 172.10.0.4 6379 2
sentinel auth-pass mymaster password
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes

cp sentinel.conf sentinel1.conf & cp sentinel.conf sentinel2.conf & cp sentinel.conf sentinel3.conf

docker-compose up -d

docker exec -it redis-master /bin/bash
redis-cli
auth password
info replication

posted @ 2022-06-01 11:49  wyz_1  阅读(56)  评论(0编辑  收藏  举报