使用docker部署redis,sentinel集群
下载镜像
本案例使用alpine版本
docker pull redis:alpine
启动redis
启动三个redis节点,端口分别是6379、6380、6381
docker run -d --name redis6379 \
-v /mnt/redis/6379:/data \
-v /etc/localtime:/etc/localtime \
--network host \
redis:alpine \
redis-server --appendonly yes \
--port 6379 \
--requirepass demo \
--masterauth demo
docker run -d --name redis6380 \
-v /mnt/redis/6380:/data \
-v /etc/localtime:/etc/localtime \
--network host \
redis:alpine \
redis-server --appendonly yes \
--port 6380 \
--requirepass demo \
--slave-read-only yes \
--slaveof 172.26.245.47 6379 \
--masterauth demo
docker run -d --name redis6381 \
-v /mnt/redis/6381:/data \
-v /etc/localtime:/etc/localtime \
--network host \
redis:alpine \
redis-server --appendonly yes \
--port 6381 \
--requirepass demo \
--slave-read-only yes \
--slaveof 172.26.245.47 6379 \
--masterauth demo
启动sentinel
创建三份配置文件
vim /etc/sentinel/26379/sentinel.conf
port 26379
dir "/var/log/sentinel"
logfile "/var/log/sentinel/26379.log"
sentinel monitor demomaster 172.26.245.47 6379 2
sentinel down-after-milliseconds demomaster 50000
sentinel parallel-syncs demomaster 1
sentinel failover-timeout demomaster 180000
sentinel auth-pass demomaster demo
vim /etc/sentinel/26380/sentinel.conf
port 26380
dir "/var/log/sentinel"
logfile "/var/log/sentinel/26380.log"
sentinel monitor demomaster 172.26.245.47 6379 2
sentinel down-after-milliseconds demomaster 50000
sentinel parallel-syncs demomaster 1
sentinel failover-timeout demomaster 180000
sentinel auth-pass demomaster demo
vim /etc/sentinel/26381/sentinel.conf
port 26381
dir "/var/log/sentinel"
logfile "/var/log/sentinel/26381.log"
sentinel monitor demomaster 172.26.245.47 6379 2
sentinel down-after-milliseconds demomaster 50000
sentinel parallel-syncs demomaster 1
sentinel failover-timeout demomaster 180000
sentinel auth-pass demomaster demo
三个sentinel节点,端口分别是26379、26380、26381
docker run -d --name sentinel26379 \
-v /etc/sentinel/26379/sentinel.conf:/conf/sentinel.conf \
-v /var/log/sentinel:/var/log/sentinel \
-v /etc/localtime:/etc/localtime \
--network host \
redis:alpine \
redis-sentinel \
/conf/sentinel.conf --sentinel
docker run -d --name sentinel26380 \
-v /etc/sentinel/26380/sentinel.conf:/conf/sentinel.conf \
-v /var/log/sentinel:/var/log/sentinel \
-v /etc/localtime:/etc/localtime \
--network host \
redis:alpine \
redis-sentinel \
/conf/sentinel.conf --sentinel
docker run -d --name sentinel26381 \
-v /etc/sentinel/26381/sentinel.conf:/conf/sentinel.conf \
-v /var/log/sentinel:/var/log/sentinel \
-v /etc/localtime:/etc/localtime \
--network host \
redis:alpine \
redis-sentinel \
/conf/sentinel.conf --sentinel
查看sentinel配置文件
启动完成后查看sentinel配置文件,sentinel会将发现的redis节点和sentinel节点写入到配置文件中