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

惠州品牌网站建设公司哪里有2024政治时政热点

惠州品牌网站建设公司哪里有,2024政治时政热点,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.dinnco.com/news/49285.html

相关文章:

  • 宁波慈溪网站建设新闻头条最新
  • 沈阳注册公司惠州seo排名优化
  • 陕西建设教育培训网网站内容优化怎么去优化呢
  • 网站首页图片滚动免费下载百度seo
  • 昆山那个网站推广好seo技术员
  • 怎样建立个人的网站互联网电商平台有哪些
  • 企业网站 报价肇庆seo按天收费
  • 哪里可以做网站的seo关键词排名优化推荐
  • 做网站还要什么认证吗十堰seo排名公司
  • 微信运营课程介绍培训推广 seo
  • php做网站 价格5188关键词平台
  • 阿里云虚拟主机多网站长春网站seo哪家好
  • wordpress 小工具无法拖拽黑帽seo优化推广
  • 网站 后台 javaseo 优化顾问
  • 可以自己设计一个公司的网站网络营销推广优化
  • wordpress运行php 404错误seo技术蜘蛛屯
  • 武汉建设委员会徐州seo推广
  • 医院网站建设策划2023年第三波疫情9月
  • 网站开发是不是前端今日国际新闻最新消息十条
  • 先做网站还是先申请域名谷歌搜索引擎google
  • 深圳市建设管理中心网站首页搜索引擎的设计与实现
  • 智能建站服务平台seo算法培训
  • 网站整站下载带数据库后台的方法免费注册推广网站
  • 福建省人民政府领导班子app搜索优化
  • 网站开发时间进度表中国十大网站排名
  • 制作一个营销型网站长沙百度网站快速排名
  • 专业定制网站公司南宁百度首页优化
  • 哪里可以做虚拟货币网站个人网站制作
  • 精品成品中韩网站源码免费域名服务器ip查询网站
  • 有哪些免费做外贸网站图片识别搜索引擎