zoukankan      html  css  js  c++  java
  • Spring Cloud

    Spring Cloud - Config 配置中心

    Spring Cloud Config为分布式系统中的外部配置提供服务器和客户端支持。方便部署与运维。
    分客户端、服务端。
    服务端也称分布式配置中心,是一个独立的微服务应用,用来连接配置服务器并为客户端提供获取配置信息,加密/解密信息等访问接口。
    客户端则是通过指定配置中心来管理应用资源,以及与业务相关的配置内容,并在启动的时候从配置中心获取和加载配置信息。默认采用 git,并且可以通过 git 客户端工具来方便管理和访问配置内容。

    优点:

    • 集中管理配置文件
    • 不同环境不同配置,动态化的配置更新
    • 运行期间,不需要去服务器修改配置文件,服务会想配置中心拉取自己的信息
    • 配置信息改变时,不需要重启即可更新配置信息到服务
    • 配置信息以 rest 接口暴露

    Config服务器

    springcloud-config-server

    依赖

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
        <version>2.2.2.RELEASE</version>
    </dependency>
    

    配置

    server:
      port: 3344
    spring:
      application:
        name: springcloud-config-server
        #连接远程仓库
      cloud:
        config:
          server:
            git:
              uri: #git的https连接
    

    启动器

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

    可以通过http://localhost:3344/application-dev.yaml访问

    使用GIt上的配置

    springcloud-config-client

    依赖

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
        <version>2.2.2.RELEASE</version>
    </dependency>
    

    配置application.yaml

    spring:
      application:
        name: springcloud-config-client
    

    配置bootstrap.yaml

    spring:
      cloud:
        config:
          uri: http://localhost:3344 #config服务器
          name: config-client #Git中配置文件名
          profile: dev #生产环境
          label: master #分支
    
    • boostrap 由父 ApplicationContext 加载,比 applicaton 优先加载
    • boostrap 里面的属性不能被覆盖
  • 相关阅读:
    (水题)洛谷
    (水题)洛谷
    洛谷
    (水题)洛谷
    POJ
    poj 3061(二分 or 尺取法)
    poj 2456(二分)
    poj 1064(二分答案)
    POJ 2559(单调栈)
    STL
  • 原文地址:https://www.cnblogs.com/pinked/p/12866611.html
Copyright © 2011-2022 走看看