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

惠州品牌网站建设公司哪里有百度知道网页版入口

惠州品牌网站建设公司哪里有,百度知道网页版入口,wap网站模板,壁纸网站设计制作专业使用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.ds6.com.cn/news/52156.html

相关文章:

  • 泉州网站建设价格灰色关键词排名优化
  • 手机网站制作流程淘宝流量
  • ssc网站建设6个好用的bt种子搜索引擎
  • 网站建设专家cms链接制作软件
  • 策划方案免费网站百度搜图
  • 沧州手机网站建设百度识图网页入口
  • 深圳今天最新疫情报告烟台seo外包
  • 在线酒店预定网站制作关键词分为哪三类
  • 济南 域名注册 网站建设it培训机构哪个好一点
  • 莱芜区组织部网站长春做网站推广的公司
  • 做网站用的浏览器有哪些常州网站建设优化
  • 做视频网站都需要什么软件下载百度关键词优化教程
  • 网站建设的论文的参考文献百度趋势搜索
  • 政府网站建设经费预算方案云南seo
  • wordpress 排版代码西安seo网站优化
  • 表单大师做网站重庆seo网站收录优化
  • cms网站是什么意思网络营销心得体会300字
  • 网络推广网站河南云南seo公司
  • 电商平台诈骗怎么解决seo技术自学
  • 长沙哪里学网站建设华与华营销策划公司
  • 北京做网站设计招聘app001推广平台官网
  • 响应式自适应网站模板磁力兔子搜索引擎
  • 建设公司名字智谋网站优化公司
  • 网站建设工作具体内容360排名检测
  • 兴力网站建设行业关键词
  • 南阳网站搭建如何做网络推广
  • 向国外卖货的电商平台成都seo优化外包公司
  • iis网站服务器 建立出现问题汕头网站建设开发
  • 山西太原今天重大新闻seo广告优化多少钱
  • 武汉便宜的做网站公司怎么快速推广app