docker 配置 docker-compose 发布 apollo,启动portal报错,不能从meta server找到admin server

 在 https://github.com/ctripcorp/apollo/issues 找到一些关于这个错误的文章,说是可以在apollo portal 管理页面测试其他admin、configservice 的健康状态,或者通过configserverip:port/services/admin 查看返回的apollo-admin 服务状态,但是当我们用configserverip:port/services/admin这个地址去测试的时候发现返回为“[]”,这个时候发现在eureka上面 config 和 admin 都已经注册上去的,这让我百思不得其解,如下图所示:

docker 配置 docker-compose 发布 apollo,启动portal报错,不能从meta server找到admin server
标题

经过不断探索,在apollo config service 源码里面发现这么一段:

  @RequestMapping("/admin")
  public List<ServiceDTO> getAdminService() {
    return discoveryService.getServiceInstances(ServiceNameConsts.APOLLO_ADMINSERVICE);
  }

查看ServiceNameConsts.APOLLO_ADMINSERVICE=apollo-adminservice,然后看了一下自己docker-compose的 配置 

apollo-adminservice:
    image: apolloconfig/apollo-configservice:1.7.1
    container_name: apollo-adminservice
    network_mode: "host"
    privileged: true
    environment:
      SERVER_PORT: 6166
      # DataSource Info
      SPRING_DATASOURCE_URL: "jdbc:mysql://mysql.host.com:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=GMT%2B8"
      SPRING_DATASOURCE_USERNAME: "root"
      SPRING_DATASOURCE_PASSWORD: "123456"
      spring.application.name: "apollo-admin-service"
      management.endpoints.web.exposure.include: "*"
      eureka.instance.prefer-ip-address: "true"
      eureka.instance.appname: "apollo-admin-service"
      eureka.instance.instance-id: "$${spring.application.name}:$${spring.application.instance_id:$${server.port}}"
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"

发现 spring.application.name 和 apollo service controller 里面所需要的配置并不正确,于是我改了一下配置

apollo-adminservice:
    image: apolloconfig/apollo-configservice:1.7.1
    container_name: apollo-adminservice
    network_mode: "host"
    privileged: true
    environment:
      SERVER_PORT: 6166
      # DataSource Info
      SPRING_DATASOURCE_URL: "jdbc:mysql://mysql.host.com:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=GMT%2B8"
      SPRING_DATASOURCE_USERNAME: "root"
      SPRING_DATASOURCE_PASSWORD: "123456"
      spring.application.name: "apollo-adminservice"
      management.endpoints.web.exposure.include: "*"
      eureka.instance.prefer-ip-address: "true"
      eureka.instance.appname: "apollo-adminservice"
      eureka.instance.instance-id: "$${spring.application.name}:$${spring.application.instance_id:$${server.port}}"
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"

最终没有报错了。

结论: 

eureka.instance.appname=ServiceNameConsts.APOLLO_ADMINSERVICE
spring.application.name=ServiceNameConsts.APOLLO_ADMINSERVICE
上一篇:MacOS 下搭建Mqtt服务器


下一篇:.Net Core apollo配置中心使用