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

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

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日志:

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

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

  1. eureka:
  2. instance:
  3. hostname: ${DOMAIN_NAME}
  4. status-page-url-path: ${management.endpoints.web.base-path}/info
  5. health-check-url-path: ${management.endpoints.web.base-path}/health
  6. lease-renewal-interval-in-seconds: 5
  7. lease-expiration-duration-in-seconds: 10
  8. metadata-map:
  9. profile: ${spring.profiles.active}
  10. version: #project.version#
  11. git-version: ${git.commit.id.describe:}
  12. git-commit: ${git.commit.id.abbrev:}
  13. git-branch: ${git.branch:}
  14. client:
  15. fetch-registry: false
  16. register-with-eureka: false
  17. instance-info-replication-interval-seconds: 10
  18. registry-fetch-interval-seconds: 10
  19. service-url:
  20. defaultZone: http://admin:${spring.security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/

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

  1. eureka:
  2. client:
  3. service-url:
  4. defaultZone: ${application.register.discovery-url}/eureka/
  5. instance-info-replication-interval-seconds: 10
  6. registry-fetch-interval-seconds: 10
  7. instance:
  8. hostname: ${DOMAIN_NAME:localhost}
  9. appname: uaa
  10. prefer-ip-address: true
  11. instanceId: uaa:${spring.application.instance-id:${random.value}}
  12. status-page-url-path: ${management.endpoints.web.base-path}/info
  13. health-check-url-path: ${management.endpoints.web.base-path}/health
  14. lease-renewal-interval-in-seconds: 5
  15. lease-expiration-duration-in-seconds: 10
  16. metadata-map:
  17. profile: ${spring.profiles.active}
  18. version: #project.version#
  19. git-version: ${git.commit.id.describe:}
  20. git-commit: ${git.commit.id.abbrev:}
  21. git-branch: ${git.branch:}

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

  1. eureka:
  2. client:
  3. service-url:
  4. defaultZone: ${application.register.discovery-url}/eureka/
  5. instance-info-replication-interval-seconds: 10
  6. registry-fetch-interval-seconds: 10
  7. instance:
  8. hostname: ${DOMAIN_NAME:localhost}
  9. appname: gateway
  10. prefer-ip-address: true
  11. instance-id: gateway:${spring.application.instance-id:${random.value}}
  12. status-page-url-path: ${management.endpoints.web.base-path}/info
  13. health-check-url-path: ${management.endpoints.web.base-path}/health
  14. lease-renewal-interval-in-seconds: 5
  15. lease-expiration-duration-in-seconds: 10
  16. metadata-map:
  17. profile: ${spring.profiles.active}
  18. version: #project.version#
  19. git-version: ${git.commit.id.describe:}
  20. git-commit: ${git.commit.id.abbrev:}
  21. git-branch: ${git.branch:}

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

  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>2.2.6.RELEASE</version>
  5. <relativePath/> <!-- lookup parent from repository -->
  6. </parent>
  7. <properties>
  8. <java.version>1.8</java.version>
  9. <spring-cloud.version>Hoxton.SR4</spring-cloud.version>
  10. </properties>
  11. <dependency>
  12. <groupId>org.springframework.cloud</groupId>
  13. <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  14. </dependency>
  15. <dependencyManagement>
  16. <dependencies>
  17. <dependency>
  18. <groupId>org.springframework.cloud</groupId>
  19. <artifactId>spring-cloud-dependencies</artifactId>
  20. <version>${spring-cloud.version}</version>
  21. <type>pom</type>
  22. <scope>import</scope>
  23. </dependency>
  24. </dependencies>
  25. </dependencyManagement>

仅Eureka服务器:

  1. <dependency>
  2. <groupId>org.springframework.cloud</groupId>
  3. <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
  4. </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:

  1. - heroku[router]: at=error code=H12 desc=&quot;Request timeout&quot; method=POST path=&quot;/auth/login&quot;
  2. - DynamicServerListLoadBalancer for client uaa initialized:
  3. DynamicServerListLoadBalancer:{NFLoadBalancer:name=uaa,current list
  4. of Servers=[IP_ADDRESS:PORT],Load balancer stats=Zone stats:
  5. {defaultzone=[Zone:defaultzone; Instance count:1; Active connections
  6. count: 0; Circuit breaker tripped count: 0; Active connections per
  7. server: 0.0;]
  8. - Server stats: [[Server:IP_ADDRESS:PORT; Zone:defaultZone; Total
  9. Requests:0; Successive connection failure:0; Total blackout
  10. seconds:0; Last connection made:Thu Jan 01 00:00:00 UTC 1970; First
  11. connection made: Thu Jan 01 00:00:00 UTC 1970; Active
  12. Connections:0; total failure count in last (1000) msecs:0; average
  13. resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp
  14. 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

  1. eureka:
  2. instance:
  3. hostname: ${DOMAIN_NAME}
  4. status-page-url-path: ${management.endpoints.web.base-path}/info
  5. health-check-url-path: ${management.endpoints.web.base-path}/health
  6. lease-renewal-interval-in-seconds: 5
  7. lease-expiration-duration-in-seconds: 10
  8. metadata-map:
  9. profile: ${spring.profiles.active}
  10. version: #project.version#
  11. git-version: ${git.commit.id.describe:}
  12. git-commit: ${git.commit.id.abbrev:}
  13. git-branch: ${git.branch:}
  14. client:
  15. fetch-registry: false
  16. register-with-eureka: false
  17. instance-info-replication-interval-seconds: 10
  18. registry-fetch-interval-seconds: 10
  19. service-url:
  20. defaultZone: http://admin:${spring.security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/

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

  1. eureka:
  2. client:
  3. service-url:
  4. defaultZone: ${application.register.discovery-url}/eureka/
  5. instance-info-replication-interval-seconds: 10
  6. registry-fetch-interval-seconds: 10
  7. instance:
  8. hostname: ${DOMAIN_NAME:localhost}
  9. appname: uaa
  10. prefer-ip-address: true
  11. instanceId: uaa:${spring.application.instance-id:${random.value}}
  12. status-page-url-path: ${management.endpoints.web.base-path}/info
  13. health-check-url-path: ${management.endpoints.web.base-path}/health
  14. lease-renewal-interval-in-seconds: 5
  15. lease-expiration-duration-in-seconds: 10
  16. metadata-map:
  17. profile: ${spring.profiles.active}
  18. version: #project.version#
  19. git-version: ${git.commit.id.describe:}
  20. git-commit: ${git.commit.id.abbrev:}
  21. git-branch: ${git.branch:}

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

  1. eureka:
  2. client:
  3. service-url:
  4. defaultZone: ${application.register.discovery-url}/eureka/
  5. instance-info-replication-interval-seconds: 10
  6. registry-fetch-interval-seconds: 10
  7. instance:
  8. hostname: ${DOMAIN_NAME:localhost}
  9. appname: gateway
  10. prefer-ip-address: true
  11. instance-id: gateway:${spring.application.instance-id:${random.value}}
  12. status-page-url-path: ${management.endpoints.web.base-path}/info
  13. health-check-url-path: ${management.endpoints.web.base-path}/health
  14. lease-renewal-interval-in-seconds: 5
  15. lease-expiration-duration-in-seconds: 10
  16. metadata-map:
  17. profile: ${spring.profiles.active}
  18. version: #project.version#
  19. git-version: ${git.commit.id.describe:}
  20. git-commit: ${git.commit.id.abbrev:}
  21. git-branch: ${git.branch:}

POM all services:
Eureka clients and server:

  1. &lt;parent&gt;
  2. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  3. &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
  4. &lt;version&gt;2.2.6.RELEASE&lt;/version&gt;
  5. &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
  6. &lt;/parent&gt;
  7. &lt;properties&gt;
  8. &lt;java.version&gt;1.8&lt;/java.version&gt;
  9. &lt;spring-cloud.version&gt;Hoxton.SR4&lt;/spring-cloud.version&gt;
  10. &lt;/properties&gt;
  11. &lt;dependency&gt;
  12. &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
  13. &lt;artifactId&gt;spring-cloud-starter-netflix-eureka-client&lt;/artifactId&gt;
  14. &lt;/dependency&gt;
  15. &lt;dependencyManagement&gt;
  16. &lt;dependencies&gt;
  17. &lt;dependency&gt;
  18. &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
  19. &lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;
  20. &lt;version&gt;${spring-cloud.version}&lt;/version&gt;
  21. &lt;type&gt;pom&lt;/type&gt;
  22. &lt;scope&gt;import&lt;/scope&gt;
  23. &lt;/dependency&gt;
  24. &lt;/dependencies&gt;
  25. &lt;/dependencyManagement&gt;

Only Eureka server:

  1. &lt;dependency&gt;
  2. &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
  3. &lt;artifactId&gt;spring-cloud-starter-netflix-eureka-server&lt;/artifactId&gt;
  4. &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:

确定