本文主要是介绍【Redis】多机部署Redis-sentinel,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1. Redis-sentinel配置文件
注意不同服务器上的Redis版本需要相同,否则可能因为RDB文件不同而导致Redis主从同步失败。
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:
spring:redis:password: "xxx" // Redis密码sentinel:master: mymasternodes:- xxx.xxxx.xxx.xxx:27001- xxx.xxxx.xxx.xxx:27001- xxx.xxxx.xxx.xxx:27001
在启动类中注册配置类Bean
@SpringBootApplication
public class RedisDemoApplication {@Beanpublic LettuceClientConfigurationBuilderCustomizer clientConfigurationBuilderCustomizer() {return clientConfigurationBuilder -> clientConfigurationBuilder.readFrom(ReadFrom.REPLICA_PREFERRED);}public static void main(String[] args) {SpringApplication.run(RedisDemoApplication.class, args);System.out.println("启动成功");}}
这篇关于【Redis】多机部署Redis-sentinel的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!