springboot连接redis集群超时(云服务器)

Springboot版本为2.7.6

redis pom.xml文件

       <dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-redis</artifactId>
		</dependency>

		<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-pool2</artifactId>
			<version>2.11.1</version>
		</dependency>

properties配置

# Redis 服务器连接密码(默认为空,建议配上密码)
spring.redis.password=
#获取失败最大重定向次数
spring.redis.cluster.max-redirects=3
spring.redis.lettuce.pool.max-active=8
spring.redis.lettuce.pool.max-wait=-1ms
spring.redis.lettuce.pool.min-idle=0
spring.redis.cluster.nodes=公网ip:6379,公网ip:6380,公网ip:6381,公网ip:6382,公网ip:6383,公网ip:6384

集群配置文件

bind 0.0.0.0
daemonize yes
protected-mode no
port 6379
logfile "/myredis/cluster/cluster6379.log"
pidfile /myredis/cluster6379.pid
dir /myredis/cluster
dbfilename dumb6379.rdb
appendonly yes
appendfilename "appendonly6379.aof"
requirepass 自己指定密码
masterauth 自己指定密码
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 5000

# 最主要是加上下面两条
# 云服务器上部署需指定公网ip
cluster-announce-ip 云服务器的ip
# Redis总线端口,用于与其它节点通信
cluster-announce-bus-port 16379

对于redis所需的端口都需要在云服务器上去开通端口(包括总线端口,即端口号加上10000)

启动各个redis服务器

redis-server /集群配置文件

创建集群模式

redis-cli -a 111 --cluster create --cluster-replicas 1 10.0.4.4:6379 10.0.4.4:6380 10.0.4.4:6381 10.0.4.4:6382 10.0.4.4:6383 10.0.4.4:6384

我使用的xshell连接云服务器,使用ifconfig得到的ip就是10.0.4.4

此时springboot连接redis集群就不会报超时问题了。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

海绵宝宝养的的小窝

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值