1、先安装好redis主从,参考我的文章,链接如下
redis主从(windows版本)_rediswindows版本_veminhe的博客-CSDN博客
2、然后配置sentinel
参考在windows上搭建redis集群(Redis-Sentinel)
配置时,报错
然后参考Creating Server TCP listening socket *:26379: listen: UnKnown error_doubleicon的博客-CSDN博客 解决了问题,
配置文件如下
port 26379bind 127.0.0.1sentinel myid 7b805e30396b34009dada1dac7971bd42e805ae4sentinel monitor mymaster 127.0.0.1 6379 1sentinel down-after-milliseconds mymaster 5000sentinel config-epoch mymaster 12
# Generated by CONFIG REWRITE
dir "D:\\soft\\Redis"
sentinel leader-epoch mymaster 13
sentinel current-epoch 12
系统自动生成了如下内容
sentinel myid 7b805e30396b34009dada1dac7971bd42e805ae4
# Generated by CONFIG REWRITE
dir "D:\\soft\\Redis"
sentinel current-epoch 12
然后再参考我发的参考文章配置好slave1 sentinel1 slave2 sentinel2并都启动好,总共是3对,共计6个服务要启动好。
3、总结一下
3.1现在的主redis目录下文件如下图所示
其中
sentinel.conf文件如下所示
port 26379bind 127.0.0.1sentinel myid 7b805e30396b34009dada1dac7971bd42e805ae4sentinel monitor mymaster 127.0.0.1 6379 1sentinel down-after-milliseconds mymaster 5000sentinel config-epoch mymaster 12
# Generated by CONFIG REWRITE
dir "D:\\soft\\Redis"
sentinel leader-epoch mymaster 14
sentinel known-slave mymaster 127.0.0.1 6381
sentinel known-slave mymaster 127.0.0.1 6380
sentinel known-sentinel mymaster 127.0.0.1 26579 642b003df3987a6e2f2f3ddc678aa64234ee2529
sentinel known-sentinel mymaster 127.0.0.1 26479 48d0d09bf0640f42794a6cd24074221a49135448
sentinel current-epoch 18
而startup.bat文件内容如下所示
title master_6379
redis-server.exe redis.windows.conf
启动该命令窗口截图如下
而startup_sentinel.bat文件内容如下
title master_6379
redis-server.exe sentinel.conf --sentinel
启动该命令的窗口截图如下
3.2现在的slave1 sentinel1的目录如下图
其中,sentinel.conf内容如下
port 26479bind 127.0.0.1sentinel myid 48d0d09bf0640f42794a6cd24074221a49135448sentinel monitor mymaster 127.0.0.1 6379 1sentinel down-after-milliseconds mymaster 5000sentinel config-epoch mymaster 12# Generated by CONFIG REWRITE
dir "D:\\soft\\Redis-slave1"
sentinel leader-epoch mymaster 18
sentinel known-slave mymaster 127.0.0.1 6381
sentinel known-slave mymaster 127.0.0.1 6380
sentinel known-sentinel mymaster 127.0.0.1 26579 642b003df3987a6e2f2f3ddc678aa64234ee2529
sentinel known-sentinel mymaster 127.0.0.1 26379 7b805e30396b34009dada1dac7971bd42e805ae4
sentinel current-epoch 18
startup.bat文件的内容如下
title master_6380
redis-server.exe redis.windows.conf
启动该命令窗口如下
startup_sentinel.bat文件如下
title master_6380
redis-server.exe sentinel.conf --sentinel
执行该命令的窗口如下
3.3现在的slave2 sentinel2的目录如下图
其中,sentinel.conf文件如下所示
port 26579bind 127.0.0.1sentinel myid 642b003df3987a6e2f2f3ddc678aa64234ee2529sentinel monitor mymaster 127.0.0.1 6379 1sentinel down-after-milliseconds mymaster 5000sentinel config-epoch mymaster 12# Generated by CONFIG REWRITE
dir "D:\\soft\\Redis-slave2"
sentinel leader-epoch mymaster 13
sentinel known-slave mymaster 127.0.0.1 6381
sentinel known-slave mymaster 127.0.0.1 6380
sentinel known-sentinel mymaster 127.0.0.1 26479 48d0d09bf0640f42794a6cd24074221a49135448
sentinel known-sentinel mymaster 127.0.0.1 26379 7b805e30396b34009dada1dac7971bd42e805ae4
sentinel current-epoch 18
而startup.bat文件内容如下所示
title master_6381
redis-server.exe redis.windows.conf
执行该命令的窗口如下
startup_sentinel.bat文件内容如下所示
title master_6381
redis-server.exe sentinel.conf --sentinel
执行该命令的窗口如下所示
至此为止,已讲完配置、安装步骤
4、接下来,参考文章继续看下
测试服务
4.1、在redis6379目录下执行
查看redis服务状态,命令: info replication
4.1.2 查看sentinel的状态,命令: info sentinel
4.2.在redis6380上查看相关信息
4.2.1查看redis服务状态,命令: info replication
4.2.2查看sentinel的状态,命令: info sentinel
4.3.在redis6381上查看相关信息 ,参考4.2
4.4.redis主从自动failover测试
停止master服务器,查看剩余服务器的状态
在slave 6380上查看,还是slave
在slave 6381上查看,也还是slave
并没有达到预期的目的:master的服务器端口从6379变成了6380,也就是说redis自动的实现了主从切换。请问是为什么呢?