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

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

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 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

Service don't want to register on Eureka with ssl

I need to use my micro-service with https so I change my Eureka configuration like this :
info:
component: Eureka
server:
port: 8761
ssl:
enabled: true
ciphers: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA
key-store: target/classes/keystore/keystore.jks
key-store-password: .....
key-alias: .....
key-password: .....
protocol: TLS
eureka:
instance:
hostname: localhost
securePort: ${server.port}
nonSecurePortEnabled: false
securePortEnabled: true
secureVirtualHostName: ${spring.application.name}
homePageUrl: https://${eureka.instance.hostname}:${server.port}/
statusPageUrl: https://${eureka.instance.hostname}:${server.port}/admin/info
metadataMap:
hostname : ${eureka.instance.hostname}
securePort: ${server.port}
client:
registerWithEureka: false
fetchRegistry: false
healthcheck:
enable: true
serviceUrl:
defaultZone: https://${eureka.instance.hostname}:${server.port}/eureka/
server:
waitTimeInMsWhenSyncEmpty: 0
enableSelfPreservation: true
It start without problem and I can go on the web-site.
My micro-service (configServer) running on https but don't register on Eureka. I don't have error message. The configuration file :
info:
component: Config Server
server:
port: 8889
ssl:
enabled: true
ciphers: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA
key-store: target/classes/keystore/keystore.jks
key-store-password: .....
key-alias: .....
key-password: ....
protocol: TLS
spring:
cloud:
config:
server:
git:
uri: .......
eureka:
client:
registerWithEureka: true
fetchRegistry: true
registryFetchIntervalSeconds: 5
securePortEnabled: true
serviceUrl:
defaultZone: https://127.0.0.1:8761/eureka/
healthcheck:
enabled: true
instance:
statusPageUrlPath: https://${management.context_path}/info
healthCheckUrlPath: https://${management.context_path}/health
leaseRenewalIntervalInSeconds: 10
securePort: ${server.port}
securePortEnabled: true
nonSecurePortEnabled: false
The log I get in Debug mode:
2016-11-29 10:47:35.324 DEBUG 12032 --- [freshExecutor-0] .a.h.i.c.DefaultClientConnectionOperator : Connecting to localhost:8761
2016-11-29 10:47:35.328 DEBUG 12032 --- [freshExecutor-0] o.a.h.impl.conn.DefaultClientConnection : Connection org.apache.http.impl.conn.DefaultClientConnection#f63e34a closed
2016-11-29 10:47:35.328 DEBUG 12032 --- [freshExecutor-0] o.a.h.impl.conn.DefaultClientConnection : Connection org.apache.http.impl.conn.DefaultClientConnection#f63e34a shut down
2016-11-29 10:47:35.328 DEBUG 12032 --- [freshExecutor-0] o.a.h.impl.conn.DefaultClientConnection : Connection org.apache.http.impl.conn.DefaultClientConnection#f63e34a closed
Without https, I don't have problem. Do you have an idea of what is wrong ?
your client has to be activated with
eureka:
client:
enabled: true
which is missing in your config servers configuration.
I had a similar issue: config server correctly registered over http but not over https (service is listed on Eureka but no host nor port is exposed).
Using spring-cloud-dependencies Edgware.RELEASE with spring-cloud-commons bumped to 1.3.1.RELEASE and a self-signed certificate (added to my JREs cacerts).
Here is the config I use that works both over http (no profile set) and https (https profile)
service-discovery application.properties
spring.application.name=service-discovery
server.port=8161
server.ssl.enabled=false
eureka.instance.hostname=${DISCOVERY_HOSTNAME}
eureka.instance.non-secure-port-enabled=true
eureka.instance.non-secure-port=${server.port}
eureka.instance.secure-port-enabled=false
eureka.client.serviceUrl.defaultZone=${DISCOVERY_SERVICE}
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=true
logging.level.com.netflix.eureka=OFF
logging.level.com.netflix.discovery=OFF
service-discovery application-https.properties
server.ssl.enabled=true
eureka.instance.non-secure-port-enabled=false
eureka.instance.secure-port-enabled=true
eureka.instance.secure-port=${server.port}
eureka.instance.statusPageUrl=https://${eureka.hostname}:${server.port}/info
eureka.instance.healthCheckUrl=https://${eureka.hostname}:${server.port}/health
eureka.instance.homePageUrl=https://${eureka.hostname}:${server.port}/
ribbon.IsSecure=true
config bootstrap.properties
eureka.client.serviceUrl.defaultZone=${DISCOVERY_SERVICE}
config application.properties
spring.application.name=config
server.port=8181
server.ssl.enabled=false
security.user.name=${SPRING_CLOUD_CONFIG_USERNAME}
security.user.password=${SPRING_CLOUD_CONFIG_PASSWORD}
security.user.role=SYSTEM
eureka.instance.non-secure-port-enabled=true
eureka.instance.non-secure-port=${DISCOVERY_PORT}
eureka.instance.secure-port-enabled=false
eureka.client.healthcheck.enabled=true
eureka.client.region=default
eureka.client.registry-fetch-interval-seconds=10
ribbon.IsSecure=true
config application-https.properties
server.ssl.enabled=true
eureka.instance.non-secure-port-enabled=false
eureka.instance.secure-port-enabled=true
eureka.instance.secure-port=${server.port}
eureka.instance.statusPageUrl=https://${eureka.hostname}:${server.port}/info
eureka.instance.healthCheckUrl=https://${eureka.hostname}:${server.port}/health
eureka.instance.homePageUrl=https://${eureka.hostname}:${server.port}/
ribbon.IsSecure=true
and here are the environment variables I use:
setx DISCOVERY_USERNAME "discoveryUser"
setx DISCOVERY_PASSWORD "change-me"
setx DISCOVERY_HOSTNAME "localhost"
setx DISCOVERY_PORT "8167"
setx DISCOVERY_SERVICE "http://${DISCOVERY_USERNAME}:${DISCOVERY_PASSWORD}#${DISCOVERY_HOSTNAME}:${DISCOVERY_PORT}/eureka/"
setx SPRING_CLOUD_CONFIG_SERVER_GIT_URI "C:/change-me/spring-rest-oauth-config"
setx SPRING_CLOUD_CONFIG_USERNAME "configUser"
setx SPRING_CLOUD_CONFIG_PASSWORD "change-me"
setx SPRING_CLOUD_CONFIG_DISCOVERY_SERVICE-ID "config"
rem something like "c:/users/ch4mp/.ssl/localhost-self-signed.p12"
setx SSL_KEY_STORE_PATH "change-me"
setx SERVER_SSL_KEY_STORE file:%SSL_KEY_STORE_PATH%
setx SERVER_SSL_KEY_STORE_PASSWORD "change-me"
setx SERVER_SSL_KEY_ALIAS "spring-rest-oauth"
setx SERVER_SSL_KEY_STORE_TYPE PKCS12
please note that DISCOVERY_SERVICE scheme must be modified to https when using https profile

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.