繁体   English   中英

Spring Cloud Netflix和Docker Compose - 无法使用eureka注册服务

[英]Spring Cloud Netflix and Docker Compose - cannot register services with eureka

我正在尝试使用docker-compose在本地运行2个简单服务(Ubuntu):eureka服务器和配置服务器(也是eureka客户端)。 这两个都有简单的dockerfiles运行java -jar ,暴露他们的端口,并单独工作正常。 我还尝试添加eureka.client.service-url.defaultZone=http://company-service-discovery:8761/eureka以查看它是否会注册,并且它有效。

我的配置服务器无法成功注册到eureka服务器,我用谷歌搜索了它,我见过的任何东西都没有帮我解决这个问题。

根据https://docs.docker.com/compose/networking/上的docker-compose文档:

默认情况下,Compose为您的应用设置单个网络。 服务的每个容器都加入默认网络,并且该网络上的其他容器都可以访问它们,并且它们可以在与容器名称相同的主机名上发现。

通过以下示例, web应该能够使用postgres://db:5432与数据库进行通信。

version: "3"
services:
  web:
    build: .
    ports:
      - "8000:8000"
  db:
    image: postgres
    ports:
      - "8001:5432"

我使用相同的方法来配置我的服务,但我的配置服务器在尝试注册时拒绝连接:

泊坞窗,compose.yml

version: '3.3'
services:
  company-service-discovery:
    build: company-service-discovery/
    ports:
      - "8761:8761"
  company-config-server:
    build: company-config-server/
    ports:
      - "8888:8888"
    links:
      - company-service-discovery

配置服务器bootstrap.yml

server:
  port: 8888

management:
  security:
    enabled: false

spring:
  application:
    name: company-config-server
  cloud:
    config:
      server:
        native:
          search-locations: classpath:/shared
  profiles:
    include: native

eureka:
  client:
    service-url:
      defaultZone: http://company-service-discovery:8761/eureka

eureka服务器bootstrap.yml

spring:
  application:
    name: company-service-discovery

server:
  port: 8761

management:
  security:
    enabled: false

例外

2017-07-26 14:25:05.738  WARN 1 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused)
2017-07-26 14:25:05.739  WARN 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_COMPANY-CONFIG-SERVER/365d20275ab0:company-config-server:8888 - registration failed Cannot execute request on any known server

我的配置有什么问题吗? 我怎样才能使它工作?

如果有任何信息丢失,请告诉我,我很乐意提供任何信息。

defaultZone配置也添加到Eureka服务器的属性中(并在配置服务器bootstrap.yml中将service-url更改为serviceUrl )。

eureka服务器bootstrap.yml

spring:
  application:
    name: company-service-discovery

eureka:
  client:
    serviceUrl:
      defaultZone: http://company-service-discovery:8761/eureka

server:
  port: 8761

management:
  security:
    enabled: false

谢谢你太多了。 这篇文章解决了我的问题 - 将eureka客户端连接到带有docker的eureka服务器。 经过2天的搜索工作。 我流泪了。

基本上 -

您应该在eureka客户端的application.properties/.yml中使用以下内容

eureka.client.service-url.defaultZone = http:// eureka -server:8761 / eureka

在docker-compose.yml中你的eureka服务名称应该匹配 - url主机名,在我的例子中是 - eureka-server

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM