繁体   English   中英

云配置出现请求执行错误。 endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/} 来自 Eureka 服务器

[英]Cloud config got Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/} from Eureka server

我正在尝试为我的 4 个微服务实施 Discovery First Bootstrap 方式。 第一个是从 git 获取配置的配置服务器,第二个是 Eureka 服务器。 当我运行 docker-compose 时,我的配置服务器无法向尤里卡注册。 我有:

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

我的配置服务器

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

应用.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

引导程序.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/

尤里卡 class

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

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

尤里卡bootstrap.yml

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

docker-compose.yml 完整配置

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 中使用服务名称,而不是本地主机。 我的工作配置

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相互连接。

因此,Eureka服务URL应该为: http://eurekaserver:8761/

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

links:
    - eurekaserver

在您的应用程序属性文件中添加以下内容:
eureka.client.register-with-eureka=false eureka.client.fetch-registry=false

这使您的 eureka 服务器在默认端口 8080 上运行,这些属性还可以帮助您不向自身注册 eurekaServer。
(EurekaServer 本身也是一个客户端。)

如果要在端口 8761 上运行此服务器,请在 application.properties 文件中添加以下内容:
server.port=8761

PS- 当您不使用 docker 时它会有所帮助。

我没有使用docker ,但我遇到了同样的错误,我在整个 web 中搜索了很多但没有找到任何东西。

然后我只是停止服务器并更新我的 maven 依赖项一次,然后尝试启动它服务发现。 有效!!

我希望这会帮助那些没有使用 docker 并获得相同结果的人。

PS-还要确保在application.propertiesapplication.yml中有这些配置

server.port=8761
spring.application.name=eureka-discovery
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false 
eureka.client.fetch-registry=false
eureka.client.service-url.defaultZone: http://localhost:8761/eureka

暂无
暂无

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

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