栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Redis哨兵模式

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Redis哨兵模式

Redis哨兵模式 环境
主机ip
master192.168.2.50
slave1192.168.2.51
slave2192.168.2.52
一、Redis主从 1、修改配置文件 master
[root@bigdata-node05 redis-4.0.9]vim /opt/redis-4.0.9/redis.conf
# 注释监听地址
#bind 127.0.0.1

#开启守护进程 开启这个会在后台启动redis-server
daemonize yes

#修改日志文件目录
logfile /opt/redis-4.0.9/log/redis.log

#修改工作目录
dir /opt/redis-4.0.9

#开启AOF持久化功能 要开启持久化才能实现主从复制
appendonly yes
    
slave1
[root@bigdata-node05 redis-4.0.9]vim /opt/redis-4.0.9/redis.conf
# 注释监听地址
#bind 127.0.0.1

#开启守护进程 开启这个会在后台启动redis-server
daemonize yes

#修改日志文件目录
logfile /opt/redis-4.0.9/log/redis.log

#开启AOF持久化功能 要开启持久化才能实现主从复制
appendonly yes

# 修改IP和端口 指向master
slaveof 192.168.2.50 6379
slave2
[root@bigdata-node05 redis-4.0.9]vim /opt/redis-4.0.9/redis.conf
# 注释监听地址
#bind 127.0.0.1

#开启守护进程 开启这个会在后台启动redis-server
daemonize yes

#修改日志文件目录
logfile /opt/redis-4.0.9/log/redis.log

#开启AOF持久化功能 要开启持久化才能实现主从复制
appendonly yes

# 修改IP和端口 指向master
slaveof 192.168.2.50 6379
重启Redis
redis-server redis.conf
二、Redis哨兵模式 1、修改配置文件(所有redis-sentinel配置统一修改)
[root@bigdata-node05 redis-4.0.9]# vi /opt/redis-4.0.9/sentinel.conf
protected-mode no                                  #关闭保护模式
daemonize yes                                      #指定sentinel为后台启动
logfile "/opt/redis-4.0.9/log/sentinel.log"        #指定日志存放路径
sentinel monitor mymaster 192.168.2.50 6379 2      #至少几个哨兵检测到主服务器故障了,才会进行故障迁移,全部指向masterIP
sentinel auth-pass mymaster 123456                 #设置主redis密码(auth-pass 要放在monitor配置后面,不然会报错)
sentinel down-after-milliseconds mymaster 30000    #判定服务器down掉的时间周期,默认30000毫秒(30秒)
sentinel failover-timeout mymaster 180000          #故障节的的最大超时时间为180000(180秒)
2、开启哨兵模式
  • 先开启master,在开启slave
redis-sentinel /opt/redis-4.0.9/sentinel.conf --Sentinel
3、查看哨兵信息
[root@localhost opt]# redis-cli -h 192.168.2.50 -p 26379 info Sentinel

address:主redis ip;slaves:有多少个从库;sentinels:有多少个哨兵

4、查看哨兵日志
[root@localhost opt]# tail -f /opt/redis-4.0.9/log/sentinel.log

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/940114.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号