国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > Java > 正文

spring cloud config分布式配置中心的高可用問題

2024-07-13 10:17:00
字體:
來源:轉載
供稿:網友

在前面的文章中,我們實現了配置文件統一管理的功能,但是我們可以發現,我們僅僅只用了一個server,如果當這個server掛掉的話,整個配置中心就會不可用,下面,我們就來解決配置中心的高可用問題。

下面我們通過整合Eureka來實現配置中心的高可用,因為作為架構內的配置管理,本身其實也是可以看作架構中的一個微服務,我們可以把config server也注冊為服務,這樣所有客戶端就能以服務的方式進行訪問。通過這種方法,只需要啟動多個指向同一Gitlab倉庫位置的config server端就能實現高可用了。

一、Config Server端加入Eureka

1、加入Eureka依賴

<dependency>    <groupId>org.springframework.cloud</groupId>    <artifactId>spring-cloud-starter-eureka</artifactId>   </dependency> 

2、添加Eureka支持,將配置服務注冊到Eureka上去

@EnableEurekaClient 

3、修改Server端的配置文件

加入Eureka注冊的配置,bootstrap.yml

server:  port: 8889 eureka:  client:  service-url:   defaultZone: http://localhost:8761/eureka  instance:  prefer-ip-address: true spring:  application:   name: foo  cloud:  config:   server:   git:    uri: <span>https://gitlab.xxx.com/xxxxx/xxxxx.git</span>  # 配置gitlab倉庫的地址    search-paths: <span>/config-repo</span> # gitlab倉庫地址下的相對地址,可以配置多個,用,分割。    username: your name  # gitlab倉庫的賬號    password: your password # gitlab倉庫的密碼 

啟動Config Server

4、修改端口號,再啟動一個Config Server

5、查看服務是否注冊成功

二、Config 客戶端加入Eureka

1、加入Eureka的pom依賴,同Config Server

2、修改Config客戶端的配置文件

bootstrap.properties經過測試,此處客戶端只能是bootstrap.properties,否則會一直連端口8888

server.port=8890 spring.application.name=configserver spring.cloud.config.name=configserver spring.cloud.config.profile=dev spring.cloud.config.label=master # 開啟Config服務發現支持 spring.cloud.config.discovery.enabled=true # 此處需要設置成Config Server在Eureka上注冊的服務名 spring.cloud.config.discovery.service-id=foo # 指定服務發現中心 eureka.client.service-url.defaultZone=http://localhost:8761/eureka 

其中,通過eureka.client.service-url.defaultZone參數指定服務注冊中心,用于服務的注冊與發現,再將spring.cloud.config.discovery.enabled參數設置為true,開啟通過服務來訪問Config Server的功能,最后利用spring.cloud.config.discovery.serviceId參數來指定Config Server注冊的服務名。這里的spring.application.name和spring.cloud.config.profile和前面博客中的意義一致。

3、在Application主類上添加Eureka支持,同Config Server一致

三、驗證

1、查看Eureka Server上的服務

spring,cloud,config,分布式,高可用

2、查看Config Server是否正常

在瀏覽器中分別輸入:http://localhost:8888/configserver/dev/master,http://localhost:8889/configserver/dev/master,看是否有返回結果如下:

{   "name": "configserver",  "profiles": [   "dev"  ],  "label": "master",  "version": "8949024814dcb6d61f97dc49db7e9dadcfc724b1",  "state": null,  "propertySources": [   {    "name": "https://gitlab.xxx.com/xxxxx/xxxxx/project/config-repo/configserver.properties",    "source": {     "name": "chhliuxyh",     "hello": "i'm the king of the world!!!",     "profile": "profile-default"    }   }  ]  } 

3、查看客戶端是否正常

在瀏覽器中輸入http://localhost:8890/hello,看是否有如下返回

i'm the king of the world!!!

如果上面幾步正常,則說明是ok的。

4、將8888端口對應的Config Server停掉,然后重新輸入http://localhost:8890/hello,看是否ok!我們發現仍然是ok的,這樣我們就完成了配置中心的高可用了!

<pre code_snippet_id="2245130" snippet_file_name="blog_20170306_4_711400"></pre> <pre></pre> <pre></pre> 

總結

以上所述是小編給大家介紹的spring cloud config分布式配置中心的高可用實現方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VeVb武林網網站的支持!


注:相關教程知識閱讀請移步到JAVA教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 湟源县| 平湖市| 买车| 册亨县| 高清| 墨脱县| 周宁县| 连云港市| 彭水| 武穴市| 盐源县| 嘉义县| 阜城县| 读书| 博兴县| 四会市| 息烽县| 红安县| 舒兰市| 定西市| 远安县| 南陵县| 错那县| 宿松县| 沂南县| 拉孜县| 肃南| 彰武县| 南城县| 江津市| 冕宁县| 驻马店市| 交口县| 阜新市| 西昌市| 洛宁县| 麦盖提县| 莱西市| 永春县| 济源市| 上思县|