Configure Eureka Server and client with custom port and address - spring-cloud

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.

Related

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

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

Can we add #EnableEurekaServer for multiple main classes in single app?

Configure this SMS Server
eureka:
instance:
hostname: localhost
client: # Not a client, don't register with yourself
registerWithEureka: false
fetchRegistry: false
server:
port: 1111 # HTTP (Tomcat) port
Configure this Mail Server
eureka:
instance:
hostname: localhost
client: # Not a client, don't register with yourself
registerWithEureka: false
fetchRegistry: false
server:
port: 2222 # HTTP (Tomcat) port

Unable to run Spring Cloud Config-Server in Eureka First Bootstrap mode

*****Config Server- Application Service Setup*****
Below is the configuration from application.yml
server:
port: 8882
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
spring:
cloud:
config:
server:
git:uri: https://github.com/appleman/config
Below is the configuration from boostrap.yml
spring:
application:
name: configserver
Starting of this plain spring boot application registers config-server to Eureka.
**General Eureka Server is running on 8761 port
********Below is the Application Client configuration*****
Below is the Application Client configuration in my bootstrap.yml
spring:
application:
name: contractService,envDEV13
cloud:
config:
enabled: true
discovery:
enabled: true
serviceId: configserver
eureka:
instance:
nonSecurePort: ${server.port:8080}
client:
serviceUrl:
defaultZone: http://${eureka.host:localhost}:${eureka.port:8761}/eureka/
Injection of properties in Spring Controller like the below snippet is not working.
#Value("${creditService.eppDbUrl}")
String bar;
Please suggest us if we are doing anything wrong.

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.