eureka 客户端 异常 Invalid eureka server URI: /; removing from the server pool 分析解决
2017-09-30 10:25
2061 查看
问题描述:
Spring cloud 项目
注册中心 Eureka,采用高可用方式 开启两个eureka server
http://IP:8761/eureka/
http://IP:8762/eureka/
客户端每隔5分钟报info log
Invalid eureka server URI: /; removing from the server pool
问题分析:
一开始没头绪,只能分析 eureka 客户端源码
info 信息出自
private List<AwsEndpoint> getClusterEndpointsFromConfig() {
String[] availZones = clientConfig.getAvailabilityZones(clientConfig.getRegion());
String myZone = InstanceInfo.getZone(availZones, myInstanceInfo);
Map<String, List<String>> serviceUrls = EndpointUtils
.getServiceUrlsMapFromConfig(clientConfig, myZone, clientConfig.shouldPreferSameZoneEureka());
List<AwsEndpoint> endpoints = new ArrayList<>();
for (String zone : serviceUrls.keySet()) {
for (String url : serviceUrls.get(zone)) {
try {
endpoints.add(new AwsEndpoint(url, getRegion(), zone));
} catch (Exception ignore) {
logger.warn("Invalid eureka server URI: {}; removing from the server pool", url);
}
}
}
if (logger.isDebugEnabled()) {
logger.debug("Config resolved to {}", endpoints);
}
if (endpoints.isEmpty()) {
logger.error("Cannot resolve to any endpoints from provided configuration: {}", serviceUrls);
}
return endpoints;
}
根因
public static Map<String, List<String>> getServiceUrlsMapFromConfig(EurekaClientConfig clientConfig, String instanceZone, boolean preferSameZone) {
Map<String, List<String>> orderedUrls = new LinkedHashMap<>();
String region = getRegion(clientConfig);
String[] availZones = clientConfig.getAvailabilityZones(clientConfig.getRegion());
if (availZones == null || availZones.length == 0) {
availZones = new String[1];
availZones[0] = DEFAULT_ZONE;
}
logger.debug("The availability zone for the given region {} are {}", region, Arrays.toString(availZones));
int myZoneOffset = getZoneOffset(instanceZone, preferSameZone, availZones);
String zone = availZones[myZoneOffset];
List<String> serviceUrls = clientConfig.getEurekaServerServiceUrls(zone);
if (serviceUrls != null) {
orderedUrls.put(zone, serviceUrls);
}
...
此方法会返回一个map 解析配置文件
{defaultZone=[http://IP:8761/eureka/, http://IP:8762/eureka/,/]}
源配置
defaultZone: http://IP:8761/eureka/,http://IP:8762/eureka/,
问题就出在配置后面多了一个, 解析时候 多了个路径 /
解决方法:
defaultZone: http://IP:8761/eureka/,http://IP:8762/eureka/,
去掉末尾,
defaultZone: http://IP:8761/eureka/,http://IP:8762/eureka/
注意事项:eureka 客户端会根据 [b]defaultZone 中配置用,去解析当做server [/b]
Spring cloud 项目
注册中心 Eureka,采用高可用方式 开启两个eureka server
http://IP:8761/eureka/
http://IP:8762/eureka/
客户端每隔5分钟报info log
Invalid eureka server URI: /; removing from the server pool
问题分析:
一开始没头绪,只能分析 eureka 客户端源码
info 信息出自
private List<AwsEndpoint> getClusterEndpointsFromConfig() {
String[] availZones = clientConfig.getAvailabilityZones(clientConfig.getRegion());
String myZone = InstanceInfo.getZone(availZones, myInstanceInfo);
Map<String, List<String>> serviceUrls = EndpointUtils
.getServiceUrlsMapFromConfig(clientConfig, myZone, clientConfig.shouldPreferSameZoneEureka());
List<AwsEndpoint> endpoints = new ArrayList<>();
for (String zone : serviceUrls.keySet()) {
for (String url : serviceUrls.get(zone)) {
try {
endpoints.add(new AwsEndpoint(url, getRegion(), zone));
} catch (Exception ignore) {
logger.warn("Invalid eureka server URI: {}; removing from the server pool", url);
}
}
}
if (logger.isDebugEnabled()) {
logger.debug("Config resolved to {}", endpoints);
}
if (endpoints.isEmpty()) {
logger.error("Cannot resolve to any endpoints from provided configuration: {}", serviceUrls);
}
return endpoints;
}
根因
public static Map<String, List<String>> getServiceUrlsMapFromConfig(EurekaClientConfig clientConfig, String instanceZone, boolean preferSameZone) {
Map<String, List<String>> orderedUrls = new LinkedHashMap<>();
String region = getRegion(clientConfig);
String[] availZones = clientConfig.getAvailabilityZones(clientConfig.getRegion());
if (availZones == null || availZones.length == 0) {
availZones = new String[1];
availZones[0] = DEFAULT_ZONE;
}
logger.debug("The availability zone for the given region {} are {}", region, Arrays.toString(availZones));
int myZoneOffset = getZoneOffset(instanceZone, preferSameZone, availZones);
String zone = availZones[myZoneOffset];
List<String> serviceUrls = clientConfig.getEurekaServerServiceUrls(zone);
if (serviceUrls != null) {
orderedUrls.put(zone, serviceUrls);
}
...
此方法会返回一个map 解析配置文件
{defaultZone=[http://IP:8761/eureka/, http://IP:8762/eureka/,/]}
源配置
defaultZone: http://IP:8761/eureka/,http://IP:8762/eureka/,
问题就出在配置后面多了一个, 解析时候 多了个路径 /
解决方法:
defaultZone: http://IP:8761/eureka/,http://IP:8762/eureka/,
去掉末尾,
defaultZone: http://IP:8761/eureka/,http://IP:8762/eureka/
注意事项:eureka 客户端会根据 [b]defaultZone 中配置用,去解析当做server [/b]
相关文章推荐
- Redis客户端连接异常:Could not get resource from the pool 解决办法
- Redis客户端连接异常:Could not get resource from the pool 解决办法
- Redis客户端连接异常:Could not get resource from the pool 解决办法
- Redis一个异常的解决办法,异常描述:Could not get a resource from the pool
- redis中 Could not get a resource from the pool 异常解决
- Redis一个异常的解决办法,异常描述:Could not get a resource from the pool
- Redis一个异常的解决办法,异常描述:Could not get a resource from the pool
- Redis一个异常的解决办法,异常描述:Could not get a resource from the pool
- 解决:The proxy server received an invalid response from an upstream server
- Java Jedis远程连接redis异常解决思路,异常描述:Could not get a resource from the pool && connect timed out
- redis---Redis一个异常的解决办法,异常描述:Could not get a resource from the pool
- The server encountered an internal error that prevented it from fulfilling this request的一种解决办法
- C#中异常:“The type initializer to throw an exception(类型初始值设定项引发异常)”的简单分析与解决方法
- The proxy server received an invalid response from an upstream server.(错误原因)
- Tomcat:The selected server is enabled 异常解决办法
- C#中异常:“The type initializer to throw an exception(类型初始值设定项引发异常)”的简单分析与解决方法
- 两种解决异常:“The last packet sent successfully to the server was 0 milliseconds ago. ”的办法
- java.sql.SQLException: null, message from server: “Host ‘xxx’ is not allowed to connect异常解决
- PhoneGap中"unable to download archive from the server. "警告的解决方法
- github安装问题解决"Unable to retrieve your user info from the server"