Redis之sentinel搭建过程
Posted Morphling
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Redis之sentinel搭建过程相关的知识,希望对你有一定的参考价值。
采用一主(master)二从(slave)三哨兵(sentinel)的架构
一、下载安装Redis
1)下载Redis-x64-3.2.100.zip
2)解压文件,复制两份并重命名,形成三个文件夹:master、salve1、slave2
https://github.com/MicrosoftArchive/redis/releases
二、配置文件
1)主从配置 1.1 master文件夹中redis.windows.conf文件配置
port 6379
requirepass "wisp1991@1"
masterauth "wisp1991@1"
bind 0.0.0.0
1.2 slave1文件夹中redis.windows.conf文件配置
port 6380
requirepass "wisp1991@1"
masterauth "wisp1991@1"
bind 0.0.0.0
slaveof 127.0.0.1 6379
1.3 slave2文件夹中redis.windows.conf文件配置
port 6381
requirepass "wisp1991@1"
masterauth "wisp1991@1"
bind 0.0.0.0
slaveof 127.0.0.1 6379
2)哨兵配置
每一个redis目录中都创建一个文sentinel.conf文件
2.1 master的sentinel.conf文件配置如下
port 26379
sentinel monitor mymaster 127.0.0.1 6379 1
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 10000
sentinel auth-pass mymaster wisp1991@1
bind 0.0.0.0
2.2 slave1中的sentinel.conf文件配置
port 26479
sentinel monitor mymaster 127.0.0.1 6379 1
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 10000
sentinel auth-pass mymaster wisp1991@1
bind 0.0.0.0
2.3 slave2中的sentinel.conf文件配置
port 26579
sentinel monitor mymaster 127.0.0.1 6379 1
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 10000
sentinel auth-pass mymaster wisp1991@1
bind 0.0.0.0
三、启动服务
1)编写启动redis脚本 3.1 master文件夹中start.bat文件配置
title master
redis-server.exe redis.windows.conf
3.2 master文件夹中startsentinel.bat文件配置
title master
redis-server.exe sentinel.conf --sentinel
3.3 master文件夹中startsentinel.vbs文件配置
set ws=wscript.createobject("wscript.shell")
ws.run "start.bat /start",0
3.4 master文件夹中start-redis.vbs文件配置
set ws=wscript.createobject("wscript.shell")
ws.run "start_sentinel.bat /start",0
3.5 master文件夹中stop.bat文件配置
title master
redis-cli -h 192.168.11.111 -p 6379 -a wisp1991@1 shutdown
3.6 master文件夹中stopsentinel.bat文件配置
title master
redis-cli -h 192.168.11.111 -p 26379 -a wisp1991@1 shutdown
3.7 master文件夹中stop-redis.vbs文件配置
et ws=wscript.createobject("wscript.shell")
ws.run "stop.bat /start",0
3.8 master文件夹中stopsentinel.vbs文件配置
set ws=wscript.createobject("wscript.shell")
ws.run "stop_sentinel.bat /start",0
slave文件夹中的脚本类似master, title命名规则 redis文件夹名
四、测试服务
1) 查看redis服务状态,命令:info replication 2)查看sentinel的状态,命令:info sentinel
五、springboot2集成
1) pom.xml依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.5.0</version>
</dependency>
2) application.yml
spring:
redis:
# host: 127.0.0.1 #哨兵模式下不用配置
# port: 6379 # 哨兵模式下不用配置
password: wisp1991@1
timeout: 6000ms
lettuce:
pool:
8 :
-1ms :
8 :
0 :
sentinel:
master: mymaster
nodes: 192.168.11.111:26379,192.168.11.111:26479,192.168.11.111:26579
以上是关于Redis之sentinel搭建过程的主要内容,如果未能解决你的问题,请参考以下文章
redis高可用之redis sentinel(哨兵)的搭建以及应用