springCloud的eureka高可用配置方案思路是:几个服务中心之间相互注册,比如两个注册中心,A注册到B上,B注册到A上,如果是三个注册中心则是:A注册到BC上,B注册到AC上,C注册到AB上,这样就会在几个注册中心间进行同步,同时服务提供方向三个注册中心均注册,这样就会保证当一个服务注册中心宕机的时候,不影响整个系统的正常运行,从而保证了eureka的高可用。本博主在最后验证了服务提供方仅注册到其中一个的方法,其高可靠性也是有保障的。所以服务提供方只需向服务注册中心之一提供注册就可以了,他们之间可以自行同步,保证高可用性。
下面贴出主要的配置代码,其他的都一样,我们在这里主要贴出yml配置和控制台效果
8880
1 #本项目端口
2 server:
3 port: 8880
4 #定义应用名称为order
5 spring:
6 application:
7 name: server
8 #服务注册中心实例主机名
9 eureka:
10 instance:
11 hostname: host
12 client:
13 #是否向注册中心注册自己
14 register-with-eureka: false
15 #是否获取注册表
16 fetch-registry: false
17 service-url:
18 defaultZone: http://127.0.0.1:8881/eureka/,http://127.0.0.1:8882/eureka/
19
8881
1 #本项目端口
2 server:
3 port: 8881
4 #定义应用名称为order
5 spring:
6 application:
7 name: server1
8 #服务注册中心实例主机名
9 eureka:
10 instance:
11 hostname: host1
12 client:
13 #是否向注册中心注册自己
14 register-with-eureka: false
15 #是否获取注册表
16 fetch-registry: false
17 service-url:
18 defaultZone: http://127.0.0.1:8880/eureka/,http://127.0.0.1:8882/eureka/
19
8882
1 server:
2 port: 8882
3 #定义应用名称为order
4 spring:
5 application:
6 name: server2
7 #服务注册中心实例主机名
8 eureka:
9 instance:
10 hostname: host2
11 client:
12 #是否向注册中心注册自己
13 register-with-eureka: true
14 #是否获取注册表
15 fetch-registry: false
16 #服务地址
17 service-url:
18 defaultZone: http://127.0.0.1:8880/eureka/,http://127.0.0.1:8881/eureka/
注意8880和8881未向自己注册,8002向自己注册,分别启动服务,8880和8881均未出现任何报错,而8882启动成功后会有超时报错信息
1 2018-09-20 10:16:13.038 INFO 7944 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@4ec4f3a0: startup date [Thu Sep 20 10:16:13 CST 2018]; root of context hierarchy
2 2018-09-20 10:16:13.286 INFO 7944 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
3 2018-09-20 10:16:13.307 INFO 7944 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$fbb30aa3] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
4
5 . ____ _ __ _ _
6 /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
7 ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
8 \\/ ___)| |_)| | | | | || (_| | ) ) ) )
9 ' |____| .__|_| |_|_| |_\__, | / / / /
10 =========|_|==============|___/=/_/_/_/
11 :: Spring Boot :: (v2.0.5.RELEASE)
12
13 2018-09-20 10:16:13.560 INFO 7944 --- [ main] c.sharp.forward.EurekaServerApplication : No active profile set, falling back to default profiles: default
14 2018-09-20 10:16:13.574 INFO 7944 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@74589991: startup date [Thu Sep 20 10:16:13 CST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@4ec4f3a0
15 2018-09-20 10:16:14.384 INFO 7944 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=86aa96a4-8d41-33fd-af49-92950d537d77
16 2018-09-20 10:16:14.399 INFO 7944 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
17 2018-09-20 10:16:14.477 INFO 7944 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$fbb30aa3] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
18 2018-09-20 10:16:14.932 INFO 7944 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8880 (http)
19 2018-09-20 10:16:14.951 INFO 7944 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
20 2018-09-20 10:16:14.951 INFO 7944 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.34
21 2018-09-20 10:16:14.958 INFO 7944 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [D:\topbandSoft\java\jre1.8\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:/topbandSoft/java/jre1.8/bin/server;D:/topbandSoft/java/jre1.8/bin;D:/topbandSoft/java/jre1.8/lib/amd64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Java\jre7;D:\topbandSoft\java\jdk1.8\bin;D:\topbandSoft\java\jdk1.8\jre\bin;D:\topbandSoft\git\Git\cmd;D:\topbandSoft\svn\bin;D:\topbandSoft\maven\apache-maven-3.3.9-bin\apache-maven-3.3.9\bin;C:\Program Files\bin;D:\topbandSoft\zookeeper/bin;D:\topbandSoft\zookeeper/conf;;D:\topbandSoft\eclipse4.8\eclipse;;.]
22 2018-09-20 10:16:15.067 INFO 7944 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
23 2018-09-20 10:16:15.067 INFO 7944 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1493 ms
24 2018-09-20 10:16:15.230 WARN 7944 --- [ost-startStop-1] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
25 2018-09-20 10:16:15.231 INFO 7944 --- [ost-startStop-1] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
26 2018-09-20 10:16:15.243 INFO 7944 --- [ost-startStop-1] c.netflix.config.DynamicPropertyFactory : DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration@7443d25a
27 2018-09-20 10:16:16.136 INFO 7944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
28 2018-09-20 10:16:16.136 INFO 7944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webMvcMetricsFilter' to: [/*]
29 2018-09-20 10:16:16.136 INFO 7944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
30 2018-09-20 10:16:16.136 INFO 7944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
31 2018-09-20 10:16:16.136 INFO 7944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
32 2018-09-20 10:16:16.137 INFO 7944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpTraceFilter' to: [/*]
33 2018-09-20 10:16:16.137 INFO 7944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'servletContainer' to urls: [/eureka/*]
34 2018-09-20 10:16:16.137 INFO 7944 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
35 2018-09-20 10:16:16.201 INFO 7944 --- [ost-startStop-1] c.s.j.s.i.a.WebApplicationImpl : Initiating Jersey application, version 'Jersey: 1.19.1 03/11/2016 02:08 PM'
36 2018-09-20 10:16:16.251 INFO 7944 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
37 2018-09-20 10:16:16.252 INFO 7944 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
38 2018-09-20 10:16:16.348 INFO 7944 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
39 2018-09-20 10:16:16.348 INFO 7944 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
40 2018-09-20 10:16:16.561 WARN 7944 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
41 2018-09-20 10:16:16.561 INFO 7944 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
42 2018-09-20 10:16:16.621 INFO 7944 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
43 2018-09-20 10:16:16.769 INFO 7944 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@74589991: startup date [Thu Sep 20 10:16:13 CST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@4ec4f3a0
44 2018-09-20 10:16:16.822 INFO 7944 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
45 2018-09-20 10:16:16.823 INFO 7944 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
46 2018-09-20 10:16:16.832 INFO 7944 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/],methods=[GET]}" onto public java.lang.String org.springframework.cloud.netflix.eureka.server.EurekaController.status(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.Object>)
47 2018-09-20 10:16:16.834 INFO 7944 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/lastn],methods=[GET]}" onto public java.lang.String org.springframework.cloud.netflix.eureka.server.EurekaController.lastn(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.Object>)
48 2018-09-20 10:16:16.858 INFO 7944 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
49 2018-09-20 10:16:16.858 INFO 7944 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
50 2018-09-20 10:16:17.166 INFO 7944 --- [ main] o.s.ui.freemarker.SpringTemplateLoader : SpringTemplateLoader for FreeMarker: using resource loader [org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@74589991: startup date [Thu Sep 20 10:16:13 CST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@4ec4f3a0] and template loader path [classpath:/templates/]
51 2018-09-20 10:16:17.167 INFO 7944 --- [ main] o.s.w.s.v.f.FreeMarkerConfigurer : ClassTemplateLoader for Spring macros added to FreeMarker configuration
52 2018-09-20 10:16:17.321 INFO 7944 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
53 2018-09-20 10:16:17.353 INFO 7944 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
54 2018-09-20 10:16:17.353 INFO 7944 --- [ main] com.netflix.discovery.DiscoveryClient : Client configured to neither register nor query for data.
55 2018-09-20 10:16:17.362 INFO 7944 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1537409777361 with initial instances count: 0
56 2018-09-20 10:16:17.409 INFO 7944 --- [ main] c.n.eureka.DefaultEurekaServerContext : Initializing ...
57 2018-09-20 10:16:17.412 INFO 7944 --- [ main] c.n.eureka.cluster.PeerEurekaNodes : Adding new peer nodes [http://127.0.0.1:8881/eureka/, http://127.0.0.1:8882/eureka/]
58 2018-09-20 10:16:17.612 INFO 7944 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
59 2018-09-20 10:16:17.612 INFO 7944 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
60 2018-09-20 10:16:17.612 INFO 7944 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
61 2018-09-20 10:16:17.612 INFO 7944 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
62 2018-09-20 10:16:17.696 INFO 7944 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
63 2018-09-20 10:16:17.696 INFO 7944 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
64 2018-09-20 10:16:17.696 INFO 7944 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
65 2018-09-20 10:16:17.696 INFO 7944 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
66 2018-09-20 10:16:17.756 INFO 7944 --- [ main] c.n.eureka.cluster.PeerEurekaNodes : Replica node URL: http://127.0.0.1:8881/eureka/
67 2018-09-20 10:16:17.756 INFO 7944 --- [ main] c.n.eureka.cluster.PeerEurekaNodes : Replica node URL: http://127.0.0.1:8882/eureka/
68 2018-09-20 10:16:17.762 INFO 7944 --- [ main] c.n.e.registry.AbstractInstanceRegistry : Finished initializing remote region registries. All known remote regions: []
69 2018-09-20 10:16:17.763 INFO 7944 --- [ main] c.n.eureka.DefaultEurekaServerContext : Initialized
70 2018-09-20 10:16:17.784 INFO 7944 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
71 2018-09-20 10:16:17.793 INFO 7944 --- [ main] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator/health],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
72 2018-09-20 10:16:17.793 INFO 7944 --- [ main] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator/info],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
73 2018-09-20 10:16:17.794 INFO 7944 --- [ main] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto protected java.util.Map<java.lang.String, java.util.Map<java.lang.String, org.springframework.boot.actuate.endpoint.web.Link>> org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping.links(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
74 2018-09-20 10:16:17.831 INFO 7944 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
75 2018-09-20 10:16:17.837 INFO 7944 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'environmentManager' has been autodetected for JMX exposure
76 2018-09-20 10:16:17.838 INFO 7944 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'refreshScope' has been autodetected for JMX exposure
77 2018-09-20 10:16:17.839 INFO 7944 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'configurationPropertiesRebinder' has been autodetected for JMX exposure
78 2018-09-20 10:16:17.841 INFO 7944 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'environmentManager': registering with JMX server as MBean [org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager]
79 2018-09-20 10:16:17.848 INFO 7944 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'refreshScope': registering with JMX server as MBean [org.springframework.cloud.context.scope.refresh:name=refreshScope,type=RefreshScope]
80 2018-09-20 10:16:17.855 INFO 7944 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'configurationPropertiesRebinder': registering with JMX server as MBean [org.springframework.cloud.context.properties:name=configurationPropertiesRebinder,context=74589991,type=ConfigurationPropertiesRebinder]
81 2018-09-20 10:16:17.863 INFO 7944 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
82 2018-09-20 10:16:17.867 INFO 7944 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application server with eureka with status UP
83 2018-09-20 10:16:17.881 INFO 7944 --- [ Thread-13] o.s.c.n.e.server.EurekaServerBootstrap : Setting the eureka configuration..
84 2018-09-20 10:16:17.881 INFO 7944 --- [ Thread-13] o.s.c.n.e.server.EurekaServerBootstrap : Eureka data center value eureka.datacenter is not set, defaulting to default
85 2018-09-20 10:16:17.881 INFO 7944 --- [ Thread-13] o.s.c.n.e.server.EurekaServerBootstrap : Eureka environment value eureka.environment is not set, defaulting to test
86 2018-09-20 10:16:17.892 INFO 7944 --- [ Thread-13] o.s.c.n.e.server.EurekaServerBootstrap : isAws returned false
87 2018-09-20 10:16:17.892 INFO 7944 --- [ Thread-13] o.s.c.n.e.server.EurekaServerBootstrap : Initialized server context
88 2018-09-20 10:16:17.892 INFO 7944 --- [ Thread-13] c.n.e.r.PeerAwareInstanceRegistryImpl : Got 1 instances from neighboring DS node
89 2018-09-20 10:16:17.892 INFO 7944 --- [ Thread-13] c.n.e.r.PeerAwareInstanceRegistryImpl : Renew threshold is: 1
90 2018-09-20 10:16:17.892 INFO 7944 --- [ Thread-13] c.n.e.r.PeerAwareInstanceRegistryImpl : Changing status to UP
91 2018-09-20 10:16:17.908 INFO 7944 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8880 (http) with context path ''
92 2018-09-20 10:16:17.909 INFO 7944 --- [ Thread-13] e.s.EurekaServerInitializerConfiguration : Started Eureka Server
93 2018-09-20 10:16:17.910 INFO 7944 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8880
94 2018-09-20 10:16:17.912 INFO 7944 --- [ main] c.sharp.forward.EurekaServerApplication : Started EurekaServerApplication in 5.373 seconds (JVM running for 5.771)
95 2018-09-20 10:16:21.748 INFO 7944 --- [nio-8880-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
96 2018-09-20 10:16:21.748 INFO 7944 --- [nio-8880-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
97 2018-09-20 10:16:21.766 INFO 7944 --- [nio-8880-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 16 ms
98 2018-09-20 10:17:07.667 INFO 7944 --- [io-8880-exec-10] c.n.e.registry.AbstractInstanceRegistry : Registered instance SERVER2/hh-PC:server2:8882 with status UP (replication=false)
99 2018-09-20 10:17:08.688 ERROR 7944 --- [et_127.0.0.1-18] c.n.e.cluster.ReplicationTaskProcessor : It seems to be a socket read timeout exception, it will retry later. if it continues to happen and some eureka node occupied all the cpu time, you should set property 'eureka.server.peer-node-read-timeout-ms' to a bigger value
100
101 com.sun.jersey.api.client.ClientHandlerException: java.net.SocketTimeoutException: Read timed out
102 at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
103 at com.netflix.eureka.cluster.DynamicGZIPContentEncodingFilter.handle(DynamicGZIPContentEncodingFilter.java:48) ~[eureka-core-1.9.3.jar:1.9.3]
104 at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.9.3.jar:1.9.3]
105 at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client-1.19.1.jar:1.19.1]
106 at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) ~[jersey-client-1.19.1.jar:1.19.1]
107 at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) ~[jersey-client-1.19.1.jar:1.19.1]
108 at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570) ~[jersey-client-1.19.1.jar:1.19.1]
109 at com.netflix.eureka.transport.JerseyReplicationClient.submitBatchUpdates(JerseyReplicationClient.java:116) ~[eureka-core-1.9.3.jar:1.9.3]
110 at com.netflix.eureka.cluster.ReplicationTaskProcessor.process(ReplicationTaskProcessor.java:80) ~[eureka-core-1.9.3.jar:1.9.3]
111 at com.netflix.eureka.util.batcher.TaskExecutors$BatchWorkerRunnable.run(TaskExecutors.java:187) [eureka-core-1.9.3.jar:1.9.3]
112 at java.lang.Thread.run(Unknown Source) [na:1.8.0_171]
113 Caused by: java.net.SocketTimeoutException: Read timed out
114 at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_171]
115 at java.net.SocketInputStream.socketRead(Unknown Source) ~[na:1.8.0_171]
116 at java.net.SocketInputStream.read(Unknown Source) ~[na:1.8.0_171]
117 at java.net.SocketInputStream.read(Unknown Source) ~[na:1.8.0_171]
118 at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:161) ~[httpcore-4.4.10.jar:4.4.10]
119 at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:82) ~[httpcore-4.4.10.jar:4.4.10]
120 at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:278) ~[httpcore-4.4.10.jar:4.4.10]
121 at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138) ~[httpclient-4.5.6.jar:4.5.6]
122 at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56) ~[httpclient-4.5.6.jar:4.5.6]
123 at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259) ~[httpcore-4.4.10.jar:4.4.10]
124 at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:286) ~[httpcore-4.4.10.jar:4.4.10]
125 at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:257) ~[httpclient-4.5.6.jar:4.5.6]
126 at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:230) ~[httpclient-4.5.6.jar:4.5.6]
127 at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273) ~[httpcore-4.4.10.jar:4.4.10]
128 at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125) ~[httpcore-4.4.10.jar:4.4.10]
129 at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:684) ~[httpclient-4.5.6.jar:4.5.6]
130 at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:486) ~[httpclient-4.5.6.jar:4.5.6]
131 at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835) ~[httpclient-4.5.6.jar:4.5.6]
132 at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118) ~[httpclient-4.5.6.jar:4.5.6]
133 at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[httpclient-4.5.6.jar:4.5.6]
134 at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
135 ... 10 common frames omitted
136
137 2018-09-20 10:17:08.693 ERROR 7944 --- [et_127.0.0.1-16] c.n.e.cluster.ReplicationTaskProcessor : It seems to be a socket read timeout exception, it will retry later. if it continues to happen and some eureka node occupied all the cpu time, you should set property 'eureka.server.peer-node-read-timeout-ms' to a bigger value
138
139 com.sun.jersey.api.client.ClientHandlerException: java.net.SocketTimeoutException: Read timed out
140 at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
141 at com.netflix.eureka.cluster.DynamicGZIPContentEncodingFilter.handle(DynamicGZIPContentEncodingFilter.java:48) ~[eureka-core-1.9.3.jar:1.9.3]
142 at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.9.3.jar:1.9.3]
143 at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client-1.19.1.jar:1.19.1]
144 at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) ~[jersey-client-1.19.1.jar:1.19.1]
145 at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) ~[jersey-client-1.19.1.jar:1.19.1]
146 at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570) ~[jersey-client-1.19.1.jar:1.19.1]
147 at com.netflix.eureka.transport.JerseyReplicationClient.submitBatchUpdates(JerseyReplicationClient.java:116) ~[eureka-core-1.9.3.jar:1.9.3]
148 at com.netflix.eureka.cluster.ReplicationTaskProcessor.process(ReplicationTaskProcessor.java:80) ~[eureka-core-1.9.3.jar:1.9.3]
149 at com.netflix.eureka.util.batcher.TaskExecutors$BatchWorkerRunnable.run(TaskExecutors.java:187) [eureka-core-1.9.3.jar:1.9.3]
150 at java.lang.Thread.run(Unknown Source) [na:1.8.0_171]
151 Caused by: java.net.SocketTimeoutException: Read timed out
152 at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_171]
153 at java.net.SocketInputStream.socketRead(Unknown Source) ~[na:1.8.0_171]
154 at java.net.SocketInputStream.read(Unknown Source) ~[na:1.8.0_171]
155 at java.net.SocketInputStream.read(Unknown Source) ~[na:1.8.0_171]
156 at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:161) ~[httpcore-4.4.10.jar:4.4.10]
157 at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:82) ~[httpcore-4.4.10.jar:4.4.10]
158 at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:278) ~[httpcore-4.4.10.jar:4.4.10]
159 at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138) ~[httpclient-4.5.6.jar:4.5.6]
160 at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56) ~[httpclient-4.5.6.jar:4.5.6]
161 at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259) ~[httpcore-4.4.10.jar:4.4.10]
162 at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:286) ~[httpcore-4.4.10.jar:4.4.10]
163 at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:257) ~[httpclient-4.5.6.jar:4.5.6]
164 at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:230) ~[httpclient-4.5.6.jar:4.5.6]
165 at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273) ~[httpcore-4.4.10.jar:4.4.10]
166 at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125) ~[httpcore-4.4.10.jar:4.4.10]
167 at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:684) ~[httpclient-4.5.6.jar:4.5.6]
168 at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:486) ~[httpclient-4.5.6.jar:4.5.6]
169 at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835) ~[httpclient-4.5.6.jar:4.5.6]
170 at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118) ~[httpclient-4.5.6.jar:4.5.6]
171 at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[httpclient-4.5.6.jar:4.5.6]
172 at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
173 ... 10 common frames omitted
174
175 2018-09-20 10:17:17.897 INFO 7944 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
176 2018-09-20 10:18:17.897 INFO 7944 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
177 2018-09-20 10:19:17.898 INFO 7944 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
178 2018-09-20 10:20:17.898 INFO 7944 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
179 2018-09-20 10:21:17.899 INFO 7944 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
180 2018-09-20 10:22:17.899 INFO 7944 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
这是因为服务向自己注册的原因,不用理会
此时查看控制台发现三个服务均注册上了server2
如果三个服务都注册自己,则三个均注册上来,贴出其中一个图看看
这时,eureka的高可用服务其实已经配置好了,我们进行一个注册服务,还是之前的client服务,配置文件修改后如下:
1 spring:
2 application:
3 name: client
4 server:
5 port: 8889
6 eureka:
7 client:
8 eureka-server-port: 8889
9 register-with-eureka: true
10 service-url:
11 defaultZone: http://127.0.0.1:8880/eureka/,http://127.0.0.1:8881/eureka/,http://127.0.0.1:8882/eureka/
启动服务,三台服务均注册上
然后我们请求服务方地址,成功
此时验证高可用性,我们停掉其中的1~2台服务,再次访问,仍然OK,说明高可用配置的成功,接下来我们把client的yml文件注册地址只保留一个8880,再次测试,发现只注册一个三个都会同步,当宕掉8880和其他任意一个,仍然可以成功调用接口,可见其高可用性能得到了较好保证。