1.为什么需要哨兵架构
如果没有哨兵架构,那么当主节点挂了的时候,需要运维人员手动将某个从节点设置为主节点,还需要修改IP等其他操作。
2.redis哨兵架构搭建
前提是先部署好redis单机或者主从
部署单机版教程地址
conf文件内容
#主要关心后面三个参数
#mymaster这个名字随便取,客户端访问时会用到
#127.0.0.1 6379 就是redis的master地址端口
#后面这个数字2不固定, 一般(总数除2)+1
sentinel monitor mymaster 127.0.0.1 6379 2
daemonize yes
protected-mode no
#如果Master存在密码,需要配置sentinel auth-pass 服务器名 密码
sentinel auth-pass myredis 123456
#端口号,根据三个文件指定三个哨兵端口
port 26379
user default on nopass sanitize-payload ~* &* +@all
dir "/tmp"
直接启动
./src/redis-sentinel ./config/sentinel-26379.conf
./src/redis-sentinel ./config/sentinel-26380.conf
./src/redis-sentinel ./config/sentinel-26381.conf
我们随便找个哨兵连接一下
成功