当前位置: 首页 > news >正文

重庆网站建设公司 十年新网站推广

重庆网站建设公司 十年,新网站推广,劲松做网站的公司,WordPress 采集文章 图片使用SpringBoot Data Redis无法连接Redis-Cluster集群 最近在研究系统高并发下的缓存架构,因此自己在自己买的云服务器上搭建好Redis 5.0 版本的集群后,使用springboot的 RedisTemplate连接是发现总是访问不到集群节点。上网百度了发现没有好的解决办法&…

使用SpringBoot Data Redis无法连接Redis-Cluster集群

最近在研究系统高并发下的缓存架构,因此自己在自己买的云服务器上搭建好Redis 5.0 版本的集群后,使用springboot的 RedisTemplate连接是发现总是访问不到集群节点。上网百度了发现没有好的解决办法,没办法只好自己debug。

RedisTemplat封装Lettuce来实现Redis操作

在Spring boot 2.X 之后,SpringBoot 将默认的客户端换成了Lettuce。对于这个客户端的好处,大家可以自行查找。

Lettuce 初始化连接池时,无法连接到Redis-Cluster集群

在使用Jedis创建Redis-Cluster集群连接时,没有任何问题,但是使用了Lettuce客户端创建,就会出现连接超时的问题,具体配置如下:

application.jpg

但是当我启动程序时,Redis客户端访问的IP:PORT 与我在如上图所示配置的IP和端口不一致。这就让我很无奈。于是只好针对日志打印的类去查找相关源码。

最后查找到了这个方法io.lettuce.core.cluster.topology.NodeTopologyView#getOwnPartition

    RedisClusterNode getOwnPartition() {for (RedisClusterNode partition : partitions) {if (partition.is(RedisClusterNode.NodeFlag.MYSELF)) {return partition;}}

在走到这段代码的时候,他会将当前Redis服务器对外的互联网及IP转变为 本机IP。 知道这个问题就好办了。通过查看redis.conf配置文件,我发现了这么一段内容。

########################## CLUSTER DOCKER/NAT support  ######################### In certain deployments, Redis Cluster nodes address discovery fails, because
# addresses are NAT-ted or because ports are forwarded (the typical case is
# Docker and other containers).
#
# In order to make Redis Cluster working in such environments, a static
# configuration where each node knows its public address is needed. The
# following two options are used for this scope, and are:
#
# * cluster-announce-ip
# * cluster-announce-port
# * cluster-announce-bus-port
#
# Each instruct the node about its address, client port, and cluster message
# bus port. The information is then published in the header of the bus packets
# so that other nodes will be able to correctly map the address of the node
# publishing the information.
#
# If the above options are not used, the normal Redis Cluster auto-detection
# will be used instead.
#
# Note that when remapped, the bus port may not be at the fixed offset of
# clients port + 10000, so you can specify any port and bus-port depending
# on how they get remapped. If the bus-port is not set, a fixed offset of
# 10000 will be used as usually.
#
# Example:
#
#cluster-announce-ip 127.0.01
#cluster-announce-port 7001
#cluster-announce-bus-port 6380

我们通过上面的英文解读可以知道这段配置的大致内容

在某些部署中,Redis 群集节点地址发现失败,因为地址是 NAT-ted 或者因为端口被转发(典型的情况是Docker 和其他集装箱)为了让 Redis 集群在这样的环境中工作,静态配置,每个节点都知道它的公共地址是必需的。

我们可以知道 以下这几个配置 是可以静态配置,保证Redis集群工作的时候,可以发现需要的公共地址(这里就是我所配置的外网地址)

因此我将以上两个配置取消了注释,并修改为我对外访问的集群 IP和PORT

cluster-announce-ip 对外访问IP
cluster-announce-port 对外端口

修改完之后,重启集群再启动SpringBoot 程序即可。

小结

有些网上的解决方法,不一定是我们真正需要的,凡是还是要自己去探索和动脑。

最后编辑于:2024-11-11 21:08:21


喜欢的朋友记得点赞、收藏、关注哦!!!

http://www.yayakq.cn/news/69398/

相关文章:

  • wordpress手机双模板做网站需要知道优化吗
  • 网站建设域名未拿到小程序开发和app开发差别
  • 快乐无极网站西部数码网站管理助手 没有d盘
  • 大型网站建设制作个人工作室装修风格
  • 做一份网站的步zou工程建设企业网站
  • 旅游网站建设项目网站上的销售怎么做的
  • 电脑做试卷的网站织梦可以做视频网站么
  • ui设计师工作内容怎么写seo和点击付费的区别
  • 网站版式济南网站开发xywlcn
  • 福建省分行建设银行网站在网站上卖东西怎么做
  • 20m带宽做网站够用吗婚恋网站设计
  • 任县网站制作100 款软件app免费下载大全
  • seo站长工具综合查询家具设计师招聘
  • 网页美工素材百家港 seo服务
  • 怎么做网站子页wordpress new2主题使用
  • 常见的网站首页布局有哪几种做网站都需要哪些软件
  • 静态做网站德州做网站的公司
  • 顺德网站开发企业建设网站好吗
  • 网站ico怎么用网站建设的比较合理的流程
  • 网站建设犭金手指六六壹柒江都区城乡建设局网站马局
  • 建设网站的风险管理开源网站建设实习心得
  • 简述网站推广的方法管理咨询公司是做什么
  • 安装安全狗网站打不开万能视频下载工具
  • 英文域名在哪个网站查询dede 两个网站图片路径
  • 做商城网站哪个好产品推广方式
  • 泰安网站建设公司带广州做seo整站优化公司
  • 做电商网站前端的技术选型是软件定制合同
  • react做网站天津建设网站哪家好
  • 微山县建设局官方网站为什么wordpress安装成了英文版
  • 怎么做直播视频教学视频网站丽水建设网站