spring-cloud-netflix: Eureka Server replication is not working for Multi instance of the Eureka Server.

I am using the below configuration for Eureka Servers.

Eureka Server1 (application.properties)

server.port=8761

eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.health-check.enabled=true

logging.level.com.netflix.eureka=DEBUG
logging.level.com.netflix.discovery=DEBUG

eureka.server.eviction-interval-timer-in-ms: 25000
eureka.server.enableSelfPreservation=false

eureka.instance.hostname=localhost
eureka.client.service-url.defaultZone=http://localhost:8762/eureka/

Eureka Server2 (application.properties)

server.port=8762

eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.health-check.enabled=true

logging.level.com.netflix.eureka=DEBUG
logging.level.com.netflix.discovery=DEBUG

eureka.server.eviction-interval-timer-in-ms: 25000
eureka.server.enableSelfPreservation=false

eureka.instance.hostname=localhost
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/

Micro service configuration (appsettings.json)

{
  "Logging": {
    "IncludeScopes": true,
    "LogLevel": {
      "Default": "Information",
      "Pivotal": "Debug",
      "Steeltoe": "Debug"
    }
  },
  "spring": {
    "application": {
      "name": "fortuneService"
    }
  },
  "eureka": {
    "client": {
      "serviceUrl": {
        "defaultZone": "http://localhost:8761/eureka/,http://localhost:8762/eureka/"
      },
      "shouldFetchRegistry": true,
      "ValidateCertificates": false,
      "registryFetchIntervalSeconds": 10
    },
    "instance": {
      "appName": "FortuneService",
      "hostName": "localhost",
      "port": 52701,
      "instanceId": "FortuneService2",
      "leaseRenewalIntervalInSeconds": 10,
      "leaseExpirationDurationInSeconds": 5
    }
  }
}

I am facing an issue with when I connect the Multi instance of the Eureka Servers to Eureka Client(Microservices) that is not working for below scenario – Let’s consider I have two Eureka Servers(ES1 – 8761 and ES2-8762)

ES1 server registered with ES2 Server and vice-versa. When I start the Microservices, both services are registered with ES1 Server only, but not registered with ES2 server. After sometime intentionally, I have stopped the ES1 server. Which are registered with ES1 server’s services are not replicating with ES2 server.

Please help me.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

Hello everybody.

I’ve been kicking my way through this issue as well, and as I was typing up my detailed complaint to add to this thread, I inadvertently fixed my problem. Maybe I can help you as well.

I had to do two things.

  1. Edit my hosts file (I am currently running locally in preparation for a deployment) so that the values in eureka.client.serviceUrl.defaultZone have different host names. I read in several threads that you should not use localhost, or the same ip or dns name for replicated Eureka instances.

  2. Make sure the value of eureka.instance.hostname is the same value from my hosts file.

So, here is my config.

hosts file:

	127.0.0.1       eureka1
	127.0.0.1       eureka2

Base properties:

eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.instance.appName=ServiceRegistryCluster
eureka.environment=local

peer1 profile properties:

server.port=8761
eureka.client.serviceUrl.defaultZone=http://eureka2:8762/eureka/,http://eureka1:8761/eureka/
eureka.instance.hostname=eureka1
spring.application.name=EUREKA_SERVICE_REGISTRY_DEV

peer2 profile properties:

server.port=8762
eureka.client.serviceUrl.defaultZone=http://eureka1:8761/eureka/,http://eureka2:8762/eureka/
eureka.instance.hostname=eureka2
spring.application.name=EUREKA_SERVICE_REGISTRY_DEV

Now when I look at the Eureka console for eureka1, I see eureka2 listed as an available replica, and vice-versa for the eureka2 console.