本文介绍了云配置获取请求执行错误.来自Eureka服务器的endpoint = DefaultEndpoint {serviceUrl ='http://localhost:8761/}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的4个微服务实现Discovery First Bootstrap方法.首先是从git获取配置的配置服务器,其次是Eureka服务器.当我运行docker-compose up时,我的配置服务器无法向eureka注册.我有:

I'm trying to implement Discovery First Bootstrap way for my 4 micro-services. First is a config server that takes config from git, and second is an Eureka server. When i'm running docker-compose up my config server is not able to register with eureka. I've got:

请求执行错误. endpoint = DefaultEndpoint {serviceUrl =' http://localhost:8761/}连接被拒绝

Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/} Connection refused

我的配置服务器

 @EnableConfigServer
    @EnableEurekaClient
    @SpringBootApplication
    public class ConfigServerApplication {
        public static void main(String[] args) {
            SpringApplication.run(ConfigServerApplication.class, args);
        }

application.yml

application.yml

   server:
  port: 8888
spring:
  cloud:
    config:
      server:
        encrypt.enabled: false
        git:
          uri: https://github.com/Artuwok/artbook-config-repo/
          searchPaths: userservice
          username: Artuwok
          password: Civilization1986
          timeout: 10
          force-pull: true

bootstrap.yml

bootstrap.yml

spring:
  application:
    name: configserver
  cloud:
    config:
      fail-fast: true
      discovery.enabled: true

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl.defaultZone: http://localhost:8761/eureka/

尤里卡课

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }

Eureka bootstrap.yml

Eureka bootstrap.yml

server:
  port: 8761
eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false

具有完整配置的docker-compose.yml

docker-compose.yml with full config

version: '3'

services:

  configserver:
    image: configserver:1.0
    ports:
      - "8888:8888"
    depends_on:
      - eurekaserver
    restart: on-failure

  eurekaserver:
    image: eurekasvr:1.0
    ports:
      - "8761:8761"


  users_db:
    image: mysql:5.7
    container_name: users_db
    restart: always
    environment:
      - MYSQL_DATABASE=artbook
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_USER=user
      - MYSQL_PASSWORD=password
    volumes:
      - users_db:/var/lib/mysql
    ports:
      - "3306:3306"
    depends_on:
      - eurekaserver

  user-service:
    image: userservice:1.0
    ports:
      - "8080:8080"
    depends_on:
      - eurekaserver
      - configserver
    restart: on-failure
volumes:
  users_db:

所以最终我能够启动服务.请特别注意要在其上发现服务的URL. 如果您正在使用docker映像,则必须使用服务名称,而不是uri和url中的localhost.我的工作配置

So in the end i was able to start-up the services. Pay huge attention to URL on which you are discovering service. If you are using docker images you must use service name, not localhost in uri and urls's. My working config

spring:
  application:
    name: configserver
  cloud:
    config:
      fail-fast: false
      discovery.enabled: false
      uri: http://configserver:8888

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl.defaultZone: http://eurekaserver:8761/eureka

推荐答案

您配置的服务器和Eureka服务器都在Docker中运行.因此,他们可以使用Docker中的名称而不是localhost来相互连接.

You config server and Eureka server both run in Docker. So they can connect with each other using their names in Docker, not localhost.

因此,尤里卡(Eureka)服务网址应为:http://eurekaserver:8761/.

So Eureka service URL should be: http://eurekaserver:8761/.

并且您应该将以下代码添加到docker-compose.yml中的configserver配置中:

And you should add the code below to your configserver configuration in docker-compose.yml:

links:
    - eurekaserver

这篇关于云配置获取请求执行错误.来自Eureka服务器的endpoint = DefaultEndpoint {serviceUrl ='http://localhost:8761/}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 11:38