三、搭建哨兵

 1、先创建一主二从,端口号分别为master:6379,slave:6380,slave:6381

 2、接着创建三个哨兵26379、26380、26381,首先在data/sentinel-01/conf目录下载sentinel.conf配置文件

wget http://download.redis.io/redis-stable/sentinel.conf  # 下载sentinel配置文件
3、编写sentinel.conf配置文件内容如下(此为sentinel26379,其余两个只需修改端口号就行):
port 26379
daemonize no
logfile "27379.log"
#dir "/data/sentinel/data"
dir ./
sentinel monitor mymaster 172.17.0.2 6379 2 #监控主master地址
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000

 

4、运行哨兵26379

  docker run --name sentinel26379 -p 26379:26379 \
-v /data/sentinel-01/conf/sentinel.conf:/redis/redis.conf \
-v /data/sentinel-01/data:/data \
-d redis:6.0.5 redis-sentinel /redis/redis.conf 
​
#运行26380
docker run --name sentinel26380 -p 26380:26380 \
-v /data/sentinel-02/conf/sentinel.conf:/redis/redis.conf \
-v /data/sentinel-02/data:/data \
-d redis:6.0.5 redis-sentinel /redis/redis.conf 
​
#运行26381
docker run --name sentinel26381 -p 26381:26381 \
-v /data/sentinel-03/conf/sentinel.conf:/redis/redis.conf \
-v /data/sentinel-03/data:/data \
-d redis:6.0.5 redis-sentinel /redis/redis.conf 
 

 5、查看sentinel.conf,有新增内容:

port 26379
daemonize no
logfile "26379.log"
dir ./
sentinel myid 251c6aaa9f0453a2cf1e1d3cc85e7a1af00a5753
sentinel deny-scripts-reconfig yes
sentinel monitor mymaster 172.17.0.2 6379 2
sentinel config-epoch mymaster 0
# Generated by CONFIG REWRITE
user default on nopass ~* +@all
sentinel leader-epoch mymaster 0
sentinel known-replica mymaster 172.17.0.4 6381
sentinel known-replica mymaster 172.17.0.3 6380
sentinel current-epoch 0

 


 6、进入sentinel26379容器内查看信息:

docker exec -it sentinel26379 /bin/bash
info

 

 

 7、查看sentinel26381的日志信息:

  

 

 

8、停掉master6379,并查看sentinel26387的日志信息:

选择了6380作为主master

 

 

9、查看redis6380的服务器信息如下:

可以查看redis6380已经被作为master服务器了。

info replication

 

 

 

 10、测试值:

 

 

 

 

 11、再次重启,还是6380作为master,6379作为slave

posted @ 2020-07-31 15:45  JDLiao  阅读(253)  评论(0编辑  收藏  举报