简体   繁体   English

Spring 微服务 eureka 客户端未向 eureka 服务器注册

[英]Spring micro services eureka client is not registering with eureka server

I'm very new to everything about docker, spring framework... They run on localhost environment successfully, now I want to push them into docker, but always gave me error there, i got stuck on it about a week.我对 docker、spring 框架的一切都很陌生......它们在本地主机环境中成功运行,现在我想将它们推送到 docker,但总是给我错误,我被困了大约一个星期。 Can someone help me figure it out PLEASE!!!有人可以帮我弄清楚吗!!!

now I have eureka-server and cloud-config-server services, here is my code:现在我有 eureka-server 和 cloud-config-server 服务,这是我的代码:

eureka-server application.yml尤里卡服务器 application.yml

server:
  port: 8761
spring:
  application:
    name: service-registration
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
management:
  security:
    enabled: false

and Dockerfile:和 Dockerfile:

FROM openjdk:11
COPY target/service-registration-0.0.1-SNAPSHOT.jar service-registration.jar
EXPOSE 8761
CMD ["java", "-jar", "service-registration.jar"]

Now I have cloud-config-server application.yml: In this file, i tried to backup it on github. From the start, I tried to change the hostname as localhost or any other hostname like service-registration, eureka-server etc... but not work, and "service-url" or "serviceUrl'....现在我有了 cloud-config-server application.yml:在这个文件中,我尝试在 github 上备份它。从一开始,我尝试将主机名更改为 localhost 或任何其他主机名,如服务注册、eureka-server 等。 .. 但不起作用,“service-url”或“serviceUrl”....

server:
  port: 9291

spring:
  application:
    name: cloud-config-server
  profiles:
    active: production
#  cloud:
#    config:
#      server:
#        git:
#          uri: https://github.com/sshaunn/config-server
#          clone-on-start: true

eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    serviceUrl:
      defaultZone: http://service-registration:8761/eureka/
  instance:
#    prefer-ip-address: true
#    ip-address: http://eureka-server:8761/eureka/å
    hostname: service-registration

Dockerfile: Dockerfile:

FROM openjdk:11
COPY target/cloud-config-server-0.0.1-SNAPSHOT.jar cloud-config-server.jar
EXPOSE 9291
ENTRYPOINT ["java", "-jar", "cloud-config-server.jar"]

and the docker-compose.yml file:和 docker-compose.yml 文件:

version: '3.7'
services:
  service-registration:
    image: service-registration
    networks:
      - eureka-server
    ports:
      - "8761:8761"
    container_name: service-registration
    hostname: service-registration
  cloud-config-server:
    build: cloud-config-server
    networks:
      - eureka-server
    ports:
      - "9291:9291"
    depends_on:
      - service-registration
    container_name: cloud-config-server
    hostname: service-registration
    environment:
      EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://service-registration:8761/eureka

networks:
  eureka-server:
    name: eureka-server
    driver: bridge
#  route:
#    image: route
#    ports:
#      - "9191:9191"
#    container_name: api-gateway

#    environment:
#      EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://service-registration:8761/eureka

这是尤里卡服务器的用户界面 The error logs here:错误记录在这里:

2022-05-29 07:22:41.713 WARN 1 --- [freshExecutor-0] c.ndstdRetryableEurekaHttpClient: Request execution failed with message: I/O error on GET request for "http://localhost:8761/eureka/apps/": Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused (Connection refused); 2022-05-29 07:22:41.713 WARN 1 --- [freshExecutor-0] c.ndstdRetryableEurekaHttpClient:请求执行失败并显示消息:“http://localhost:8761/eureka/apps”的 GET 请求出现 I/O 错误/": 连接到 localhost:8761 [localhost/127.0.0.1] 失败:连接被拒绝(Connection refused); 2022-05-29 07:06:11.565 WARN 1 --- [tbeatExecutor-0] c.ndstdRetryableEurekaHttpClient: Request execution failed with message: I/O error on PUT request for "http://localhost:8761/eureka/apps/CONFIG-SERVER/service-registration:CONFIG-SERVER:9291": Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused (Connection refused); 2022-05-29 07:06:11.565 WARN 1 --- [tbeatExecutor-0] c.ndstdRetryableEurekaHttpClient:请求执行失败并显示消息:PUT 请求“http://localhost:8761/eureka/apps 时出现 I/O 错误/CONFIG-SERVER/service-registration:CONFIG-SERVER:9291": Connect to localhost:8761 [localhost/127.0.0.1] 失败:连接被拒绝(Connection refused);

Ok, I dont know why but I set up a docker-compose.yml file like this and it works: Note, I set up environment about "service-url" defaultZone in docker-compose.yml file.好的,我不知道为什么,但是我像这样设置了一个 docker-compose.yml 文件并且它可以工作:注意,我在 docker-compose.yml 文件中设置了关于“service-url”defaultZone 的环境。

version: '3.7'
services:
  service-registration:
    container_name: service-registration
    build:
      context: ./service-registration
      dockerfile: Dockerfile
    ports:
      - "8761:8761"
  cloud-config-server:
    container_name: cloud-config-server
    build:
      context: ./cloud-config-server
      dockerfile: Dockerfile
    environment:
      - eureka.client.service-url.defaultZone=http://service-registration:8761/eureka
    depends_on:
      - service-registration
    ports:
      - "9191:9191"
  route:
    container_name: route
    build:
      context: ./route
      dockerfile: Dockerfile
    environment:
      - eureka.client.service-url.defaultZone=http://service-registration:8761/eureka
    depends_on:
      - service-registration
      - employee
      - income
    ports:
      - "9291:9291"
  employee:
    container_name: employee
    build:
      context: ./employee
      dockerfile: Dockerfile
    environment:
      - eureka.client.service-url.defaultZone=http://service-registration:8761/eureka
    depends_on:
      - service-registration
    ports:
      - "9001:9001"
  income:
    container_name: income
    build:
      context: ./income
      dockerfile: Dockerfile
    environment:
      - eureka.client.service-url.defaultZone=http://service-registration:8761/eureka
    depends_on:
      - service-registration
    ports:
      - "9002:9002"

You should use your host ip address to run in your local machine.你应该使用你的主机 ip 地址在你的本地机器上运行。 For the docker it should not be localhost对于 docker 它不应该是localhost

Try with the below configuration in your application.properties file.在您的application.properties文件中尝试使用以下配置。

eureka.client.service-url.defaultZone=http://host.docker.internal:8761/eureka/

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

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