spring-cloud - Spring 客户端无法注册 Eureka (MiniShift)
问题描述
我的 Spring Eureka 服务器 YAML 配置。这是
spring:
application:
name: discovery-service
eureka:
instance:
hostname: spring-cloud-gateway.discovery.svc # it should be service url in openshift cluster.
client:
eureka-server-connect-timeout-seconds: 5
enabled: true
fetch-registry: false
register-with-eureka: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
server:
port: 8761
我使用显示在 OpenShift 控制台上的服务器 URL。
selectors:
app=spring-cloud-gateway, deploymentconfig=spring-cloud-gateway
Type:
ClusterIP
IP:
172.30.167.146
Hostname:
spring-cloud-gateway.discovery.svc
Session affinity:
None
显示尤里卡服务器状态的日志是这样的。
2019-08-21 09:01:00.921 INFO 7 --- [ Thread-11] e.s.EurekaServerInitializerConfiguration : Started Eureka Server
2019-08-21 09:01:00.991 INFO 7 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8761 (http) with context path ''
2019-08-21 09:01:00.998 INFO 7 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8761
2019-08-21 09:01:01.007 INFO 7 --- [ main] c.o.g.DiscoveryServiceApplication : Started DiscoveryServiceApplication in 56.204 seconds (JVM running for 66.164)
2019-08-21 09:02:00.839 INFO 7 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
2019-08-21 09:03:00.839 INFO 7 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
2019-08-21 09:04:00.841 INFO 7 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 1ms
2019-08-21 09:05:00.843 INFO 7 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 2ms
2019-08-21 09:06:00.843 INFO 7 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
2019-08-21 09:07:00.843 INFO 7 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
2019-08-21 09:08:00.851 INFO 7 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 8ms
2019-08-21 09:09:00.856 INFO 7 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 4ms
2019-08-21 09:10:00.860 INFO 7 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 4ms
2019-08-21 09:10:59.206 WARN 7 --- [eerNodesUpdater] c.n.eureka.cluster.PeerEurekaNodes : The replica size seems to be empty. Check the route 53 DNS Registry
2019-08-21 09:11:00.865 INFO 7 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 4ms
2019-08-21 09:12:00.866 INFO 7 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
2019-08-21 09:13:00.885 INFO 7 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 18ms
REST 端点客户端 YAML 配置。这是。
spring:
application:
name: second-service
server:
port: 8087
eureka:
instance:
preferIpAddress: false
client:
service-url:
defaultZone: http://spring-cloud-gateway.discovery.svc:8761/eureka/
它似乎没有注册。
2019-08-21 09:46:12.416 ERROR 7 --- [tbeatExecutor-0] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error.
endpoint=DefaultEndpoint{ serviceUrl='http://spring-cloud-gateway.discovery.svc:8761/eureka/ }
com.sun.jersey.api.client.ClientHandlerException: org.apache.http.conn.ConnectTimeoutException: Connect to spring-cloud-gateway.discovery.svc:8761 timed out
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar!/:1.19.1]
at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123) ~[jersey-client-1.19.1.jar!/:1.19.1]
at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.9.8.jar!/:1.9.8]
at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client-1.19.1.jar!/:1.19.1]
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) ~[jersey-client-1.19.1.jar!/:1.19.1]
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) ~[jersey-client-1.19.1.jar!/:1.19.1]
我尝试使用公开的 URL ( http://spring-cloud-gateway-discovery.192.168.42.79.nip.io/eureka ) 检查 eureka 服务器的 Web ui,但我得到了这个页面。
NAME HOST/PORT PATH SERVICES PORT T
ERMINATION WILDCARD
route.route.openshift.io/spring-cloud-gateway spring-cloud-gateway-discovery.192.168.42.79.nip.io spring-cloud-gateway 8080-tcp
None
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/spring-cloud-gateway ClusterIP 172.30.167.146 <none> 8080/TCP 23h
服务器或客户端有问题吗?
eureka 服务器是 project-1 的一部分,其余服务客户端是 project-2 的一部分。这就是我在 Openshift 控制台中设置它的方式。那是问题吗 ?我不这么认为。
更新:我将所有内容都移到了同一个项目中,但它仍然显示错误。
2019-08-22 06:45:39.412 WARN 7 --- [tbeatExecutor-0] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution
failed with message: org.apache.http.conn.ConnectTimeoutException: Connect to spring-cloud-gateway.discovery.svc:8761 timed
out
2019-08-22 06:45:39.413 ERROR 7 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_SE
COND-SERVICE/spring-cloud-gateway-5-bh8rj:second-service:8087 - was unable to send heartbeat!
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
解决方案
您的错误日志显示“超时”和“无法发送心跳”,这可能是客户端注册表问题,由运行 docker 容器以使用 yml/properties 文件中指定的端口启动服务引起。
当我将微服务部署到 Cloud Foundry 时,我遇到了同样的问题,尽管我可以在本地成功运行它们。我想根本原因是一样的。
解决方案:使用安全/非安全端口而不是“server.port”。
这是示例(使用非安全端口),祝您好运。
http://spring-cloud-gateway.discovery.svc/eureka/apps
如果您仍然有 eureka 服务器和客户端之间的连接问题,您可以尝试找出详细信息。
尤里卡服务器:
spring:
application:
name: discovery-service
eureka:
instance:
hostname: spring-cloud-gateway.discovery.svc
nonSecurePortEnabled: true
nonSecurePort: 80
homePageUrl: http://${eureka.instance.hostname}/
statusPageUrl: http://${eureka.instance.hostname}/actuator/info/
healthCheckUrl: http://${eureka.instance.hostname}/actuator/health/
client:
fetch-registry: false
register-with-eureka: false
service-url:
defaultZone: http://${eureka.instance.hostname}/eureka/
尤里卡客户端:
spring:
application:
name: second-service
eureka:
instance:
nonSecurePortEnabled: true
nonSecurePort: 80
hostname: <your_client_host> # or you can use preferIpAddress: true
homePageUrl: http://${eureka.instance.hostname}/
client:
service-url:
defaultZone: http://spring-cloud-gateway.discovery.svc/eureka/
推荐阅读
- reactjs - React redux 不更新数据
- excel - VBA如何从不同的工作表中打印出单元格
- java - 从两个列表中删除元素的方法
- sql-server - 如何解决以下 SQL 查询?
- php - 来自 S3 存储桶的流式视频无法在 Safari 浏览器上运行
- javascript - 将 JavaScript JSON 对象与匹配的参数合并
- android - Seek Bar Preference 不更新其值
- javascript - 为什么我不能通过 JS 函数更改我的内部 HTML?
- java - 在我自己的单链表实现中插入数据
- go - gobuffalo/packr 如何(为什么)在构建时运行?