日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

第十篇: 高可用的服务注册中心(Finchley版本)V2.0_dev

發布時間:2024/9/27 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 第十篇: 高可用的服务注册中心(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
配置信息修改如下:

eureka:client:registerWithEureka: falsefetchRegistry: falseserviceUrl:defaultZone: http://localhost:8762/eureka/,http://localhost:8763/eureka/ spring:application:name: eurka-server

第一步:啟動以第1個eureka-server實例:
-Dserver.port=8762
配置信息修改如下:

eureka:client:registerWithEureka: falsefetchRegistry: falseserviceUrl:defaultZone: http://localhost:8761/eureka/,http://localhost:8763/eureka/ spring:application:name: eurka-server

第三步:啟動以第1個eureka-server實例:
-Dserver.port=8763
配置信息修改如下:

eureka:client:registerWithEureka: falsefetchRegistry: falseserviceUrl:defaultZone: http://localhost:8762/eureka/,http://localhost:8761/eureka/ spring:application:name: eurka-server

依次訪問: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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。