1. Create a directory
mkdir /usr/local/docker
cd /usr/local/docker
mkdir redis sentinel
2. Create a profile Redis
nano self-installing tool
cd redis
nano docker-compose.yml
Enter the following
version: '3.1'
services:
master:
image: redis
container_name: redis-master
ports:
- 6379:6379
slave1:
image: redis
container_name: redis-slave-1
ports:
- 6380:6379
command: redis-server --slaveof redis-master 6379
slave2:
image: redis
container_name: redis-slave-2
ports:
- 6381:6379
command: redis-server --slaveof redis-master 6379
Save and Exit
ctrl + o
Enter
ctrl + x
Start Redis service
docker-compose up -d
3, create a configuration file Sentinel
cd ../sentinel
nano docker-compose.yml
Enter the following
version: '3.1'
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
Save and exit
nano sentinel.conf
Enter the following
port 26379
dir /tmp
sentinel monitor mymaster IP 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
IP Office and fill out your own IP
replicate three profiles
cp sentinel.conf sentinel1.conf
cp sentinel.conf sentinel2.conf
cp sentinel.conf sentinel3.conf
Start Sentinel Service
docker-compose up -d
4, open Redis client
Enter the name, address, port number, click below to test the connection, the connection is successful