当前位置:
首页 >
第十篇: 高可用的服务注册中心(Finchley版本)V2.0_dev
发布时间:2024/9/27
38
豆豆
生活随笔
收集整理的这篇文章主要介绍了
第十篇: 高可用的服务注册中心(Finchley版本)V2.0_dev
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
一、准备工作
Eureka通过运行多个实例,使其更具有高可用性。事实上,这是它默认的熟性,你需要做的就是给对等的实例一个合法的关联serviceurl。
二、创建eureka-server
引入依赖
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency>添加配置信息
eureka:client:registerWithEureka: falsefetchRegistry: falseserviceUrl:defaultZone: http://localhost:8762/eureka/,http://localhost:8763/eureka/ spring:application:name: eurka-server运行主类
@SpringBootApplication @EnableEurekaServer public class EurekaServerApplication {public static void main(String[] args) {SpringApplication.run(EurekaServerApplication.class, args);}}分别启动3个eureka-server实例,
第一步:启动以第1个eureka-server实例:
-Dserver.port=8761
配置信息修改如下:
第一步:启动以第1个eureka-server实例:
-Dserver.port=8762
配置信息修改如下:
第三步:启动以第1个eureka-server实例:
-Dserver.port=8763
配置信息修改如下:
依次访问:localhost:8761、localhost:8761、localhost:8761
可以看到运行了3个eureka-serser实例
创建eureka-client工程
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId> </dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>启动主类
@SpringBootApplication @EnableEurekaClient @EnableDiscoveryClient public class ServiceHiApplication {public static void main(String[] args) {SpringApplication.run(ServiceHiApplication.class, args);} }配置文件
server:port: 8765spring:application:name: service-hieureka:client:serviceUrl:defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/,http://localhost:8763/eureka/web访问
@RestController public class HiController {@Value("${server.port}")private String port;@GetMapping("/hi")public String home(@RequestParam(value = "name", defaultValue = "gblfy") String name) {return "hi," + name + ",i am from port" + port;} }启动eureka-client,
再依次访问:localhost:8761、localhost:8761、localhost:8761
发现eureka-client已经成功注册到3个eureka-server服务端了,本次策略采取的是,eureka-server两两注册,就算其中一个宕机了,也不会影响服务的发现和注册。
当然eureka-client建议采用集群策略,以达到高可用
总结
以上是生活随笔为你收集整理的第十篇: 高可用的服务注册中心(Finchley版本)V2.0_dev的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: gradle下载及配置
- 下一篇: 使用Jenkins搭建自动化测试环境_环