springCloud 之 Eureka注册中心高可用配置

时间:2023-03-09 18:22:57
springCloud 之 Eureka注册中心高可用配置

  springCloud的eureka高可用配置方案思路是:几个服务中心之间相互注册,比如两个注册中心,A注册到B上,B注册到A上,如果是三个注册中心则是:A注册到BC上,B注册到AC上,C注册到AB上,这样就会在几个注册中心间进行同步,同时服务提供方向三个注册中心均注册,这样就会保证当一个服务注册中心宕机的时候,不影响整个系统的正常运行,从而保证了eureka的高可用。本博主在最后验证了服务提供方仅注册到其中一个的方法,其高可靠性也是有保障的。所以服务提供方只需向服务注册中心之一提供注册就可以了,他们之间可以自行同步,保证高可用性。

  下面贴出主要的配置代码,其他的都一样,我们在这里主要贴出yml配置和控制台效果

8880

 #本项目端口
server:
port: 8880
#定义应用名称为order
spring:
application:
name: server
#服务注册中心实例主机名
eureka:
instance:
hostname: host
client:
#是否向注册中心注册自己
register-with-eureka: false
#是否获取注册表
fetch-registry: false
service-url:
defaultZone: http://127.0.0.1:8881/eureka/,http://127.0.0.1:8882/eureka/

8881

 #本项目端口
server:
port: 8881
#定义应用名称为order
spring:
application:
name: server1
#服务注册中心实例主机名
eureka:
instance:
hostname: host1
client:
#是否向注册中心注册自己
register-with-eureka: false
#是否获取注册表
fetch-registry: false
service-url:
defaultZone: http://127.0.0.1:8880/eureka/,http://127.0.0.1:8882/eureka/

8882

 server:
port: 8882
#定义应用名称为order
spring:
application:
name: server2
#服务注册中心实例主机名
eureka:
instance:
hostname: host2
client:
#是否向注册中心注册自己
register-with-eureka: true
#是否获取注册表
fetch-registry: false
#服务地址
service-url:
defaultZone: http://127.0.0.1:8880/eureka/,http://127.0.0.1:8881/eureka/

注意8880和8881未向自己注册,8002向自己注册,分别启动服务,8880和8881均未出现任何报错,而8882启动成功后会有超时报错信息

 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
2018-09-20 10:16:13.286 INFO 7944 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
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) . ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.5.RELEASE) 2018-09-20 10:16:13.560 INFO 7944 --- [ main] c.sharp.forward.EurekaServerApplication : No active profile set, falling back to default profiles: default
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
2018-09-20 10:16:14.384 INFO 7944 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=86aa96a4-8d41-33fd-af49-92950d537d77
2018-09-20 10:16:14.399 INFO 7944 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
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)
2018-09-20 10:16:14.932 INFO 7944 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8880 (http)
2018-09-20 10:16:14.951 INFO 7944 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-09-20 10:16:14.951 INFO 7944 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.34
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;;.]
2018-09-20 10:16:15.067 INFO 7944 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-09-20 10:16:15.067 INFO 7944 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1493 ms
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.
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.
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
2018-09-20 10:16:16.136 INFO 7944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-09-20 10:16:16.136 INFO 7944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webMvcMetricsFilter' to: [/*]
2018-09-20 10:16:16.136 INFO 7944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-09-20 10:16:16.136 INFO 7944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-09-20 10:16:16.136 INFO 7944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-09-20 10:16:16.137 INFO 7944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpTraceFilter' to: [/*]
2018-09-20 10:16:16.137 INFO 7944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'servletContainer' to urls: [/eureka/*]
2018-09-20 10:16:16.137 INFO 7944 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
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'
2018-09-20 10:16:16.251 INFO 7944 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
2018-09-20 10:16:16.252 INFO 7944 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
2018-09-20 10:16:16.348 INFO 7944 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
2018-09-20 10:16:16.348 INFO 7944 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
2018-09-20 10:16:16.561 WARN 7944 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
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.
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]
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
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)
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)
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>)
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>)
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]
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]
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/]
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
2018-09-20 10:16:17.321 INFO 7944 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2018-09-20 10:16:17.353 INFO 7944 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2018-09-20 10:16:17.353 INFO 7944 --- [ main] com.netflix.discovery.DiscoveryClient : Client configured to neither register nor query for data.
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
2018-09-20 10:16:17.409 INFO 7944 --- [ main] c.n.eureka.DefaultEurekaServerContext : Initializing ...
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/]
2018-09-20 10:16:17.612 INFO 7944 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
2018-09-20 10:16:17.612 INFO 7944 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
2018-09-20 10:16:17.612 INFO 7944 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
2018-09-20 10:16:17.612 INFO 7944 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
2018-09-20 10:16:17.696 INFO 7944 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
2018-09-20 10:16:17.696 INFO 7944 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
2018-09-20 10:16:17.696 INFO 7944 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
2018-09-20 10:16:17.696 INFO 7944 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
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/
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/
2018-09-20 10:16:17.762 INFO 7944 --- [ main] c.n.e.registry.AbstractInstanceRegistry : Finished initializing remote region registries. All known remote regions: []
2018-09-20 10:16:17.763 INFO 7944 --- [ main] c.n.eureka.DefaultEurekaServerContext : Initialized
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'
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>)
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>)
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)
2018-09-20 10:16:17.831 INFO 7944 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
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
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
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
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]
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]
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]
2018-09-20 10:16:17.863 INFO 7944 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
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
2018-09-20 10:16:17.881 INFO 7944 --- [ Thread-13] o.s.c.n.e.server.EurekaServerBootstrap : Setting the eureka configuration..
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
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
2018-09-20 10:16:17.892 INFO 7944 --- [ Thread-13] o.s.c.n.e.server.EurekaServerBootstrap : isAws returned false
2018-09-20 10:16:17.892 INFO 7944 --- [ Thread-13] o.s.c.n.e.server.EurekaServerBootstrap : Initialized server context
2018-09-20 10:16:17.892 INFO 7944 --- [ Thread-13] c.n.e.r.PeerAwareInstanceRegistryImpl : Got 1 instances from neighboring DS node
2018-09-20 10:16:17.892 INFO 7944 --- [ Thread-13] c.n.e.r.PeerAwareInstanceRegistryImpl : Renew threshold is: 1
2018-09-20 10:16:17.892 INFO 7944 --- [ Thread-13] c.n.e.r.PeerAwareInstanceRegistryImpl : Changing status to UP
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 ''
2018-09-20 10:16:17.909 INFO 7944 --- [ Thread-13] e.s.EurekaServerInitializerConfiguration : Started Eureka Server
2018-09-20 10:16:17.910 INFO 7944 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8880
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)
2018-09-20 10:16:21.748 INFO 7944 --- [nio-8880-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-09-20 10:16:21.748 INFO 7944 --- [nio-8880-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
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
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)
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 com.sun.jersey.api.client.ClientHandlerException: java.net.SocketTimeoutException: Read 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.netflix.eureka.cluster.DynamicGZIPContentEncodingFilter.handle(DynamicGZIPContentEncodingFilter.java:48) ~[eureka-core-1.9.3.jar:1.9.3]
at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.9.3.jar:1.9.3]
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]
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570) ~[jersey-client-1.19.1.jar:1.19.1]
at com.netflix.eureka.transport.JerseyReplicationClient.submitBatchUpdates(JerseyReplicationClient.java:116) ~[eureka-core-1.9.3.jar:1.9.3]
at com.netflix.eureka.cluster.ReplicationTaskProcessor.process(ReplicationTaskProcessor.java:80) ~[eureka-core-1.9.3.jar:1.9.3]
at com.netflix.eureka.util.batcher.TaskExecutors$BatchWorkerRunnable.run(TaskExecutors.java:187) [eureka-core-1.9.3.jar:1.9.3]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_171]
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_171]
at java.net.SocketInputStream.socketRead(Unknown Source) ~[na:1.8.0_171]
at java.net.SocketInputStream.read(Unknown Source) ~[na:1.8.0_171]
at java.net.SocketInputStream.read(Unknown Source) ~[na:1.8.0_171]
at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:161) ~[httpcore-4.4.10.jar:4.4.10]
at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:82) ~[httpcore-4.4.10.jar:4.4.10]
at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:278) ~[httpcore-4.4.10.jar:4.4.10]
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138) ~[httpclient-4.5.6.jar:4.5.6]
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56) ~[httpclient-4.5.6.jar:4.5.6]
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259) ~[httpcore-4.4.10.jar:4.4.10]
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:286) ~[httpcore-4.4.10.jar:4.4.10]
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:257) ~[httpclient-4.5.6.jar:4.5.6]
at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:230) ~[httpclient-4.5.6.jar:4.5.6]
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273) ~[httpcore-4.4.10.jar:4.4.10]
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125) ~[httpcore-4.4.10.jar:4.4.10]
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:684) ~[httpclient-4.5.6.jar:4.5.6]
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:486) ~[httpclient-4.5.6.jar:4.5.6]
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835) ~[httpclient-4.5.6.jar:4.5.6]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118) ~[httpclient-4.5.6.jar:4.5.6]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[httpclient-4.5.6.jar:4.5.6]
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
... 10 common frames omitted 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 com.sun.jersey.api.client.ClientHandlerException: java.net.SocketTimeoutException: Read 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.netflix.eureka.cluster.DynamicGZIPContentEncodingFilter.handle(DynamicGZIPContentEncodingFilter.java:48) ~[eureka-core-1.9.3.jar:1.9.3]
at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.9.3.jar:1.9.3]
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]
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570) ~[jersey-client-1.19.1.jar:1.19.1]
at com.netflix.eureka.transport.JerseyReplicationClient.submitBatchUpdates(JerseyReplicationClient.java:116) ~[eureka-core-1.9.3.jar:1.9.3]
at com.netflix.eureka.cluster.ReplicationTaskProcessor.process(ReplicationTaskProcessor.java:80) ~[eureka-core-1.9.3.jar:1.9.3]
at com.netflix.eureka.util.batcher.TaskExecutors$BatchWorkerRunnable.run(TaskExecutors.java:187) [eureka-core-1.9.3.jar:1.9.3]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_171]
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_171]
at java.net.SocketInputStream.socketRead(Unknown Source) ~[na:1.8.0_171]
at java.net.SocketInputStream.read(Unknown Source) ~[na:1.8.0_171]
at java.net.SocketInputStream.read(Unknown Source) ~[na:1.8.0_171]
at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:161) ~[httpcore-4.4.10.jar:4.4.10]
at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:82) ~[httpcore-4.4.10.jar:4.4.10]
at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:278) ~[httpcore-4.4.10.jar:4.4.10]
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138) ~[httpclient-4.5.6.jar:4.5.6]
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56) ~[httpclient-4.5.6.jar:4.5.6]
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259) ~[httpcore-4.4.10.jar:4.4.10]
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:286) ~[httpcore-4.4.10.jar:4.4.10]
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:257) ~[httpclient-4.5.6.jar:4.5.6]
at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:230) ~[httpclient-4.5.6.jar:4.5.6]
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273) ~[httpcore-4.4.10.jar:4.4.10]
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125) ~[httpcore-4.4.10.jar:4.4.10]
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:684) ~[httpclient-4.5.6.jar:4.5.6]
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:486) ~[httpclient-4.5.6.jar:4.5.6]
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835) ~[httpclient-4.5.6.jar:4.5.6]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118) ~[httpclient-4.5.6.jar:4.5.6]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[httpclient-4.5.6.jar:4.5.6]
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
... 10 common frames omitted 2018-09-20 10:17:17.897 INFO 7944 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
2018-09-20 10:18:17.897 INFO 7944 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
2018-09-20 10:19:17.898 INFO 7944 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
2018-09-20 10:20:17.898 INFO 7944 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
2018-09-20 10:21:17.899 INFO 7944 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
2018-09-20 10:22:17.899 INFO 7944 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms

这是因为服务向自己注册的原因,不用理会

此时查看控制台发现三个服务均注册上了server2

springCloud 之 Eureka注册中心高可用配置

springCloud 之 Eureka注册中心高可用配置

springCloud 之 Eureka注册中心高可用配置

如果三个服务都注册自己,则三个均注册上来,贴出其中一个图看看

springCloud 之 Eureka注册中心高可用配置

这时,eureka的高可用服务其实已经配置好了,我们进行一个注册服务,还是之前的client服务,配置文件修改后如下:

 spring:
application:
name: client
server:
port: 8889
eureka:
client:
eureka-server-port: 8889
register-with-eureka: true
service-url:
defaultZone: http://127.0.0.1:8880/eureka/,http://127.0.0.1:8881/eureka/,http://127.0.0.1:8882/eureka/

启动服务,三台服务均注册上

springCloud 之 Eureka注册中心高可用配置

然后我们请求服务方地址,成功

springCloud 之 Eureka注册中心高可用配置

此时验证高可用性,我们停掉其中的1~2台服务,再次访问,仍然OK,说明高可用配置的成功,接下来我们把client的yml文件注册地址只保留一个8880,再次测试,发现只注册一个三个都会同步,当宕掉8880和其他任意一个,仍然可以成功调用接口,可见其高可用性能得到了较好保证。