jhipster / jhipster-registry

JHipster Registry, based on Spring Cloud Netflix Eureka and Spring Cloud Config
Apache License 2.0
698 stars 657 forks source link

Eureka won't connect when run jhipster-registery in docker with cloud config server #538

Open Chipsona opened 2 years ago

Chipsona commented 2 years ago

Hi All, I am new to jhipster and docker. Just creating a jhipster-registry instance on linux server using docker. I am getting below exception

_jhipster-registry_1 | 2022-05-18 09:20:35.839 INFO 1 --- [ main] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://admin:admin@localhost:8761/eureka/}, exception=java.net.ConnectException: Connection refused (Connection refused) stacktrace=com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused (Connection refused) jhipster-registry_1 | at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) jhipster-registry_1 | at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123) jhipster-registry_1 | at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) jhipster-registry1 | at com.sun.jersey.api.client.Client.handle(Client.java:652)

It also shows Jhipster-registry instand as DOWN on dashboard image

I have downloaded the jhipster registry image and created created a container using docker-compose command. I am using GIT repo for config server.

Command : docker-compose -f jhipster-registry.yml up

jhipster-registry.yml

version: '3.8'
services:
  jhipster-registry:
    image: jhipster/jhipster-registry:v7.1.0
    network_mode: vs-bridge-net
    environment:
      - _JAVA_OPTIONS=-Xmx512m -Xms256m
      - SPRING_PROFILES_ACTIVE=prod
      - SPRING_SECURITY_USER_PASSWORD=admin
      - JHIPSTER_REGISTRY_PASSWORD=admin
      - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_TYPE=git
      - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_URI=https://github.com/xxxxxx/config-server.git
      - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_USERNAME=<git username>
      - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_PASSWORD=<git pswd>
      - SPRING_CLOUD_CONFIG_SERVER_GIT_DEFAULT-LABEL=main
      - SPRING_CLOUD_CONFIG_SERVER_GIT_BASEDIR=<directory>
      - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_SEARCH_PATHS=central-config
    ports:
      - 8761:8761

Config-server : application.yml at GIT repo

# ===================================================================
# JHipster Sample Spring Cloud Config.
# ===================================================================

# Property used on app startup to check the config server status
configserver:
    name: JHipster Registry config server
    status: Connected to the JHipster Registry config server!

# Default JWT secret token (to be changed in production!)
jhipster:
    security:
        authentication:
            jwt:               
                base64-secret: MjkwYWRhZTZmYmY5ZWRkMDg4MjM4YmNhZDVjMzVkYmExM2UwYzkyNDAyMWQ0ODkxNzllYmRkN2I2MGM1ZmIyOWM2NzNhMDZkYzU0MjcxYTkxN2ZjMTk5YWUzYTJkYTRiNDI4NjY4NzgwZDBlYmQ1YzZmZmYxM2E2MmY2ODk4NDk

# Enable /management/logfile endpoint for all apps
logging:
    path: /tmp
    file: ${spring.application.name}.log

#defaultZone=http://admin:${jhipster.registry.password}@jhipster-registry:8761/eureka/
eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://admin:admin@localhost:8761/eureka/

It won't throw error when I set value to false for below property . But it won't register any microservices.

register-with-eureka: false fetch-registry: false

Kindly help and let me know what is wrong with above configuration.

Tcharl commented 2 years ago

Last time I used it, I registered my local url as 127.0.0.1 jhipster-registry in my /etc/hosts and it worked. Can you please try it?

Chipsona commented 2 years ago

Last time I used it, I registered my local url as 127.0.0.1 jhipster-registry in my /etc/hosts and it worked. Can you please try it?

Thanks @Tcharl for your response. I have tried this but no luck.

Tcharl commented 2 years ago

You should also modify the service url in your compose file right?

Chipsona commented 2 years ago

http://admin:${jhipster.registry.password}@jhipster-registry:8761/eureka/

yes @Tcharl . I did that. like below http://admin:admin@jhipster-registry:8761/eureka/

Error-

--- [ main] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://admin:admin@jhipster-registry:8761/eureka/}, exception=java.net.ConnectException: Connection refused (Connection refused) stacktrace=com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused (Connection refused)

Eureka instance shows DOWN on jhipster registry dashboard.

I have tried with following property register-with-eureka: false fetch-registry: false

but in this case microservices wont get registered and Eureka server also wont start I think.

Tcharl commented 2 years ago

Here's what I had on my side for local environment (I'll retest with another example in the latest version as soon as I can).

Back In the old days, it worked pretty well :-).

  marketplace-app:
    image: gitlab.thalesdigital.io:5005/ecwp/marketplace
    container_name: marketplace-app
    environment:
      - _JAVA_OPTIONS=-Xmx512m -Xms256m
      - SPRING_PROFILES_ACTIVE=prod,swagger
      - EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://admin:$${jhipster.registry.password}@jhipster-registry:8761/eureka
      - SPRING_CLOUD_CONFIG_URI=http://admin:$${jhipster.registry.password}@jhipster-registry:8761/config
      - SPRING_DATASOURCE_URL=jdbc:mariadb://marketplace-mysql:3306/marketplace?useUnicode=true&characterEncoding=utf8&useSSL=false&createDatabaseIfNotExist=true&useLegacyDatetimeCode=false&serverTimezone=UTC
      - SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=http://keycloak:9080/auth/realms/jhipster # should also be in etc/hosts
      - SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID=marketplace
      - SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET=secret-marketplace
      - SPRING_DATA_JEST_URI=http://ecwp-elasticsearch:9200
      - SPRING_ELASTICSEARCH_REST_URIS=http://ecwp-elasticsearch:9200
      - SPRING_ZIPKIN_BASEURL=http://jhipster-zipkin:9411
      - SPRING_ZIPKIN_ENABLED=false
      - JHIPSTER_LOGGING_LOGSTASH_ENABLED=false
      - JHIPSTER_LOGGING_LOGSTASH_HOST=jhipster-logstash
      - SPRING_RABBITMQ_HOST=ecwp-rabbitmq
      - JHIPSTER_CACHE_MANAGEMENTCENTER_URL=http://hazelcast-management-center:8080/mancenter
      - JHIPSTER_REGISTRY_PASSWORD=admin
    networks:
      - microservices
    ports:
      - '8103:8103'
    depends_on:
      - ecwp-elasticsearch
      - jhipster-registry
      - marketplace-mysql
      - ecwp-rabbitmq
      - keycloak
      - hazelcast-management-center
    command: ["./wait-for-stack.sh", "com.corp.service.marketplace.MarketplaceApp", "jhipster-registry", "keycloak", "ecwp-elasticsearch", "ecwp-rabbitmq", "marketplace-mysql", "hazelcast-management-center"]
    healthcheck:
      test: ["CMD-SHELL", "netstat -plnt | grep 8103 | grep LISTEN > /dev/null || exit 1"]
      interval: 2m
      timeout: 10s
      retries: 3

jhipster-registry:
    image: jhipster/jhipster-registry:v6.3.0
    container_name: jhipster-registry
    volumes:
      - ./central-server-config:/central-config
    # By default the JHipster Registry runs with the "dev" and "native"
    # Spring profiles.
    # "native" profile means the filesystem is used to store data, see
    # http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html
    environment:
      - _JAVA_OPTIONS=-Xmx512m -Xms256m
      - SPRING_PROFILES_ACTIVE=dev,oauth2
      - SPRING_SECURITY_USER_PASSWORD=admin
      - JHIPSTER_REGISTRY_PASSWORD=admin
      - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_TYPE=native
      - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_SEARCH_LOCATIONS=file:./central-config
      # - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_TYPE=git
      # - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_URI=https://github.com/jhipster/jhipster-registry/
      # - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_SEARCH_PATHS=central-config
      # - JHIPSTER_LOGGING_LOGSTASH_ENABLED=true
      # - JHIPSTER_LOGGING_LOGSTASH_HOST=jhipster-logstash
      # - JHIPSTER_METRICS_LOGS_ENABLED=true
      # - JHIPSTER_METRICS_LOGS_REPORTFREQUENCY=60
      # For Keycloak to work, you need to add '127.0.0.1 keycloak' to your hosts file
      - SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=http://keycloak:9080/auth/realms/jhipster
      - SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID=jhipster-registry
      - SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET=secret-jhipster-registry
    # healthcheck:
      # test: ["CMD-SHELL", "netstat -plnt | grep 8761 | grep LISTEN > /dev/null || exit 1"]
      # interval: 1m
      # timeout: 10s
      # retries: 3
    networks:
      - microservices
    ports:
      - 8761:8761
    depends_on:
      - keycloak
  keycloak:
    image: jboss/keycloak:10.0.0
    container_name: keycloak
    command: [
      "-b",
      "0.0.0.0",
      "-Dkeycloak.migration.action=import",
      "-Dkeycloak.migration.provider=dir",
      "-Dkeycloak.migration.dir=/opt/jboss/keycloak/realm-config",
      "-Dkeycloak.migration.strategy=OVERWRITE_EXISTING",
      "-Djboss.socket.binding.port-offset=1000",
      '-Dkeycloak.profile.feature.upload_scripts=enabled'
    ]
    volumes:
      - ./realm-config:/opt/jboss/keycloak/realm-config
    environment:
      - KEYCLOAK_USER=admin
      - KEYCLOAK_PASSWORD=admin
      - DB_VENDOR=h2
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:9080 || exit 1"]
      interval: 1m
      timeout: 10s
      retries: 3
    networks:
      - microservices
    ports:
      - 9080:9080
      - 9444:9443
      - 10990:10990

And the application.yml (it was made when jhipster was in version 7.0.1, some properties may have changed)

eureka:
 client:
    enabled: true
    healthcheck:
      enabled: true
    fetch-registry: true
    register-with-eureka: true
    instance-info-replication-interval-seconds: 10
    registry-fetch-interval-seconds: 10
    service-url:
      defaultZone: http://admin:${jhipster.registry.password}@localhost:8761/eureka/
  instance:
    appname: marketplace
    instanceId: marketplace:${spring.application.instance-id:${random.value}}
    lease-renewal-interval-in-seconds: 5
    lease-expiration-duration-in-seconds: 10
    status-page-url-path: ${management.endpoints.web.base-path}/info
    health-check-url-path: ${management.endpoints.web.base-path}/health
    metadata-map:
      zone: primary # This is needed for the load balancer
      profile: ${spring.profiles.active}
      version: #project.version#
      git-version: ${git.commit.id.describe:}
      git-commit: ${git.commit.id.abbrev:}
      git-branch: ${git.branch:}
      context-path: ${server.servlet.context-path:}
  instance:
    prefer-ip-address: true

jhipster:
  http:
    cache: # Used by the CachingHttpHeadersFilter
      timeToLiveInDays: 1461
  cache: # Cache configuration
    hazelcast: # Hazelcast distributed cache
      time-to-live-seconds: 3600
      backup-count: 1
  registry:
    password: admin
spring:
  cloud:
    config:
      fail-fast: true # fail startup of a service if it cannot connect to the Config Server
      retry:
        initial-interval: 1000
        max-interval: 2000
        max-attempts: 20
        # uri: set by the Spring Cloud Cloud Foundry Connector if application bound to config server
        # name of the config server's property source (file.yml) that we want to use
      name: marketplace
      profile: cloud,production # profile(s) of the property source
      label: master # toggle to switch to a different version of the configuration as stored in git
      # it can be set to any label, branch or commit of the configuration source Git repository
Chipsona commented 2 years ago

Thanks @Tcharl for you prompt response. The issue occurs when I use "Spring Cloud Config" from GIT repo using PROD profile. Kindly check section - Config-server : application.yml at GIT repo above

At local Dev profile with "central-config" works fine.

Could you check jhipster-registry.yml and config-server application.yml above and let me know if I am missing anything.

Thanks.