【Redis】多机部署Redis-sentinel

1. Redis-sentinel配置文件

注意不同服务器上的Redis版本需要相同,否则可能因为RDB文件不同而导致Redis主从同步失败。

java 复制代码
bind 0.0.0.0	// 任何ip都可以连接
port 27001		// 本机的端口
daemonize yes	// 后台运行
sentinel announce-ip "xxx.xxx.xxx.xxx"	// 本机的ip
sentinel monitor mymaster xxx.xxxx.xxxx.xxx 6379 2	// masterRedis的ip 端口 要有多少个sentinel票可以选为master
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
sentinel auth-pass mymaster xxxx // 密码
dir "/root/sentinel/sentinel"
logfile "a.log"
# Generated by CONFIG REWRITE
protected-mode no

2. SpringBoot配置Redis-sentinel

application.yaml:

java 复制代码
spring:
  redis:
    password: "xxx" // Redis密码
    sentinel:
      master: mymaster
      nodes:
        - xxx.xxxx.xxx.xxx:27001
        - xxx.xxxx.xxx.xxx:27001
        - xxx.xxxx.xxx.xxx:27001

在启动类中注册配置类Bean

java 复制代码
@SpringBootApplication
public class RedisDemoApplication {

    @Bean
    public LettuceClientConfigurationBuilderCustomizer clientConfigurationBuilderCustomizer() {
        return clientConfigurationBuilder -> clientConfigurationBuilder.readFrom(ReadFrom.REPLICA_PREFERRED);
    }

    public static void main(String[] args) {
        SpringApplication.run(RedisDemoApplication.class, args);
        System.out.println("启动成功");
    }

}
相关推荐
zaim144 分钟前
计算机的错误计算(一百一十四)
java·c++·python·rust·go·c·多项式
hong_zc2 小时前
算法【Java】—— 二叉树的深搜
java·算法
进击的女IT3 小时前
SpringBoot上传图片实现本地存储以及实现直接上传阿里云OSS
java·spring boot·后端
Miqiuha3 小时前
lock_guard和unique_lock学习总结
java·数据库·学习
一 乐4 小时前
学籍管理平台|在线学籍管理平台系统|基于Springboot+VUE的在线学籍管理平台系统设计与实现(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·学习
数云界4 小时前
如何在 DAX 中计算多个周期的移动平均线
java·服务器·前端
阑梦清川4 小时前
Java继承、final/protected说明、super/this辨析
java·开发语言
快乐就好ya6 小时前
Java多线程
java·开发语言
IT学长编程6 小时前
计算机毕业设计 二手图书交易系统的设计与实现 Java实战项目 附源码+文档+视频讲解
java·spring boot·毕业设计·课程设计·毕业论文·计算机毕业设计选题·二手图书交易系统
CS_GaoMing6 小时前
Centos7 JDK 多版本管理与 Maven 构建问题和注意!
java·开发语言·maven·centos7·java多版本