尤里卡客户不能够连接到同行服务(尤里卡客户)
我正在开发一个微服务应用程序使用春季,春季启动,尤里卡(服务发现)和function区。
我的应用程序由三个服务客户端,服务器和尤里卡服务器组成
客户端和服务器都使用尤里卡服务器进行注册,后来客户端使用尤里卡服务发现进行服务器调用。
我能够在本地运行应用程序,事情工作得很好。
但是,当部署在一些事情上会变得不合时宜。
步骤如下
- 同一安全组中的三个ec2实例。
- 每个微服务都作为docker集装箱正常运行,具有适当的端口。
- 一个ec2实例有弹性ip。 尤里卡服务器容器正在运行。
- 客户端和服务器容器部署在其他两个ec2实例上。
结果
使用ECS时
-
客户端和服务器能够向Eureka服务器注册。
Application AMIs Availability Zones Status HELLO-CLIENT n/a (1) (1) UP (1) - 3fcd1c92386d:hello-client:8071 HELLO-SERVER n/a (1) (1) UP (1) - 6a5d643b32e1:hello-server:8072
-
当遇到客户端端点java.net.UnknownHostException。
Whitelabel Error Page This application has no explicit mapping for /error,so you are seeing this as a fallback. Sun Sep 10 08:38:17 GMT 2017 There was an unexpected error (type=Internal Server Error, status=500). I/O error on GET request for "http://hello-server/hello/server/":6a5d643b32e1; nested exception is java.net.UnknownHostException: 6a5d643b32e1
使用Docker Swarm时
-
客户端和服务器能够向Eureka服务器注册。
Application AMIs Availability Zones Status HELLO-CLIENT n/a (1) (1) UP (1) - ip-10-255-0-5.ap-south-1.compute.internal:hello-client:8071 HELLO-SERVER n/a (1) (1) UP (1) - ip-10-255-0-6.ap-south-1.compute.internal:hello-server:8072
-
当达到客户端端点获取连接超时。
白标签错误页面
This application has no explicit mapping for /error, so you are seeing this as a fallback. Sun Sep 10 11:22:20 GMT 2017 There was an unexpected error (type=Internal Server Error, status=500). I/O error on GET request for "http://hello-server/hello/server/": Operation timed out (Connection timed out); nested exception is java.net.ConnectException: Operation timed out (Connection timed out)
尤里卡configuration
application.properties -------- spring.application.name=eureka-server server.port=8070 bootstrap.yml -------- eureka: client: registerWithEureka: false fetchRegistry: false server: waitTimeInMsWhenSyncEmpty: 0 service-url: defaultZone: http://<Elastic IP of eureka server>:8070/eureka
服务器configuration
application.properties -------- spring.application.name=hello-server server.port=8072 bootstrap.yml -------- eureka: client: service-url: defaultZone: http://<Elastic IP of eureka server>:8070/eureka
客户端configuration
application.properties -------- spring.application.name=hello-client server.port=8071 bootstrap.yml -------- eureka: client: service-url: defaultZone: http://<Elastic IP of eureka server>:8070/eureka
Rest客户端configuration
Resource.java --------------------------------- @Autowired RestTemplate restTemplate; @GetMapping @RequestMapping("/hello/client") public String hello(){ String uri = "http://hello-server/hello/server/"; return restTemplate.getForObject(uri, String.class); } Config.java ---------------------------- @LoadBalanced @Bean public RestTemplate restTemplate(){ return new RestTemplate(); }