基于 Eureka 的配置服务器破坏执行器端点

Eureka based configuration server breaking actuator endpoints

我将我的服务设置为使用 spring 基于云 eureka 的配置服务器。

版本信息:spring云1.0.1.RELEASE

当我将它设置为固定端点时,我可以看到它获得了正确的配置文件,并且我可以访问执行器端点,如健康、信息等。所以 .../manage/info returns正确的信息。

然而,当我将其设置为使用发现时,相同的执行器端点在尝试访问它们时超时。

在每种情况下都会检索并下载配置文件(包括日志文件)。

我设置配置服务器和书签服务(使用配置服务器的服务)的方式有问题吗?

我的配置服务器设置如下:

server:
  port: 8888
  contextPath: /configurationservice

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  instance:
    leaseRenewalIntervalInSeconds: 10
    statusPageUrlPath: /configurationservice/info
    homePageUrlPath: /configurationservice/
    healthCheckUrlPath: /configurationservice/health
    preferIpAddress: true

spring:
  cloud:
    config:
      server:
        native:
          searchLocations: file:/Users/larrymitchell/libertas/configserver/configfiles

服务 bootstrap.yml 设置为:

spring:
  profiles:
    default: development
    active: development
  application:
    name: bookmarkservice
  cloud:
    config:
      enabled: true # note this needs to be turned on if you wnat the config server to work
#      uri: http://localhost:8888/configurationservice
      label: 1.0.0
      discovery:
        enabled: true
        serviceId: configurationservice

application.yml 设置为:

# general spring settings
spring:
  application:
    name: bookmarkservice
  profiles:
    default: development
    active: development    
# name of the service
service:
  name: bookmarkservice

# embedded web server settings
# some of these are specific to tomcat
server:
  port: 9001
  # the context path is the part after http:/localhost:8080
  contextPath: /bookmarkservice
  tomcat:
    basedir: target/tomcat
    uri-encoding: UTF-8

management:
  context-path: /manage
  security:
    enabled: false

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  instance:
    statusPageUrlPath: /bookmarkservice/manage/info
    homePageUrlPath: /bookmarkservice/manage
    healthCheckUrlPath: /bookmarkservice/manage/health
    preferIpAddress: true

书签服务启动日志如下:

2015-06-24 17:52:49.806 DEBUG 11234 --- [           main] o.s.web.client.RestTemplate              : Created GET request for "http://10.132.1.56:8888/configurationservice/bookmarkservice/development/1.0.0"
2015-06-24 17:52:49.890 DEBUG 11234 --- [           main] o.s.web.client.RestTemplate              : Setting request Accept header to [application/json, application/*+json]
2015-06-24 17:52:50.439 DEBUG 11234 --- [           main] o.s.web.client.RestTemplate              : GET request for "http://10.132.1.56:8888/configurationservice/bookmarkservice/development/1.0.0" resulted in 200 (OK)
2015-06-24 17:52:50.441 DEBUG 11234 --- [           main] o.s.web.client.RestTemplate              : Reading [class org.springframework.cloud.config.environment.Environment] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@2b07e607]
2015-06-24 17:52:50.466  INFO 11234 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource [name='file:/Users/larrymitchell/libertas/configserver/configfiles/1.0.0/bookmarkservice-development.yml']]]
2015-06-24 17:52:50.503  INFO 11234 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5fa23965: startup date [Wed Jun 24 17:52:50 EDT 2015]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@5cced717
2015-06-24 17:52:51.723  WARN 11234 --- [           main] .i.s.PathMatchingResourcePatternResolver : Skipping [/var/folders/kq/ykvl3t4n3l71p7s9ymywb4ym0000gn/T/spring-boot-libs/06f98804e83cf4a94380b46591b976b1d17c36b8-eureka-client-1.1.147.jar] because it does not denote a directory
2015-06-24 17:52:53.662  INFO 11234 --- [           main] o.s.b.f.config.PropertiesFactoryBean     : Loading properties file from URL [jar:file:/Users/larrymitchell/libertas/vipaas/applicationservices/bookmarkservice/target/bookmarkservice.jar!/lib/spring-integration-core-4.1.2.RELEASE.jar!/META-INF/spring.integration.default.properties]

好的,在与另一位同事讨论后,我弄清楚了实际问题所在。 部分困惑是我使用的是 spring 云 (https://github.com/VanRoy/spring-cloud-dashboard),顺便说一句,这是一个很棒的前端。因此,当服务启动时,我们会看到它以发现并检索正确的配置文件并加载它。在我转到 spring 云控制台并看到 UP 设置后,这意味着它通过发现被发现并注册。还有第二个状态指示器,即 spring 云仪表板获取已注册端点并获得运行状况的时间。在我的问题中,端点显示为未知。

如果我随后使用控制台中显示的端点并尝试信息执行器端点,则请求超时。这就是我的问题的本质

好的,问题出在哪里?

基本上因为我在 application.yml 中定义了并且因为当服务在 bootstrap 中注册时它还不知道端口然后它选择默认值 8080(我的假设是它能做什么)。服务器端口在 application.yml 中设置为 9001,但发现发现注册为 8080,因此 spring 云控制台无法访问 localhost:8080/bookmarkservice/manage/health,因为那里没有服务端点(实际上是 9001)。其他服务也找不到该服务。

通过将 server.port 移动到 bootstrap.yml,然后注册了正确的费率服务端点并且可以正确访问该服务。