I would like to register my service with the Eureka server, using a specific Hostname or IP.
This is my configuration snippet:
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka
instance:
preferIpAddress: true
hostname: localhost
ipAddr: 127.0.0.1
I am using the 2.0.2.RELEASE version of client.
I would expect the service to register with 127.0.0.1; if I switch preferIpAddress to false, I would expect it to register with localhost.
Instead, I always get this:
APPLICATION/1H1DNQ2.mshome.net:application:8080 -
Re-registering apps/APPLICATION
1H1DNQ2 is my PC id. I also tried using eureka.hostname, same result.
I was able to get it to identify with the hostname of my choice using this snippet:
spring:
cloud:
client:
hostname: localhost
I found the inspiration on this article.
I think this is sort of a workaround though and I am still looking for a more specific solution.
Related
I have the following setup:
eureka server
api gateway
auth service
Api gateway yml:
server:
port: 8081
spring:
application:
name: api-gateway
zipkin:
base-url: http://localhost:9411
cloud:
gateway:
discovery:
locator:
enabled: true
lower-case-service-id: true
routes:
- id: auth
uri: lb://auth
predicates:
- Path=/api/user/**
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka
fetch-registry: true
register-with-eureka: true
instance:
prefer-ip-address: true
hostname: localhost
Auth service yml:
server:
port: 8080
spring:
application:
name: auth
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka
fetch-registry: true
register-with-eureka: true
instance:
prefer-ip-address: true
hostname: localhost
On the eureka web dashboard both services are showing correctly. Now, I want to test the auth service with the endpoint /api/user/signup.
If I fire a post request like this:
http://localhost:8081/auth/api/user/signup
or like this:
http://localhost:8081/api/user/signup
Before adding
instance:
prefer-ip-address: true
hostname: localhost
I got an unknown host exception, how I get this:
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: /192.168.0.104:8080
I'm currently at home, but router and wifi works. But indeed, if I copy in the browser the 192.168.0.104, then I get connection timeout.
I'm developing this app on a company laptop (which has it's own domain), and which I use at home on my own network. Maybe this can be relevant. Basically I just want to use localhost. But how?
Thanks for taking the time to read my post.
My issue is as such. I have 2 microservices (auth-service and image-service) deployed on Heroku, as well as a server Eureka and a gateway Zuul.
In local, all of this works.
However, when deployed, the same calls give me 404 errors : for example :
zuul is deployed on port 8762 in local,
so http://localhost:8762/images/user/create works, it points to http://localhost:8200/user/create of the image-service.
Deployed, https://croquis-time-image.herokuapp.com/user/create works, but https://croquis-time-zuul.herokuapp.com/images/user/create throws a 404 error.
On eureka however, all my services are registered, so the trouble doesn't come from there. I thought perhaps zuul didn't manage to get all the services from Eureka, but I'm not sure how to check.
More information :
application.yml of zuul deployed :
server:
port: 8762
eureka:
client:
serviceUrl:
defaultZone: https://croquis-time-eureka.herokuapp.com/eureka/
instance:
hostName: croquis-time-eureka.herokuapp.com
zuul:
#Service will be mapped under the /api URI
prefix: /api
# Uncomment to disable auto-registering all services read from Eureka
# ignoredServices: '*'
routes:
image-service:
path: /images/**
serviceId: image-service
auth-service:
path: /auth/**
serviceId: auth-service
stripPrefix: false
sensitiveHeaders: Cookie,Set-Cookie
spring:
application:
name: zuul-server
security:
jwt:
uri: /auth/**
prefix: Bearer
expiration: 86400
header: Authorization
secret: *****************
The application.yml of eureka deployed
server:
port: 8761
eureka:
instance:
hostname: croquis-time-eureka.herokuapp.com
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: https://croquis-time-eureka.herokuapp.com/eureka/
spring:
application:
name: eureka-server
The image service I'm trying to call :
server:
port: 8200
eureka:
client:
serviceUrl:
defaultZone: https://croquis-time-eureka.herokuapp.com/eureka/
instance:
hostName: croquis-time-eureka.herokuapp.com
spring:
application:
name: image-service
jpa:
showSql: true
hibernate:
ddlAuto: update
datasource:
url: jdbc:mysql://***********:3306/croquis-time
username: ******************
password: ****************
I have tried removing and adding the "ignored-services" from zuul to see if that was the problem, but it didn't change anything.
I'm very willing to edit my question with more information if you require more, I'm not sure where is the origin of the problem, so I'm a bit at a loss as to what to add.
Thanks !
you have an issue with the configuration of .yml in zuul server
Your .yml of zuul server must be:
instance:
hostName: croquis-time-zuul.herokuapp.com
And your .yml of image must be:
instance:
hostName: croquis-time-image.herokuapp.com
because instance.hostname is the host of your application acting as the eureka client. if you need more information please visit: https://blog.heroku.com/managing_your_microservices_on_heroku_with_netflix_s_eureka
I'm trying to use docker-compose to run 2 simple services locally (Ubuntu): a eureka server, and config server (which is also a eureka client). Both of these have simple dockerfiles that run java -jar, expose their ports, and individually work fine. I also tried to add eureka.client.service-url.defaultZone=http://company-service-discovery:8761/eureka to see if it would register itself, and it worked.
My config server cannot successfully register to the eureka server, and I've googled it and nothing I've seen helped me solve this.
According to docker-compose documentation at https://docs.docker.com/compose/networking/ :
By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.
With the following example web should be able to use postgres://db:5432 to communicate with the database.
version: "3"
services:
web:
build: .
ports:
- "8000:8000"
db:
image: postgres
ports:
- "8001:5432"
I have used the same method to configure my services, but my config server gets connection refused when trying to register:
docker-compose.yml
version: '3.3'
services:
company-service-discovery:
build: company-service-discovery/
ports:
- "8761:8761"
company-config-server:
build: company-config-server/
ports:
- "8888:8888"
links:
- company-service-discovery
config server bootstrap.yml
server:
port: 8888
management:
security:
enabled: false
spring:
application:
name: company-config-server
cloud:
config:
server:
native:
search-locations: classpath:/shared
profiles:
include: native
eureka:
client:
service-url:
defaultZone: http://company-service-discovery:8761/eureka
eureka server bootstrap.yml
spring:
application:
name: company-service-discovery
server:
port: 8761
management:
security:
enabled: false
exception
2017-07-26 14:25:05.738 WARN 1 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused)
2017-07-26 14:25:05.739 WARN 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_COMPANY-CONFIG-SERVER/365d20275ab0:company-config-server:8888 - registration failed Cannot execute request on any known server
question
Is there anything wrong with my configuration ? How can I make it work ?
Let me know if there's any info missing, I'll gladly give any info I can.
Add the defaultZone configuration to the Eureka server's properties too (and change the service-url to serviceUrl in your config server bootstrap.yml).
eureka server bootstrap.yml
spring:
application:
name: company-service-discovery
eureka:
client:
serviceUrl:
defaultZone: http://company-service-discovery:8761/eureka
server:
port: 8761
management:
security:
enabled: false
Thank you sooo much. this post resolved my problem - connecting eureka client to eureka server with docker. After 2 days of searching it work. I am in tears.
So basically -
you should use following in eureka client's application.properties/.yml
eureka.client.service-url.defaultZone=http://eureka-server:8761/eureka
and in docker-compose.yml your eureka service name should match with - the url host name, in my case it is - eureka-server
I am trying to register an application available through https only. I have problem with correct configuration and links displayed in eureka's dashboard are not correct. I have tried some configurations but I can't get the right effect i.e. working dashboard links in Eureka.
My base configuration.
server:
port: 9999
context-path: /ctx
ssl:
key-store: classpath:keystore.jks
key-store-password: 'kspass'
key-password: 'kpass'
keyAlias: ssl
spring:
application:
name: app-ctx
cloud:
loadbalancer:
retry:
enabled: true
eureka:
client:
serviceUrl:
defaultZone: https://localhost:8761/eureka/
instance:
hostname: localhost
secure-port-enabled: true
non-secure-port-enabled: false
secure-port: ${server.port}
health-check-url: https://${eureka.hostname}:XYZ/ctx/health
status-page-url: https://${eureka.hostname}:XYZ/ctx/info
home-page-url: https://${eureka.hostname}:XYZ/ctx
I have tried following versions of health/status/home URLs:
Absolute URLs without port
Example: health-check-url: https://${eureka.hostname}/ctx/health
Result: https://localhost/ctx/info
Absolute URLs with ${server.port} replacement
Example: health-check-url: https://${eureka.hostname}:${server.port}/ctx/health)
Result: ${server.port} not resolved, url in dashboard is:
https://localhost:${server.port}/ctx/info
Relative URLs
Example: health-check-url-path: /ctx/health
Result:
http://localhost:9999/ctx/info, no https.
Last one is quite close to my expectations, but there is no https.
Finally I've got solution for my problem. Not sure it that's the best one because as far as I can see it doesn't work with random ports i.e. server.port = 0. In that case eureka registers application with port 0 and on dashboard there is link with port that does not forward to correct location and that's not expected behavior.
Instead of using ${server.port} placeholder that is related to current application we have to use eureka's part of configuration ${eureka.instance.secure-port} i.e.
server:
port: 9999
context-path: /ctx
ssl:
key-store: classpath:keystore.jks
key-store-password: 'kspass'
key-password: 'kpass'
keyAlias: ssl
spring:
application:
name: app-ctx
cloud:
loadbalancer:
retry:
enabled: true
eureka:
client:
serviceUrl:
defaultZone: https://localhost:8761/eureka/
instance:
hostname: localhost
secure-port-enabled: true
non-secure-port-enabled: false
secure-port: ${server.port}
health-check-url: https://${eureka.instance.hostname}:${eureka.instance.secure-port}/ctx/health
status-page-url: https://${eureka.instance.hostname}:${eureka.instance.secure-port}/ctx/info
home-page-url: https://${eureka.instance.hostname}:${eureka.instance.secure-port}/ctx
Eureka does not recognized HTTPS endpoints like '/info' and '/health' and always points to HTTP endpoints after enabling HTTPS. How to enable HTTPS micro-service url registration at Eureka ?
You have to explicitly define these URLs as Eureka always points to HTTP internally. Read Here for more about it.
You can add following into your yaml file in the microservice.
eureka:
instance:
nonSecurePortEnabled: false
securePortEnabled: true
statusPageUrl: 'https://${eureka.instance.hostName}:${server.port}/info'
healthCheckUrl: 'https://${eureka.instance.hostName}:${server.port}/health'
homePageUrl: 'https://${eureka.instance.hostName}:${server.port}/'
Here "eureka.instance.hostName" and "server.port" values will be taken from the environment.
For me this configuration works:
eureka:
instance:
nonSecurePortEnabled: false
securePortEnabled: true
securePort: ${server.port}
statusPageUrl: https://${eureka.instance.hostname}:${eureka.instance.securePort}/info
homePageUrl: https://${eureka.instance.hostname}:${eureka.instance.securePort}/
For me below configuration works fine:-
eureka:
instance:
statusPageUrl: https://${eureka.hostname}:${server.port}/actuator/info
healthCheckUrl: https://${eureka.hostname}:${server.port}/health
homePageUrl: https://${eureka.hostname}:${server.port}/