Spring Eureka cluster replication issues [version eureka-Brixton.SR1] - spring-cloud

I am trying to setup a eureka cluster which comprise of there servers. (my setup is on local machine)
Configurations for each eureka server as below:
server1:
server:
port: 8764
eureka:
instance:
metadataMap:
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
client:
registerWithEureka: true
fetchRegistry: true
# availabilityZones: zone1,zone1,zone1
server:
waitTimeInMsWhenSyncEmpty: 0
serviceUrl:
defaultZone: http://localhost:8762/eureka/,http://localhost:8763/eureka/,http://localhost:8764/eureka/
server2:
server:
port: 8762
eureka:
instance:
metadataMap:
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
client:
registerWithEureka: true
fetchRegistry: true
server:
waitTimeInMsWhenSyncEmpty: 0
serviceUrl:
defaultZone: http://localhost:8762/eureka/,http://localhost:8763/eureka/,http://localhost:8764/eureka/
server3:
server:
port: 8763
eureka:
instance:
metadataMap:
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
client:
registerWithEureka: true
fetchRegistry: true
server:
waitTimeInMsWhenSyncEmpty: 0
serviceUrl:
defaultZone: http://localhost:8762/eureka/,http://localhost:8763/eureka/,http://localhost:8764/eureka/
each server is peering to each others, so registration info will be replicated among servsers.
But, when I checked the logs server, it always throw exception as beblow:
I also checked dashboard of eureka server and it shown as below:
I dont know why the registered replicas (http://localhost:8761/eureka/) did not change even I have configured
serviceUrl:
defaultZone: http://localhost:8762/eureka/,http://localhost:8763/eureka/,http://localhost:8764/eureka/
I have setup a micro services and register to the eureka cluster, but for somehow the service info only is registered on one of eureak server, I am expecting that info also replicated to others as well
is there anyone suffering from same issue, I have been trying searching a lot but could not find the right answer for my case.
High appreicate for any advice?

I have found the issues. I have put serviceUrl in wrong section (server).
it should be in the client part.
server:
port: 8763
eureka:
instance:
metadataMap:
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://localhost:8762/eureka/,http://localhost:8763/eureka/,http://localhost:876
server:
waitTimeInMsWhenSyncEmpty: 0

Related

Configure Eureka Server and client with custom port and address

I have a Eureka Server running on default localhost host and port 8761, so i tried to change this default configuration in this way:
server:
port: 6000
servlet:
context-path: /myeureka
eureka:
client:
register-with-eureka: false
fetch-registry: false
But in this way i can't access eureka dashboard, just using default configuration:
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
In my client same thing occurrs, i can't point to another eureka server different from default (localhost:8761), see my configuration:
server:
port: 7000
servlet:
context-path: /client-eureka
spring:
application:
name: client-eureka
eureka:
instance:
prefer-ip-address: true
client:
eureka-server-port: 6000
eureka-server-u-r-l-context: /myeureka
Lookin in client log i got the following:
2018-09-01 09:19:37.175 INFO 4931 --- [ main] c.n.eureka.cluster.PeerEurekaNodes : Replica node URL: http://localhost:8761/eureka/
No matter what port or host i configure in client, always try to reach the default.
Important:
I'm using eureka in this version: https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-eureka-server/2.0.1.RELEASE
I used the same dependency version as yours and cannot find the config path server.servlet.contextpath
Instead, you can use either server.servlet-path or server.context-path
With each of the server configuration, you need to update your client application.yml file too. Remember that /eureka is the default REST endpoint used to register Eureka client with Eureka server
Case 1: Use server.servlet-path
Eureka Server:
server:
port: 7000
servlet-path: /myeureka
eureka:
client:
register-with-eureka: false
fetch-registry: false
Eureka Client:
spring:
application:
name: spring-cloud-eureka-client
server:
port: 0
eureka:
client:
service-url:
defaultZone: ${EUREKA_URI:http://localhost:7000/eureka}
instance:
preferIpAddress: true
Case 2: Use server.context-path
Eureka Server:
server:
port: 7000
context-path: /myeureka
eureka:
client:
register-with-eureka: false
fetch-registry: false
Eureka Client:
spring:
application:
name: spring-cloud-eureka-client
server:
port: 0
eureka:
client:
service-url:
defaultZone: ${EUREKA_URI:http://localhost:7000/myeureka/eureka}
instance:
preferIpAddress: true
Updated answer:
Because server.servlet-path and server.context-path were deprecated, eureka server will be configured as following:
server:
port: 7000
servlet:
context-path: /myeureka
eureka:
client:
register-with-eureka: false
fetch-registry: false
Eureka client application.yml will be kept as in Case 2.

Spring Cloud - Eureka service discovery clustering

I have tried starting Eureka service in peer to peer awareness with following profiles.
#profile 1:
spring:
application:
name: service-registry
profiles: p1
server:
port: 8761
eureka:
dashboard:
enabled: false
override: true
enableselfPresentation: true
shouldUseDns: true
instance:
appname: ${spring.application.name}
instanceId: ${random.value}
client:
registerWithEureka: false
fetchRegistry: false
#profile 2:
spring:
application:
name: service-registry
profiles: p2
server:
port: 8762
eureka:
dashboard:
enabled: false
override: true
enableselfPresentation: true
shouldUseDns: true
instance:
appname: ${spring.application.name}
instanceId: ${random.value}
client:
registerWithEureka: false
fetchRegistry: false
After starting eureka with these profiles, at eureka dashboard for port 8761 I see DS replica as localhost:8761 but not as localhost:8762
and on localhost:8762 DS replica as localhost:8761
How to make the replica of localhost:8761 as localhost:8762 and vice versa
Found the solution for this added following config:
#profile p1
eureka
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://localhost:8762/eureka/
#profile p2
eureka
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://localhost:8761/eureka/

Setting up Eureka for non-AWS datacenter

I have setup Eureka with 2 peers, after about 5 minutes I see this message appear in the UI:
EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.
When I look at the output from one of the running instances of Eureka, I see this:
2015-11-11 14:46:47.276 INFO 32748 --- [pool-5-thread-1] com.netflix.discovery.DiscoveryClient : The response status is 200
2015-11-11 14:56:17.427 WARN 32748 --- [eerNodesUpdater] c.n.eureka.cluster.PeerEurekaNodes : The replica size seems to be empty. Check the route 53 DNS Registry
If I'm understanding this correctly, Eureka thinks it is configured at AWS. I'm unable to find anything in the application.yml to indicate this.
Any ideas on what I'm missing in the config?
server:
port: 80
eureka:
datacenter: boston
instance:
hostname: eureka03.domain.com
client:
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
---
eureka:
instance:
hostname: eureka01.domain.com
client:
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
I found the issue with my application.yml to get peers setup. Here's the proper application.yml if anyone runs into the same issue.
application.yml on peer1
server:
port: 80
eureka:
datacenter: boston
instance:
hostname: eureka01
client:
serviceUrl:
defaultZone: http://eureka03/eureka/
application.yml on peer2
server:
port: 80
eureka:
datacenter: boston
instance:
hostname: eureka03
client:
serviceUrl:
defaultZone: http://eureka01/eureka/
It may be that you are missing instanceId which helps eureka to identifies nodes:
eureka:
instance:
hostname: app56.test.online.eniro
metadataMap:
instanceId: EUREKA01_${spring.application.name}:${spring.application.instance_id:${random.value}}
client:
serviceUrl:
defaultZone: http:///eureka01/eureka/
After about 5 minutes, I see this in the web ui. EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.
I have also verified the peers can talk to each other. Here's what I see in the eureka output.
2015-11-13 09:08:39.928 WARN 860 --- [p-nio-80-exec-2] c.n.e.registry.AbstractInstanceRegistry : DS: Registry: lease doesn't exist, registering resource: EUREKA - eureka03:eureka:80
2015-11-13 09:08:39.928 WARN 860 --- [p-nio-80-exec-2] c.n.eureka.resources.InstanceResource : Not Found (Renew): EUREKA - eureka03:eureka:80
2015-11-13 09:08:40.451 INFO 860 --- [p-nio-80-exec-4] c.n.e.registry.AbstractInstanceRegistry : Registered instance EUREKA/eureka03:eureka:80 with status UP (replication=true)
2015-11-13 09:08:43.066 WARN 860 --- [ka01.ctct.net-6] c.n.eureka.cluster.ReplicationTask : The replication of task EUREKA/eureka01:eureka:80:Heartbeat#eureka01 failed with response code 404
2015-11-13 09:08:43.066 WARN 860 --- [ka01.ctct.net-6] c.netflix.eureka.cluster.PeerEurekaNode : EUREKA/eureka01:eureka:80:Heartbeat#eureka01: missing entry.
2015-11-13 09:08:43.066 WARN 860 --- [ka01.ctct.net-6] c.netflix.eureka.cluster.PeerEurekaNode : EUREKA/eureka01:eureka:80:Heartbeat#p2-dev-eureka01.ctct.net: cannot find instance id eureka01:eureka:80 and hence replicating the instance with status UP
Here's my application.yml for the 2 peers
peer1
server:
port: 80
eureka:
datacenter: bedford
instance:
hostname: eureka01
metadataMap:
instanceId: EUREKA01_${spring.application.name}:${spring.application.instance_id:${random.value}}
client:
serviceUrl:
defaultZone: http://eureka03/eureka/
peer2
server:
port: 80
eureka:
datacenter: bedford
instance:
hostname: eureka03
metadataMap:
instanceId: EUREKA03_${spring.application.name}:${spring.application.instance_id:${random.value}}
client:
serviceUrl:
defaultZone: http://eureka01/eureka/
I was trying to run the 3 eureka servers on my localhost, however the hostname being localhost for all 3 caused the above noted error. The error was resolved When I changed it by creating hostname entries in hosts file

How to config multiple Eureka Servers from client in Spring Cloud

From the spring doc, I see we can have peer eureka server together, so for Eureka1, in application.yml, I can have:
spring:
profiles: peer1
eureka:
instance:
hostname: peer1
client:
serviceUrl:
defaultZone: http://peer2/eureka/
And in Eureka Server 2, I can have:
spring:
profiles: peer2
eureka:
instance:
hostname: peer2
client:
serviceUrl:
defaultZone: http://peer1/eureka/
Now these two eureka servers are aware each other, it is good.
BUT, now in configuring client, when they register again Eureka, how to do this?
In my client application, I have:
eureka:
instance:
hostname: ${host.instance.name:localhost}
nonSecurePort: ${host.instance.port:8080}
leaseRenewalIntervalInSeconds: 5 #default is 30, recommended to keep default
metadataMap:
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
client:
serviceUrl:
defaultZone: http://(eurekaServerHost):8761/eureka/
server:
port: ${host.instance.port:8080}
So now my question is shall I use peer1 or peer2 as EurekaServerHost in the client application.yml?
Thanks
Use a comma separated list of peers in eureka.client.serviceUrl.defaultZone.
eureka.client.serviceUrl.defaultZone=http://<peer1host>:<peer1port>/eureka,http://<peer2host>:<peer2port>/eureka

Service instances register to both eureka services that are peers

We are running in a peer to peer Eureka configuration. See below for the configuration.
So when the services are started, they register to 10.202.10.95 (the primary) and we see them there with none showing on 10.202.10.97 (the secondary)
If we kill 10.202.10.95 (the primary) then we see them show up on 10.202.10.97 (the secondary eureka).
If we restart 10.202.10.95 (which was the primary), we see the services show up on 10.202.10.95 and also on 10.202.10.97. So services are visible on both eureka servers
If we restart 10.202.10.97 (the secondary), the services vanish and are just visible on the primary (10.202.10.95)
Case 3 is unexpected to me. Is this a case of improper peer to peer Eureka configuration?
The eureka configuration is as follows: (we point these 2 instances to each other in a peer to peer configuration)
spring:
profiles: api06-prod-int-discoveryserver # 10.202.10.95 eureka host
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://10.202.10.97:8761/eureka/
---
spring:
profiles: api05-prod-int-discoveryserver # 10.202.10.97 eureka host
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://10.202.10.95:8761/eureka/
Each service has its configuration to eureka set like this: (we point to both instances with x.x.x.95 being the primary)
eureka:
# these are settings for the client that gets services
client:
# enable these two settings if you want discovery to work
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://10.202.10.95:8761/eureka/,http://10.202.10.97:8761/eureka/
So, following some other posts and Spencer's response I checked and my configuration was incorrect. After I changed it, it responds correctly.
This is the Eureka settings. I run 2 eureka servers, one with profile peer1 and the other with profile peer2.
---
spring:
profiles: peer1 # not standalone
server:
port: 8761
eureka:
instance:
hostname: peer2
leaseRenewalIntervalInSeconds: 3
client:
serviceUrl:
defaultZone: http://localhost:8762/eureka/
---
spring:
profiles: peer2 # not standalone
server:
port: 8762
eureka:
instance:
hostname: peer1
leaseRenewalIntervalInSeconds: 3
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
server:
waitTimeInMsWhenSyncEmpty: 0
The Service that I have connecting is configured like this
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/
instance:
statusPageUrlPath: /${info.app.name}/manage/info
homePageUrlPath: /${info.app.name}/manage
healthCheckUrlPath: /${info.app.name}/manage/health
preferIpAddress: true
After I run my service, I can see it connect to both discovery services and if I kill either then it is visible on the other discovery service.