门户网站建设如何入账,网站策划的最终体现是什么,中山做网站的大公司,建设信用卡购物网站前些天发现了一个巨牛的人工智能学习网站#xff0c;通俗易懂#xff0c;风趣幽默#xff0c;忍不住分享一下给大家。点击跳转到教程。
当微服务系统中 应用服务有很多时#xff08;serviceA 、serviceB ...#xff09;#xff0c;会都从同一个配置中心读取配置文件。此…前些天发现了一个巨牛的人工智能学习网站通俗易懂风趣幽默忍不住分享一下给大家。点击跳转到教程。
当微服务系统中 应用服务有很多时serviceA 、serviceB ...会都从同一个配置中心读取配置文件。此时可选择集群模式部署配置文件管理中心的 config-server 多个 config-server 也作负载匀衡。以达到配置文件管理中心的高可用。
如下图此图出自https://blog.csdn.net/forezp/article/details/81041045 1. 注册中心依旧使用已有工程eureka该工程不作任何修改。
2. 配置管理中心服务端 config-server 中作 3 点修改pom 、启动类、配置文件。
2.1pom 中加依赖。 完整 pom 如下
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.config/groupIdartifactIdconfig-server/artifactIdversion0.0.1-SNAPSHOT/versionnameconfig-server/namedescription配置文件管理 server/descriptionparentgroupIdcom.base/groupIdartifactIdbase-config/artifactIdversion0.0.1-SNAPSHOT/version/parentdependencies!--注册服务到 注册中心作为 Eureka 服务端--dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-server/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-config-server/artifactId/dependency/dependencies/project2.2启动类加注解EnableEurekaServer
package com.config.configserver;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;SpringBootApplication// 配置文件管理
EnableConfigServer// 标明自已为服务
EnableEurekaServer
public class ConfigServerApplication {public static void main(String[] args) {SpringApplication.run(ConfigServerApplication.class, args);}}2.3配置文件中加上注册到 eureka 的配置 spring.application.nameconfig-server
server.port3333# git仓库地址
spring.cloud.config.server.git.urihttps://gitee.com/FJ_WoMenDeShiJie/springcloud-base# 仓库路径
spring.cloud.config.server.git.searchPathsconfig# 仓库分支
spring.cloud.config.labelmaster# git仓库用户名 ( 公开库-可不填 )
spring.cloud.config.server.git.username# git仓库密码 ( 公开库-可不填 )
spring.cloud.config.server.git.password# 注册中心 - 端口 1234、工程名 eureka 见 eureka 工程中配置。
eureka.client.serviceUrl.defaultZone http://localhost:1234/eureka/
3. 配置管理中心客户端 config-client 中作 2 点修改pom 、配置文件。
3.1pom 中加依赖。 完整 pom 如下
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.config/groupIdartifactIdconfig-client/artifactIdversion0.0.1-SNAPSHOT/versionnameconfig-client/namedescription配置文件管理 client/descriptionparentgroupIdcom.base/groupIdartifactIdbase-config/artifactIdversion0.0.1-SNAPSHOT/version/parentdependencies!--注册服务到 注册中心作为 Eureka 客户端--dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-client/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-config/artifactId/dependency/dependencies/project3.2配置文件中加 3 行配置 完整配置如下注意 此行要注释掉 spring.cloud.config.urihttp://localhost:3333/
# 项目名
spring.application.nameconfig-client# 端口
server.port4444# 指定远程仓库分支
spring.cloud.config.labelmaster# 读取文件dev开发环境、test测试、pro生产
spring.cloud.config.profiledev# 配置文件管理中心 config-server 地址
# 配置中心-集群模式时不使用 ip方式
#spring.cloud.config.urihttp://localhost:3333/# 配置中心-集群模式 start -----------------# 注册中心 - 端口 1234、工程名 eureka 见 eureka 工程中配置。
eureka.client.serviceUrl.defaultZone http://localhost:1234/eureka/# 从配置中心读取文件
spring.cloud.config.discovery.enabledtrue# 配置文件管理中心服务名 config-server
spring.cloud.config.discovery.serviceIdconfig-server# 配置中心-集群模式 end ----------------- 由此时的配置可见配置中心的服务是使用的服务名不再写死 IP 。
可选择集群模式部署配置文件管理中心的 config-server 多个 config-server 作负载匀衡。以达到配置文件管理中心的高可用。
4. 启动 注册中心 eureka、配置文件管理服务端 config-server 、配置文件管理客户端 config-client 。 访问 config-client http://localhost:4444/getVersion 证明成功读取到配置文件中的值 。
-------------------------------------------------------------
下一篇springCloud - 第10篇 - 服务间调用追踪 zipkin 的使用
源码见
https://gitee.com/FJ_WoMenDeShiJie/springcloud-config-server
https://gitee.com/FJ_WoMenDeShiJie/springcloud-config-client
-------------------------------------------------------------
PS这个系列不定时更新只是个人的学习分享
内容全程参考书目
《Spring Cloud 与 Docker 微服务架构空实战 》、
《Spring Cloud 微服务实战》及此书作者博客http://blog.didispace.com/spring-cloud-learning/
《深入理解 Spring Cloud 与微服务构建》及此书作者博客https://blog.csdn.net/forezp/article/details/70148833 --------------------------------------------------------------