1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>

微服务技术栈

  • 一、微服务 介绍了解
    • 1 架构结构案例
      • 与 springboot 兼容关系
      • 拆分案例
        • 拆分
        • 服务拆分-服务远程调用
    • 2 eureka注册中心
      • Eureka-提供者与消费者
      • Eureka-eureka原理分析
      • Eureka-搭建eureka服务
      • Eureka-服务注册
      • Eureka-服务发现
    • 3 Ribbon组件 负载均衡
      • Ribbon-负载均衡原理
      • Ribbon-负载均衡策略
      • Ribbon-饥饿加载
    • 4 nacos 阿里注册中心
      • Nacos-快速入门
      • Nacos-服务多级存储模型
      • Nacos-NacosRule负载均衡
      • Nacos-服务实例的权重设置
      • Nacos-环境隔离
      • Nacos和Eureka的对比
      • Nacos实现配置管理
      • Nacos配置管理-微服务配置拉取
      • Nacos配置管理-配置热更新
      • Nacos配置管理-多环境配置共享
      • Nacos配置管理-nacos集群搭建

一、微服务 介绍了解

分布式架构的一种
把服务进行 拆分
springcloud 解决了 服务拆分过程中的 治理问题
与单体应用 进行区分
(单体架构 把业务所有功能集中开发,打成一个包部署)

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第1张图片

每个模块独立开发和部署(服务集群)

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第2张图片

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第3张图片

服务之间互相调用
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第4张图片
出现分布式技术
Webservice
ESB
Hession
Dubbo

异步通信 消息队列(秒杀)
敏捷开发思想
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第5张图片
高内聚低耦合

微服务 + 持续集成
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第6张图片

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第7张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第8张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第9张图片

1 架构结构案例

微服务方案 技术框架落地
eg springcloud + 阿里dubbo

2012 dubbo 开源 (“半吊子”微服务)

2015-2017 springcloud(整合)
封装了Feign客户端 发http 请求 Restful接口
Spring Cloud Bus 自动通知 热更新

实现了同样的 接口规范
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第10张图片

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第11张图片

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第12张图片
springcloud 模块

  • 统一配置管理
  • 服务注册发现
  • 请求路由
  • 服务远程调用
  • 负载均衡
  • 断路
    1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第13张图片
    1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第14张图片
    基于 springboot 自动装配

与 springboot 兼容关系

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第15张图片
Hoxton SR10 + boot2.3.x

拆分案例

拆分

功能模块进行拆分
单一职责
即 不同微服务 不重复开发相同业务
数据独立
不要访问其他微服务数据库
业务接口
每个模块将自己的业务暴露为接口,供其他服务调用
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第16张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第17张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第18张图片
且没法关联查询
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第19张图片
将工程文件夹放到 IDE 的 工作空间
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第20张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第21张图片
可以看到项目所有的微服务
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第22张图片

项目结构
父工程(主要定义了依赖版本)

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第23张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第24张图片
数据分离
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第25张图片
业务逻辑
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第26张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第27张图片
返回订单对象
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第28张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第29张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第30张图片
符合 微服务 拆分 的单一职责
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第31张图片

服务拆分-服务远程调用

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第32张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第33张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第34张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第35张图片
spring的 HTTP 请求工具
用Bean的方式 把RestTemplate 注册 为spring容器 的 对象
就可以在任何地方 以 注入的方式 来用
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第36张图片
Bean的注入 只能放在 配置类里面
带有 main的 启动类 本身也是配置类

在这创建 RestTemplate对象
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第37张图片
跟入 orderservice 1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第38张图片
先把 resttemplate注入进spring 容器里来
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第39张图片
http请求 返回 json 但在这里需要一个user对象
resttemplate 会 给让你输入一个 返回对象
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第40张图片

2 eureka注册中心

Eureka-提供者与消费者

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第41张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第42张图片
概念 是 业务中谁对谁而言
既可以是 提供 也可以是 消费者
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第43张图片

Eureka-eureka原理分析

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第44张图片
ip 端口 是 硬编码在 代码中的
不方便 环境部署
集群 不好布置
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第45张图片

注册中心 (记录管理微服务)
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第46张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第47张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第48张图片

Eureka-搭建eureka服务

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第49张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第50张图片
starter -----spring boot里面的 自动装配
注解是 eureka server 自动装配的 开关

创建 maven模块
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第51张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第52张图片
父工程pom 已经把 版本依赖做好了
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第53张图片
所有组件版本信息 点进去看
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第54张图片
加个 springboot注解
psvm

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第55张图片
加上 eureka 自动装配的 开关注解(启动类 上 做注解)

新建 配置文件

eureka 集群 所以 自己也将自己的 微服务 注册
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第56张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第57张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第58张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第59张图片
注册到eureka 的 实例

windows 显示的 是 计算机名 本来是 ip
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第60张图片

Eureka-服务注册

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第61张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第62张图片
编辑eureka地址信息
yml文件 不许 出现两个 根名称
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第63张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第64张图片
启动两个实例
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第65张图片

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第66张图片
-D 参数
yml 文件 内的 server.port
在这里插入图片描述
实例列表
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第67张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第68张图片

Eureka-服务发现

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第69张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第70张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第71张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第72张图片
查看 order services 是 负载均衡 走的 哪个
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第73张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第74张图片

3 Ribbon组件 负载均衡

Ribbon-负载均衡原理

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第75张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第76张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第77张图片
LoadBalancer 标记 拦截 实现 http 请求 接口
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第78张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第79张图片
接口定义的 方法名字 intercept
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第80张图片
同样实现了intercept 方法
下断点
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第81张图片
取得主机名
去 做 服务拉取

在这里插入图片描述
Ribbon load balamcer对象
在这里插入图片描述
步入 这个 execute 方法
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第82张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第83张图片
把这个 service id 交给 getloadBanlancer处理
得到 loadbalancer 对象

动态服务列表 负载均衡器
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第84张图片
在这个对象里面
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第85张图片
就拉取到了 服务列表

整个步骤 根据 服务名称 拉取 服务列表
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第86张图片
getserver 开始负载均衡
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第87张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第88张图片
进入 getserver 方法
选择 server 步入
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第89张图片
找一个 super 父亲的 选择

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第90张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第91张图片
走到了 rule 的 选择

要有一个 规则 从 动态 server 里 选
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第92张图片
这个 IRule 是一个 接口I
规则接口 那就会有实现类

IDEA Ctrl H 查看实现类
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第93张图片
比如
轮询负载均衡
随机

默认规则 ZoneAvoidance
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第94张图片
返回来了 选择的 8081
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第95张图片

Ribbon-负载均衡策略

IRule 接口 继承关系 图

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第96张图片
ZoneAvoidance 这个 它爷爷 也是 轮询

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第97张图片
在 服务 注册 时 可以 设置 zone的 值
(杭州,上海)

配置类内 修改 规则 用 Irule 的 bean 作为 一个 对象 注入到 spring 容器

可以 实现 Irule 各种类型
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第98张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第99张图片
全局的

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第100张图片
针对 某个 微服务的 配置
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第101张图片

Ribbon-饥饿加载

在这里插入图片描述
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第102张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第103张图片
创建 load balance Client 还要做 服务拉取
时间较长

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第104张图片
拉取 时 创建了 动态 serverlist load balancer 等 耗费时间 - 懒加载
第二次 server list 会 缓存到内存中
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第105张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第106张图片
与 spring boot 一样

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第107张图片
随着 tomcat 启动 就完成了

在这里插入图片描述

springmvc 容器 的 初始化
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第108张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第109张图片

4 nacos 阿里注册中心

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第110张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第111张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第112张图片
服务注册 与发现
分布式 配置
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第113张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第114张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第115张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第116张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第117张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第118张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第119张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第120张图片

8848 默认端口

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第121张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第122张图片

-m 模式 单启动
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第123张图片

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第124张图片

Nacos-快速入门

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第125张图片
通用 在这里 定义了 接口规范

定义了服务发现 与 服务注册
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第126张图片
Eureka 和 nacos 都要遵循 这些接口

所以 服务者 消费者 代码 不用变
需要 更改 依赖 和 地址

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第127张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第128张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第129张图片

添加 父管理依赖
添加 服务注册 启动器依赖

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第130张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第131张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第132张图片

添加yml 地址
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第133张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第134张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第135张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第136张图片

Nacos-服务多级存储模型

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第137张图片在这里插入图片描述1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第138张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第139张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第140张图片

Nacos-NacosRule负载均衡

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第141张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第142张图片
nacos 地区 随机 选择 服务
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第143张图片
如果 本地 没有 服务 访问 外地 同服务 同时 警告
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第144张图片

Nacos-服务实例的权重设置

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第145张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第146张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第147张图片
调整成0 时 权重 , 不会被 访问

平滑升级业务
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第148张图片

Nacos-环境隔离

注册中心 - 数据中心 对 服务 进行 隔离
命名空间 - group 属性
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第149张图片

服务(集群)–下一级–》 实例

对实例的划分 是 对业务 进行的 划分 (地域)

命名空间 是 对于 开发生产 测试 环境 的划分
(比如 把 业务相似度 比较高的 服务 放在 一个 分组)
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第150张图片

订单—支付 放一块
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第151张图片
默认 public
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第152张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第153张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第154张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第155张图片
添加 命名 空间的 ID
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第156张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第157张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第158张图片

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第159张图片

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第160张图片

Nacos和Eureka的对比

会在 动态服务 loadbalancer 里拉取 缓存 server 列表 周期30s
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第161张图片

区别 在于 提供者的 健康检测
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第162张图片

划分 提供者 为 临时 实例
和非临时实例
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第163张图片
临时 实例 会 直接剔除
非临时实例 会 等待 康复
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第164张图片
如果 提供者 挂掉了 nacos 主动 推送 变更 消息

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第165张图片在这里插入图片描述1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第166张图片
临时实例  关掉服务 直接 剔除

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第167张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第168张图片
非临时实例 不会被 剔除掉 等待 复活

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第169张图片
nacos 强调 AP 数据的 可用性
CP 强调 可靠性 和 一致性
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第170张图片
Nacos 配置管理 功能

Feign 声明式远程调用 比较 Resttemplate

Nacos实现配置管理

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第171张图片
配置文件 - 关联服务重启 - (热更新 不用重启 就能 配置 生效)

配置管理服务 记录核心配置
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第172张图片

读取配置 结合 本地配置

DataID 服务名称+ profile运行环境名 dev/test/prod.yaml

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第173张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第174张图片

模版 类型
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第175张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第176张图片

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第177张图片

Nacos配置管理-微服务配置拉取

 ![在这里插入图片描述](https://img-blog.csdnimg.cn/e2f375f857d245388e8770ec78de4f03.png)

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第178张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第179张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第180张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第181张图片
去掉重复配置

用 Value 注解 读取配置

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第182张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第183张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第184张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第185张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第186张图片

Nacos配置管理-配置热更新

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第187张图片
属性刷新
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第188张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第189张图片

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第190张图片

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第191张图片

配置 自动加载 注解
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第192张图片
定义一个 成员变量
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第193张图片
添加 data注解 getset 方法

用 component 把这个类变成 spring 容器的 一个 bean
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第194张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第195张图片
注入进来 用getdateformat 获取
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第196张图片

Nacos配置管理-多环境配置共享

开发生产测试 环境 配置值 一致
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第197张图片在这里插入图片描述
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第198张图片

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第199张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第200张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第201张图片
另起一个 spring 测试 微服务 环境
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第202张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第203张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第204张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第205张图片
配置文件 的 优先级
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第206张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第207张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第208张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第209张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第210张图片

以 userservice 为准

共享 与 有环境的 以 环境为准
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第211张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第212张图片

Nacos配置管理-nacos集群搭建

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第213张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第214张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第215张图片

nginx 有 反向代理 和 负载均衡 的 功能

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第216张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第217张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第218张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第219张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第220张图片

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第221张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第222张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第223张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第224张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第225张图片

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第226张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第227张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第228张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第229张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第230张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第231张图片

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第232张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第233张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第234张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第235张图片
粘贴到 http 的 内部
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第236张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第237张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第238张图片

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第239张图片1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第240张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第241张图片
1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_第242张图片

你可能感兴趣的:(spring,cloud,分布式,微服务)