Config 高可用

Config 高可用

介紹

當使用Spring Cloud進行高可用的時候,可以創建多個應用然後註冊到Eureka中,然後通過Service-id進行訪問,這樣Eureka會進行自動的負載均衡,這樣就能簡單的實現高可用,所以Config Server的高可用就是創建三個Config Server分別註冊到Eureka中,這樣當Config 客戶端進行獲取的時候就會進行負載均衡,如果其中一個掛掉就會自動的訪問其餘的部分,由於模擬簡單的企業級的高可用,所以選擇三個Congfig Server進行測試。(默認的Eureka是上文Eureka創建的高可用服務)

構建

  1. POM文件中的依賴內容:
<dependencies>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>2.0.0.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>2.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
            <version>2.0.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
  1. application.properties文件中的內容:
server.port=8110
spring.application.name=lattice-config
spring.cloud.config.label=master
spring.cloud.config.server.git.uri=https://gitee.com/limitzjh/springcloud.git
spring.cloud.config.server.git.search-paths=/
spring.cloud.config.server.git.username=
spring.cloud.config.server.git.password=
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.instance.lease-renewal-interval-in-seconds=4
eureka.instance.lease-expiration-duration-in-seconds=6
eureka.client.service-url.defaultZone=http://127.0.0.1:8100/eureka/,http://127.0.0.1:8200/eureka/,http://127.0.0.1:8300/eureka/
spring.boot.admin.client.url=http://127.0.0.1:8100/sba,http://127.0.0.1:8200/sba,http://127.0.0.1:8300/sba
management.endpoints.web.exposure.include=*
  1. application.java文件中的內容:
package com.lattice.configone;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@SpringBootApplication
@EnableConfigServer
@RefreshScope
@EnableEurekaClient
public class ConfigOneApplication {
	public static void main(String[] args) {
		SpringApplication.run(ConfigOneApplication.class, args);
	}
}

創建三個Config Server 只需要更改一下application.properties中的server.port就可以了。

啓動畫面

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章