(九)Spring Cloud构建分布式微服务架构 - commonservice-config配置服务搭建
- 介绍
Spring Cloud Config为分布式系统中的外部配置提供服务器和客户端支持。使用Config Server,您可以在所有环境中管理应用程序的外部属性。客户端和服务器上的概念映射与Spring Environment和PropertySource抽象相同,因此它们与Spring应用程序非常契合,但可以与任何以任何语言运行的应用程序一起使用。随着应用程序通过从开发人员到测试和生产的部署流程,您可以管理这些环境之间的配置,并确定应用程序具有迁移时需要运行的一切。服务器存储后端的默认实现使用git,因此它轻松支持标签版本的配置环境,以及可以访问用于管理内容的各种工具。很容易添加替代实现,并使用Spring配置将其插入。
- 引入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>
- 在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); } }
- 在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架构的搭建过程及如何运用于企业项目。
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
规模、性能、弹性全面升级,让天下没有难用的 K8s
作者 | 汤志敏 阿里云容器服务开发负责人 Kubernetes 是云原生时代的基础设施、云上的分布式操作系统。9 月 26 日云栖大会容器专场,在《拐点已至,云原生引领数字化转型升级》的演讲中,容器服务开发负责人汤志敏表示:“阿里云容器服务已经拥有国内最大规模的公共云容器集群,据各大国际评测机构显示,其市场份额和产品综合能力中国内第一。本次容器服务 ACK2.0 在规模、性能和弹性能力上全面升级,支持单集群万节点、90% 原生性能的安全沙箱容器、分钟级千节点弹性。此外,容器服务已经在全球 20 个地域部署,推出云原生混合云 2.0 架构和 ACK@Edge,打造安全智能的无边界云计算。本文根据演讲内容整理,关注阿里巴巴云原生公众号,回复“云原生”获得本文 PPT。 K8s,云原生时代的重要生产力 在早期,K8s 上跑的应用多是
- 下一篇
应用上云新模式,Aliware 全家桶亮相杭州云栖大会
全面上云带来的变化,不仅是上云企业数量上的攀升,也是企业对云的使用方式的转变,越来越多的企业用户不仅将云作为一种弹性资源,更是开始在云上部署架构和应用,借助 Serverless 等技术,开发人员只需聚焦于业务代码,省去了对底层资源的维护,同时底层资源用起来会更节省。 9 月 26 日,在杭州云栖大会 - 企业数字化转型专场的现场,阿里云的架构师、产品经理和客户、合作伙伴全面分享了企业上云的新模式,并发布了简单、丰富、开放和低成本的 PaaS 产品服务集 – Aliware 全家桶。 更高效、更节省的应用托管平台 Web 应用托管上云的利器 阿里云Web应用托管服务(Web+)是一款用来运行并管理 Web 类、移动类和 API 类应用程序的 PaaS 产品。支持 Java、Python、Node.js、PHP、Ruby 和 Go 等多种语
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
-
Docker使用Oracle官方镜像安装(12C,18C,19C)
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- CentOS8编译安装MySQL8.0.19
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
推荐阅读
最新文章
- CentOS7,CentOS8安装Elasticsearch6.8.6
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程
- CentOS6,CentOS7官方镜像安装Oracle11G
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- 设置Eclipse缩进为4个空格,增强代码规范
- Mario游戏-低调大师作品
- MySQL8.0.19开启GTID主从同步CentOS8
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果