问题描述

Java Spring Boot的代码在IDE里面跑可以连上 Azure 的 Redis服务,打包成Image放在容器里面跑,就连不上azure的redis服务,错误消息为:

Unable to connect to Redis; nested exception is org.springframework.data.redis.connection.PoolException: 
Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to xxxxxxxxxxxxx.redis.cache.chinacloudapi.cn:6380

问题分析

第一步: 因为容器是Linux的机器上运行,所以第一步是确认客户端与Azure Redis服务之间的网络连通性。可以通过PsPing或者PaPing 测试。

#PsPing
psping xxxxxxxxxxxxx.redis.cache.chinacloudapi.cn:6380 #PaPing
./paping -p 6380 -c 500 xxxxxxxxxxxxx.redis.cache.chinacloudapi.cn

PsPing:https://docs.microsoft.com/zh-cn/sysinternals/downloads/psping

PaPinghttps://code.google.com/archive/p/paping/downloads

PS:在windows的机器上,可以使用 tcping  xxxxxxxxxxxxx.redis.cache.chinacloudapi.cn:6380

第二步: 抓取网络包

sudo tcpdump -i en0 -w xxxx.pcap

从网络包中验证是否是与TLS协议,版本错误相关。如果能够查看TCP及TLSv1.2的Application Data传递,则表明网络连通性,TLS协议都没有问题。

经过以上分析后,就可以定位问题一定发生在应用代码中,然后就是通过Demo来复现及定位问题。比如:排除项目中各种组件间的相互干扰,使用Azure官网中的简单Demo来测试联通问题。如上Jedis连接Redis的代码片段:

App.java

package example.demo;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisShardInfo; /**
* Redis test
*
*/
public class App
{
public static void main( String[] args )
{ boolean useSsl = true;
String cacheHostname = "redis host";
String cachekey = "key"; // Connect to the Azure Cache for Redis over the TLS/SSL port using the key.
JedisShardInfo shardInfo = new JedisShardInfo(cacheHostname, 6380, useSsl);
shardInfo.setPassword(cachekey); /* Use your access key. */
Jedis jedis = new Jedis(shardInfo); // Perform cache operations using the cache connection object... // Simple PING command
System.out.println( "\nCache Command : Ping" );
System.out.println( "Cache Response : " + jedis.ping()); // Simple get and put of integral data types into the cache
System.out.println( "\nCache Command : GET Message" );
System.out.println( "Cache Response : " + jedis.get("Message")); System.out.println( "\nCache Command : SET Message" );
System.out.println( "Cache Response : " + jedis.set("Message", "Hello! The cache is working from Java!")); // Demonstrate "SET Message" executed as expected...
System.out.println( "\nCache Command : GET Message" );
System.out.println( "Cache Response : " + jedis.get("Message")); // Get the client list, useful to see if connection list is growing...
System.out.println( "\nCache Command : CLIENT LIST" );
System.out.println( "Cache Response : " + jedis.clientList()); jedis.close();
}
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>example.demo</groupId>
<artifactId>redistest</artifactId>
<version>1.0</version> <name>redistest</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties> <dependencies>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.2.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies> <build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

参考资料

使用 PsPing & PaPing 进行 TCP 端口连通性测试: https://docs.azure.cn/zh-cn/articles/azure-operations-guide/virtual-network/aog-virtual-network-tcp-psping-paping-connectivity#paping

【Azure Redis 缓存】定位Java Spring Boot 使用 Jedis 或 Lettuce 无法连接到 Redis的网络连通性步骤的更多相关文章

  1. 【Azure 应用服务】App Service For Linux 部署Java Spring Boot应用后,查看日志文件时的疑惑

    编写Java Spring Boot应用,通过配置logging.path路径把日志输出在指定的文件夹中. 第一步:通过VS Code创建一个空的Spring Boot项目 第二步:在applicat ...

  2. Java Spring Boot VS .NetCore (一)来一个简单的 Hello World

    系列文章 Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filte ...

  3. Java Spring Boot VS .NetCore (二)实现一个过滤器Filter

    Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...

  4. Java Spring Boot VS .NetCore (三)Ioc容器处理

    Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...

  5. Java Spring Boot VS .NetCore (四)数据库操作 Spring Data JPA vs EFCore

    Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...

  6. Java Spring Boot VS .NetCore (五)MyBatis vs EFCore

    Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...

  7. Java Spring Boot VS .NetCore (六) UI thymeleaf vs cshtml

    Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...

  8. Java Spring Boot VS .NetCore (七) 配置文件

    Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...

  9. Java Spring Boot VS .NetCore (八) Java 注解 vs .NetCore Attribute

    Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...

  10. Java Spring Boot VS .NetCore (九) Spring Security vs .NetCore Security

    Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...

随机推荐

  1. WebAssembly入门笔记[1]:与JavaScript的交互

    前一阵子利用Balazor开发了一个NuGet站点,对WebAssembly进行了初步的了解,觉得挺有意思.在接下来的一系列文章中,我们将通过实例演示的方式介绍WebAssembly的一些基本概念和编 ...

  2. Docker与虚拟化技术浅析第一弹之docker与Kubernetes

    1 前言 Docker是一个开源的引擎,可以轻松地为任何应用创建一个轻量级的. 可移植的.自给自足的容器.开发者在笔记本电脑上编译测试通过的容器可以批量地在生产环境中部署,包括VMs (虚拟机).ba ...

  3. 手把手教学小型金融知识图谱构建:量化分析、图数据库neo4j、图算法、关系预测、命名实体识别、Cypher Cheetsheet详细教学等

    手把手教学小型金融知识图谱构建:量化分析.图数据库neo4j.图算法.关系预测.命名实体识别.Cypher Cheetsheet详细教学等 效果预览: 1. 知识图谱存储方式 知识图谱存储方式主要包含 ...

  4. MySQL【四】---案例实战{拆分多表、外键创建等}

    1.准备数据 数据准备 create database jing_dong charset = utf8mb4; 创建一个商品goods数据表: create table goods( id int ...

  5. MySQL【五】与python交互

    1.安装pymysql 安装pymysql pip install pymysql 2.游标(cursor)的使用 cursor,就是一个标识,用来标识数据可以理解成数组中的下标  . 一.声明一个游 ...

  6. spark读取空orc文件时报错java.lang.RuntimeException: serious problem at OrcInputFormat.generateSplitsInfo

    问题复现: G:\bigdata\spark-2.3.3-bin-hadoop2.7\bin>spark-shell 2020-12-26 10:20:48 WARN NativeCodeLoa ...

  7. requests模块的高级应用

    requests抓取数据报错 - HttpConnectinPool: - 原因: - 1.短时间内发起了高频的请求导致ip被禁 - 2.http连接池中的连接资源被耗尽 - 解决: - 1.代理 - ...

  8. 嫌 OSS 查询太慢?看我们如何将速度提升 10 倍!

    背景 HDFS 是 Hadoop 生态的默认存储系统,很多数据分析和管理工具都是基于它的 API 设计和实现的.但 HDFS 是为传统机房设计的,在云上维护 HDFS 一点也不轻松,需要投入不少人力进 ...

  9. 永久解决 WSL vm.max_map_count 65530 is too low 的问题

    问题 在使用基于 WSL 的 Docker 的时候,启动 ES 总是会出现 vm.max_map_count 65530 is too low 问题,导致容器无法启动,网上答案基本就两种,例如 sta ...

  10. NC15291 幸运数字Ⅱ

    题目链接 题目 题目描述 定义一个数字为幸运数字当且仅当它的所有数位都是4或者7. 比如说,47.744.4都是幸运数字而5.17.467都不是. 定义next(x)为大于等于x的第一个幸运数字.给定 ...