Springcloud Learning-Highly Available Distributed Configuration Center (Spring Cloud Config)

Source: Internet
Author: User

1. Introduction

  The highly available distributed configuration Center, which is a microservices-ready configuration Center, is clustered to achieve high availability. Config-server and Config-client register with Eureka-server and Config-server multi-instance clustering deployment

2. Retrofit Config-server

1, we use the previously created Eureka-server project as a registry, port 8761

2, we will Config-server project, as Eureka-client, need to introduce spring-cloud-starter-netflix-eureka-client dependency in Pom.xml, the code is as follows

<?XML version= "1.0" encoding= "UTF-8"?><Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">    <modelversion>4.0.0</modelversion>    <groupId>Com.lishun</groupId>    <Artifactid>Config-server</Artifactid>    <version>0.0.1-snapshot</version>    <Packaging>Jar</Packaging>    <name>Config-server</name>    <Description>Demo Project for Spring Boot</Description>    <Parent>        <groupId>Com.lishun</groupId>        <Artifactid>Cloud</Artifactid>        <version>1.0-snapshot</version>        <RelativePath/> <!--Lookup parent from repository -    </Parent>    <Dependencies>        <Dependency>            <groupId>Org.springframework.cloud</groupId>            <Artifactid>Spring-cloud-starter-netflix-eureka-client</Artifactid>        </Dependency>         <Dependency>        <groupId>Org.springframework.boot</groupId>        <Artifactid>Spring-boot-starter-web</Artifactid>    </Dependency>        <Dependency>            <groupId>Org.springframework.cloud</groupId>            <Artifactid>Spring-cloud-config-server</Artifactid>        </Dependency>    </Dependencies></Project>

3, in the project start class Configserverapplication annotated @enableeurekaclient, open eurekaclient function, the code is as follows

@EnableEurekaClient @enableconfigserver@springbootapplication  Public class configserverapplication {    publicstaticvoid  main (string[] args) {        Springapplication.run (configserverapplication. class , args);}    }

4, in the Application.properties configuration file, specify the service registration address, the code is as follows

spring.application.name=config-serverserver.port=8889#spring.cloud.config.server.native.search-locations= classpath:/shared#spring.profiles.active=nativespring.cloud.config.server.git.uri=https://github.com/lis-ylfy/ Config-test/spring.cloud.config.server.git.searchpaths=lisspring.cloud.config.label= masterspring.cloud.config.server.git.username=spring.cloud.config.server.git.password= eureka.client.serviceurl.defaultzone=http://localhost:8761/eureka/

3. Retrofit Config-client

  1, the config-client also as a eureka-client, in the Pom.xml file to add spring-cloud-starter-netflix-eureka-client dependency, in the project start class add annotations @ Enableeurekaclient, turn on the Eurekaclient function

2, in the project configuration file bootstrap.properties Specify the registered address of the service is Http://localhost:8761/eureka, specify to Serviceid to Config-server Configuration service read the configuration file, The code is as follows

Spring.application.name=config-clientspring.cloud.config.uri= http://localhost:8888/ spring.cloud.config.fail-fast=truespring.profiles.active=devserver.port= 8881eureka.client.serviceurl.defaultzone=http://localhost:8761/eureka/spring.cloud.config.discovery.enabled= Truespring.cloud.config.discovery.serviceid=config-server

3. Start the Eureka-server, Config-server and config-client projects in turn, note that it is necessary to config-server start the successful well and register with the Eureka-server to start the process. Config-client, otherwise config-client can't find Config-server.

4, visit Http://localhost:8881/hi, browser display:

Config-test

5. Achieve high availability of config-server

Using idea to open multiple config-server instances, ports 8888 and 8889, and then open multiple config-client instances, from the control can see it in turn from 8888 and 88,892 Config-server read the configuration file, And the load balance is realized.

Springcloud Learning-Highly Available Distributed Configuration Center (Spring Cloud Config)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.