Spring Cloud云服务架构 - commonservice-config配置服务搭建
1. 介绍
Spring Cloud Config为分布式系统中的外部配置提供服务器和客户端支持。使用Config Server,您可以在所有环境中管理应用程序的外部属性。客户端和服务器上的概念映射与Spring Environment和PropertySource抽象相同,因此它们与Spring应用程序非常契合,但可以与任何以任何语言运行的应用程序一起使用。随着应用程序通过从开发人员到测试和生产的部署流程,您可以管理这些环境之间的配置,并确定应用程序具有迁移时需要运行的一切。服务器存储后端的默认实现使用git,因此它轻松支持标签版本的配置环境,以及可以访问用于管理内容的各种工具。很容易添加替代实现,并使用Spring配置将其插入。
2. 引入pom相关jar包,其中pom.xml配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="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> <parent>
<groupId>com.ml.honghu</groupId>
<artifactId>commonservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent> <artifactId>commonservice-config</artifactId>
<packaging>jar</packaging> <name>commonservice-config</name>
<description>Config Server</description> <dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>1</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
<execution>
<id>2</id>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
3. 在src/main/java进行ConfigApplication.java启动文件配置:
package com.ml.honghu; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @EnableConfigServer
@EnableEurekaClient
@SpringBootApplication
public class ConfigApplication { public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
4. 在src/main/resource下进行bootstrap.yml配置
server:
port: 8888
spring:
application:
name: commonservice-config-server
profiles:
active: discovery,native
cloud:
config:
server:
git:
uri: http://192.168.0.254/honghu.../honghu-config.git
username: honghu
password: 123456
searchPaths: config-dev
security:
basic:
enabled: true
user:
name: honghu
password: 123456
eureka:
client:
serviceUrl:
defaultZone: http://honghu:123456@localhost:8761/eureka/
honghuZone: http://honghu:123456@localhost:8761/eureka/
registry-fetch-interval-seconds: 300
availability-zones:
honghu: honghuZone
instance:
prefer-ip-address: true
metadataMap:
version: 1.0
variant: A
user: ${security.user.name}
password: ${security.user.password}
management:
security:
enabled: false
注意: 如果不从远程git或者svn库加载配置文件信息,可以配置加载本地地址,比如window下配置使用:
server:
port: 8888
spring:
application:
name: commonservice-config-server
profiles:
active: discovery,native
cloud:
config:
server:
<span style="color: #ff0000;">native.searchLocations: d:/honghu-config</span>
security:
basic:
enabled: true
user:
name: honghu
password: 123456
eureka:
client:
serviceUrl:
defaultZone: http://honghu:123456@localhost:8761/eureka/
honghuZone: http://honghu:123456@localhost:8761/eureka/
registry-fetch-interval-seconds: 300
availability-zones:
honghu: honghuZone
instance:
prefer-ip-address: true
metadataMap:
version: 1.0
variant: A
user: ${security.user.name}
password: ${security.user.password}
management:
security:
enabled: false
到此,整个config服务项目配置完毕!!
从现在开始,我这边会将近期研发的spring cloud微服务云架构的搭建过程和精髓记录下来,帮助更多有兴趣研发spring cloud框架的朋友,大家来一起探讨spring cloud架构的搭建过程及如何运用于企业项目。
Spring Cloud云服务架构 - commonservice-config配置服务搭建的更多相关文章
- Spring Cloud(十四)Config 配置中心与客户端的使用与详细
前言 在上一篇 文章 中我们直接用了本应在本文中配置的Config Server,对Config也有了一个基本的认识,即 Spring Cloud Config 是一种用来动态获取Git.SVN.本地 ...
- Spring Cloud(9):Config配置中心
Config配置中心作用简单来讲:统一配置,方便管理 开源配置中心: 1.百度Disconf 2.阿里Diamand 3.Spring Cloud Config 搭建Config-Server 快速上 ...
- 整合SPRING CLOUD云服务架构 - 企业分布式微服务云架构构建
整合SPRING CLOUD云服务架构 - 企业分布式微服务云架构构建 1. 介绍 Commonservice-system是一个大型分布式.微服务.面向企业的JavaEE体系快速研发平台,基于模 ...
- 第1章 Spring Cloud 构建微服务架构(一)服务注册与发现
一.Spring Cloud 简介 Spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中的配置管理.服务发现.断路器.智能路由.微代理.控制总 ...
- Spring Cloud构建微服务架构(二)服务消费者
Netflix Ribbon is an Inter Process Communication (IPC) cloud library. Ribbon primarily provides clie ...
- Spring Cloud构建微服务架构(五)服务网关
通过之前几篇Spring Cloud中几个核心组件的介绍,我们已经可以构建一个简略的(不够完善)微服务架构了.比如下图所示: 我们使用Spring Cloud Netflix中的Eureka实现了服务 ...
- Spring Cloud系列(一):微服务架构简介
一.微服务概述 1.微服务是什么 微服务架构的核心就是服务的拆分,把传统的单体式应用,根据一定的维度(比如业务)拆分为一个一个的服务,每一个服务都有自身特定的功能,又都能够独立的部署,甚至可以拥有自己 ...
- spring cloud深入学习(一)-----什么是微服务?什么是rpc?spring cloud简介
近年来,微服务非常的流行,那么为什么是它?简单介绍一下. 为什么是微服务? 微服务架构是一种将单应用程序作为一套小型服务开发的方法,每种应用程序都在其自己的进程中运行,并与轻量级机制(通常是HTTP资 ...
- Spring Cloud Alibaba基础教程:Nacos配置的多环境管理
前情回顾: <Spring Cloud Alibaba基础教程:使用Nacos实现服务注册与发现> <Spring Cloud Alibaba基础教程:支持的几种服务消费方式> ...
- Spring Cloud学习笔记【一】Eureka服务注册与发现
Spring Cloud Eureka 是 Spring Cloud Netflix 微服务套件的一部分,基于 Netflix Eureka 做了二次封装,主要负责完成微服务架构中的服务治理功能,服务 ...
随机推荐
- spring boot-7.日志系统
日志系统分为两部分,一部分是日志抽象层,一部分是日志实现层.常见的日志抽象层JCL,SLF4J,JBoss-Logging,日志实现层有logback,log4j,log4j2,JUL.日志抽象层的功 ...
- Objective-C中的自动释放池
自动释放池块@autoreleasepool 自动释放池块在MRC和ARC下都可以使用.在MARC下,为了将自动释放池块内部的变量放入自动释放池,需要手动调用autorelease方法:在ARC下,只 ...
- linux 终端的用户与主机名
首先这个属于Linux中的$PS1的变量,你可以通过 echo $PS1查看你当前的变量值. 默认的PS1变量值是 [\u@\h \W]\$,每个参数的含义 "root":表示当前 ...
- iOS和Android图标大小
iOS版 有关要求和指导原则适用于iOS的应用程序图标的更多详细信息,请参阅的iOS人机界面指南:图标和图像尺寸和技术Q&A QA1686:iPad和iPhone上的应用程序图标. 所有图标都 ...
- Redis5以上版本伪集群搭建(高可用集群模式)
redis集群需要至少要三个master节点,我们这里搭建三个master节点,并且给每个master再搭建一个slave节点,总共6个redis节点,这里用一台机器(可以多台机器部署,修改一下ip地 ...
- Java 从后向前依次比较两个数组
这是华为往年的一道上机题 题目: 给定两个数组,以及两个数组的长度,要求从最后一个元素开始,依次比较两个数组对应的元素.如果有一个数组较短,则以短数组为准.返回不同元素的个数. 解答: int fun ...
- initlocation - 创建一个从属的 PostgreSQL数据库存储区
SYNOPSIS initlocation directory DESCRIPTION 描述 initlocation 创建一个新的PostgreSQL从属数据库存储区.参阅 CREATE DATAB ...
- mariadb读写分离
mycat maraidb主从架构,是主负责写,从负责读,但前端如果没有调度器的话,是无法实现读写分离的.这就涉及到了中间站,它就是mycat.一定要在主从架构的基础之上实现读写分离. 配置三台的主从 ...
- zabbix利用percona-toolkit工具监控Mysql主从同步状态
一.下载percona-toolkit工具包 percona-toolkit是一组高级命令行工具的集合,可以查看当前服务的摘要信息,磁盘检测,分析慢查询日志,查找重复索引,实现表同步等等. [root ...
- php字符串大小写转换
strtoupper().strtolower().ucfirst().ucfirst().ucwords().mb_strtoupper().mb_strtolower()和mb_convert_c ...
