Spring Boot应用部署在Heroku上时未能正确注册到Eureka。

huangapple 未分类评论55阅读模式
英文:

Spring Boot apps deployed on Heroku are not properly registered with Eureka

问题

我有几个部署在Heroku上的Spring Boot应用程序。我已经将以下服务注册到Eureka中:

  • configserver
  • eureka-server
  • gateway
  • uaa

configserver、gateway和uaa会注册自己,但是它们注册到Eureka时出现了问题,注册的方式并不正确。当我执行请求到gateway(POST https://APP_NAME.herokuapp.com/auth/login)时,响应是Uaa服务503 Service Unavailable。

Gateway日志:

- heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/auth/login"

- DynamicServerListLoadBalancer for client uaa initialized:
  DynamicServerListLoadBalancer:{NFLoadBalancer:name=uaa,current list
  of Servers=[IP_ADDRESS:PORT],Load balancer stats=Zone stats:
  {defaultzone=[Zone:defaultzone;	Instance count:1;	Active connections
  count: 0;	Circuit breaker tripped count: 0;	Active connections per
  server: 0.0;]

- Server stats: [[Server:IP_ADDRESS:PORT;	Zone:defaultZone;	Total
  Requests:0;	Successive connection failure:0;	Total blackout
  seconds:0;	Last connection made:Thu Jan 01 00:00:00 UTC 1970;	First
  connection made: Thu Jan 01 00:00:00 UTC 1970;	Active
  Connections:0;	total failure count in last (1000) msecs:0;	average
  resp time:0.0;	90 percentile resp time:0.0;	95 percentile resp
  time:0.0;	min resp time:0.0;	max resp time:0.0;	stddev resp time:0.0]

这是我的Eureka服务器配置:
application-prod.yml

eureka:
  instance:
    hostname: ${DOMAIN_NAME}
    status-page-url-path: ${management.endpoints.web.base-path}/info
    health-check-url-path: ${management.endpoints.web.base-path}/health
    lease-renewal-interval-in-seconds: 5
    lease-expiration-duration-in-seconds: 10
    metadata-map:
      profile: ${spring.profiles.active}
      version: #project.version#
      git-version: ${git.commit.id.describe:}
      git-commit: ${git.commit.id.abbrev:}
      git-branch: ${git.branch:}
  client:
    fetch-registry: false
    register-with-eureka: false
    instance-info-replication-interval-seconds: 10
    registry-fetch-interval-seconds: 10
    service-url:
      defaultZone: http://admin:${spring.security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/

这是我的Uaa配置:
application-prod.yml

eureka:
  client:
    service-url:
      defaultZone: ${application.register.discovery-url}/eureka/
    instance-info-replication-interval-seconds: 10
    registry-fetch-interval-seconds: 10
  instance:
    hostname: ${DOMAIN_NAME:localhost}
    appname: uaa
    prefer-ip-address: true
    instanceId: uaa:${spring.application.instance-id:${random.value}}
    status-page-url-path: ${management.endpoints.web.base-path}/info
    health-check-url-path: ${management.endpoints.web.base-path}/health
    lease-renewal-interval-in-seconds: 5
    lease-expiration-duration-in-seconds: 10
    metadata-map:
      profile: ${spring.profiles.active}
      version: #project.version#
      git-version: ${git.commit.id.describe:}
      git-commit: ${git.commit.id.abbrev:}
      git-branch: ${git.branch:}

这是我的Gateway配置:
application-prod.yml

eureka:
  client:
    service-url:
      defaultZone: ${application.register.discovery-url}/eureka/
    instance-info-replication-interval-seconds: 10
    registry-fetch-interval-seconds: 10
  instance:
    hostname: ${DOMAIN_NAME:localhost}
    appname: gateway
    prefer-ip-address: true
    instance-id: gateway:${spring.application.instance-id:${random.value}}
    status-page-url-path: ${management.endpoints.web.base-path}/info
    health-check-url-path: ${management.endpoints.web.base-path}/health
    lease-renewal-interval-in-seconds: 5
    lease-expiration-duration-in-seconds: 10
    metadata-map:
      profile: ${spring.profiles.active}
      version: #project.version#
      git-version: ${git.commit.id.describe:}
      git-commit: ${git.commit.id.abbrev:}
      git-branch: ${git.branch:}

所有服务的POM:
Eureka客户端和服务器:

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.2.6.RELEASE</version>
  <relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
  <java.version>1.8</java.version>
  <spring-cloud.version>Hoxton.SR4</spring-cloud.version>
</properties>
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-dependencies</artifactId>
      <version>${spring-cloud.version}</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

仅Eureka服务器:

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

Uaa和gateway之间的连接从未建立过,我猜问题出在将eureka客户端注册到eureka时。我也尝试了修改此属性eureka.instance.prefer-ip-address: false,但是eureka客户端会注册为APP_NAME.herokuapp.com:PORT,这使得它们要么无法被发现,要么无法查找或调用其他已注册的服务。

注意:

所有服务已经在eureka服务器上注册

eureka.instance.prefer-ip-address: false
ribbon的服务器列表=[APP_NAME.herokuapp.com:PORT]。

eureka.instance.prefer-ip-address: true
ribbon的服务器列表=[IP_ADDRESS:PORT]。

DOMAIN_NAME = APP_NAME.herokuapp.com 对于所有服务。

我执行了对IP_ADDRESS的ping测试,但没有响应。

我已经使用Heroku账户进行了测试。

[1

英文:

I have several Spring Boot apps deployed to Heroku. I have the following services registered with Eureka:

  • configserver
  • eureka-server
  • gateway
  • uaa
    The configserver, gateway and uaa registers themselves, but it registers itself with Eureka but not rightly. When I executed the request to the gateway (POST https://APP_NAME.herokuapp.com/auth/login), the response is Uaa service 503 Service Unavailable.

Gateway Log:

- heroku[router]: at=error code=H12 desc=&quot;Request timeout&quot; method=POST path=&quot;/auth/login&quot;
    
- DynamicServerListLoadBalancer for client uaa initialized:
  DynamicServerListLoadBalancer:{NFLoadBalancer:name=uaa,current list
  of Servers=[IP_ADDRESS:PORT],Load balancer stats=Zone stats:
  {defaultzone=[Zone:defaultzone;	Instance count:1;	Active connections
  count: 0;	Circuit breaker tripped count: 0;	Active connections per
  server: 0.0;]
    
- Server stats: [[Server:IP_ADDRESS:PORT;	Zone:defaultZone;	Total
  Requests:0;	Successive connection failure:0;	Total blackout
  seconds:0;	Last connection made:Thu Jan 01 00:00:00 UTC 1970;	First
  connection made: Thu Jan 01 00:00:00 UTC 1970;	Active
  Connections:0;	total failure count in last (1000) msecs:0;	average
  resp time:0.0;	90 percentile resp time:0.0;	95 percentile resp
  time:0.0;	min resp time:0.0;	max resp time:0.0;	stddev resp time:0.0]

This is my configuration for Eureka-server:
application-prod.yml

eureka:
  instance:
    hostname: ${DOMAIN_NAME}
    status-page-url-path: ${management.endpoints.web.base-path}/info
    health-check-url-path: ${management.endpoints.web.base-path}/health
    lease-renewal-interval-in-seconds: 5
    lease-expiration-duration-in-seconds: 10
    metadata-map:
      profile: ${spring.profiles.active}
      version: #project.version#
      git-version: ${git.commit.id.describe:}
      git-commit: ${git.commit.id.abbrev:}
      git-branch: ${git.branch:}
  client:
    fetch-registry: false
    register-with-eureka: false
    instance-info-replication-interval-seconds: 10
    registry-fetch-interval-seconds: 10
    service-url:
      defaultZone: http://admin:${spring.security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/

This is my configuration for Uaa:
application-prod.yml

eureka:
  client:
    service-url:
      defaultZone: ${application.register.discovery-url}/eureka/
    instance-info-replication-interval-seconds: 10
    registry-fetch-interval-seconds: 10
  instance:
    hostname: ${DOMAIN_NAME:localhost}
    appname: uaa
    prefer-ip-address: true
    instanceId: uaa:${spring.application.instance-id:${random.value}}
    status-page-url-path: ${management.endpoints.web.base-path}/info
    health-check-url-path: ${management.endpoints.web.base-path}/health
    lease-renewal-interval-in-seconds: 5
    lease-expiration-duration-in-seconds: 10
    metadata-map:
      profile: ${spring.profiles.active}
      version: #project.version#
      git-version: ${git.commit.id.describe:}
      git-commit: ${git.commit.id.abbrev:}
      git-branch: ${git.branch:}

This is my configuration for Gateway:
application-prod.yml

eureka:
  client:
    service-url:
      defaultZone: ${application.register.discovery-url}/eureka/
    instance-info-replication-interval-seconds: 10
    registry-fetch-interval-seconds: 10
  instance:
    hostname: ${DOMAIN_NAME:localhost}
    appname: gateway
    prefer-ip-address: true
    instance-id: gateway:${spring.application.instance-id:${random.value}}
    status-page-url-path: ${management.endpoints.web.base-path}/info
    health-check-url-path: ${management.endpoints.web.base-path}/health
    lease-renewal-interval-in-seconds: 5
    lease-expiration-duration-in-seconds: 10
    metadata-map:
      profile: ${spring.profiles.active}
      version: #project.version#
      git-version: ${git.commit.id.describe:}
      git-commit: ${git.commit.id.abbrev:}
      git-branch: ${git.branch:}

POM all services:
Eureka clients and server:

&lt;parent&gt;
 &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
 &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
 &lt;version&gt;2.2.6.RELEASE&lt;/version&gt;
 &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
&lt;/parent&gt;
&lt;properties&gt;
 &lt;java.version&gt;1.8&lt;/java.version&gt;
 &lt;spring-cloud.version&gt;Hoxton.SR4&lt;/spring-cloud.version&gt;
 &lt;/properties&gt;
&lt;dependency&gt;
 &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
 &lt;artifactId&gt;spring-cloud-starter-netflix-eureka-client&lt;/artifactId&gt;
&lt;/dependency&gt;

&lt;dependencyManagement&gt;
 &lt;dependencies&gt;
  &lt;dependency&gt;
	&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
	&lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;
	&lt;version&gt;${spring-cloud.version}&lt;/version&gt;
	&lt;type&gt;pom&lt;/type&gt;
	&lt;scope&gt;import&lt;/scope&gt;
   &lt;/dependency&gt;
 &lt;/dependencies&gt;
&lt;/dependencyManagement&gt;

Only Eureka server:

&lt;dependency&gt;
 &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
 &lt;artifactId&gt;spring-cloud-starter-netflix-eureka-server&lt;/artifactId&gt;
&lt;/dependency&gt;

Uaa and gateway connection was never established, I guess the problem is when registering eureka-clients with eureka. Also I have try modifing this property eureka.instance.prefer-ip-address: false and the eureka-clients are registers as APP_NAME.herokuapp.com:PORT which makes it either non-discoverable or unable to lookup or call other registered services.

NOTE:

All service alrady registered with eureka server

eureka.instance.prefer-ip-address: false
list of Servers=[APP_NAME.herokuapp.com:PORT] of ribbon.

eureka.instance.prefer-ip-address: true
list of Servers=[IP_ADDRESS:PORT] of ribbon

DOMAIN_NAME = APP_NAME.herokuapp.com for all services.

I execute ping to IP_ADDRESS and no response

I have Use Account Heroku for test.

huangapple
  • 本文由 发表于 2020年7月27日 11:00:44
  • 转载请务必保留本文链接:https://java.coder-hub.com/63108105.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定