0
点赞
收藏
分享

微信扫一扫

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分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_分布式_02

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

服务之间互相调用

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_04


出现分布式技术

Webservice

ESB

Hession

Dubbo异步通信 消息队列(秒杀)

敏捷开发思想

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


高内聚低耦合微服务 + 持续集成

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

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


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


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

1 架构结构案例

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

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

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

实现了同样的 接口规范

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

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

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


springcloud 模块

  • 统一配置管理
  • 服务注册发现
  • 请求路由
  • 服务远程调用
  • 负载均衡
  • 断路


    基于 springboot 自动装配

与 springboot 兼容关系

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_13


Hoxton SR10 + boot2.3.x

拆分案例

拆分

功能模块进行拆分

单一职责

即 不同微服务 不重复开发相同业务

数据独立

不要访问其他微服务数据库

业务接口

每个模块将自己的业务暴露为接口,供其他服务调用

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


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


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


且没法关联查询

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


将工程文件夹放到 IDE 的 工作空间

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_18

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


可以看到项目所有的微服务

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>_spring cloud_24


1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_25


返回订单对象

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


1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_27


1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_28


符合 微服务 拆分 的单一职责

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

服务拆分-服务远程调用

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

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


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

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


spring的 HTTP 请求工具

用Bean的方式 把RestTemplate 注册 为spring容器 的 对象

就可以在任何地方 以 注入的方式 来用

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


Bean的注入 只能放在 配置类里面

带有 main的 启动类 本身也是配置类在这创建 RestTemplate对象

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


跟入 orderservice

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


先把 resttemplate注入进spring 容器里来

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_37


http请求 返回 json 但在这里需要一个user对象

resttemplate 会 给让你输入一个 返回对象

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

2 eureka注册中心

Eureka-提供者与消费者

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


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


概念 是 业务中谁对谁而言

既可以是 提供 也可以是 消费者

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

Eureka-eureka原理分析

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


ip 端口 是 硬编码在 代码中的

不方便 环境部署

集群 不好布置

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

注册中心 (记录管理微服务)

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


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


1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_46

Eureka-搭建eureka服务

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_47


1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_48


starter -----spring boot里面的 自动装配

注解是 eureka server 自动装配的 开关创建 maven模块

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


1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_50


父工程pom 已经把 版本依赖做好了

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


所有组件版本信息 点进去看

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


加个 springboot注解

psvm

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_53


加上 eureka 自动装配的 开关注解(启动类 上 做注解)

新建 配置文件

eureka 集群 所以 自己也将自己的 微服务 注册

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


1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_55


1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_56

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_57


注册到eureka 的 实例windows 显示的 是 计算机名 本来是 ip

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_58

Eureka-服务注册

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


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


编辑eureka地址信息

yml文件 不许 出现两个 根名称

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


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


启动两个实例

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

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


-D 参数

yml 文件 内的 server.port

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


实例列表

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


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

Eureka-服务发现

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


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


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


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


查看 order services 是 负载均衡 走的 哪个

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_72


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

3 Ribbon组件 负载均衡

Ribbon-负载均衡原理

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


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


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


LoadBalancer 标记 拦截 实现 http 请求 接口

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


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


接口定义的 方法名字 intercept

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_79


同样实现了intercept 方法

下断点

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


取得主机名

去 做 服务拉取

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_81


Ribbon load balamcer对象

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_82


步入 这个 execute 方法

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

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


把这个 service id 交给 getloadBanlancer处理

得到 loadbalancer 对象动态服务列表 负载均衡器

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


在这个对象里面

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_86


就拉取到了 服务列表整个步骤 根据 服务名称 拉取 服务列表

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_87


getserver 开始负载均衡

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_88


1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_89


进入 getserver 方法

选择 server 步入

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


找一个 super 父亲的 选择

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_91


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


走到了 rule 的 选择要有一个 规则 从 动态 server 里 选

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


这个 IRule 是一个 接口I

规则接口 那就会有实现类IDEA Ctrl H 查看实现类

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


比如

轮询负载均衡

随机默认规则 ZoneAvoidance

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


返回来了 选择的 8081

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

Ribbon-负载均衡策略

IRule 接口 继承关系 图

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


ZoneAvoidance 这个 它爷爷 也是 轮询

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


在 服务 注册 时 可以 设置 zone的 值

(杭州,上海)

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

可以 实现 Irule 各种类型

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_99


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


全局的

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


针对 某个 微服务的 配置

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

Ribbon-饥饿加载

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


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

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_105


创建 load balance Client 还要做 服务拉取

时间较长

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


拉取 时 创建了 动态 serverlist load balancer 等 耗费时间 - 懒加载

第二次 server list 会 缓存到内存中

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


1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_108


与 spring boot 一样

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_109


随着 tomcat 启动 就完成了

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_110

springmvc 容器 的 初始化

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


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

4 nacos 阿里注册中心

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

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


1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_115


服务注册 与发现

分布式 配置

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


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

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


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


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


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

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


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

8848 默认端口

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


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

-m 模式 单启动

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

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

Nacos-快速入门

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


通用 在这里 定义了 接口规范定义了服务发现 与 服务注册

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


Eureka 和 nacos 都要遵循 这些接口

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

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

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_131

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

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

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

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

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

添加yml 地址

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

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

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

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

Nacos-服务多级存储模型

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

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

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


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


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

Nacos-NacosRule负载均衡

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

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


nacos 地区 随机 选择 服务

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


如果 本地 没有 服务 访问 外地 同服务 同时 警告

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

Nacos-服务实例的权重设置

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


1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_150

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


调整成0 时 权重 , 不会被 访问平滑升级业务

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

Nacos-环境隔离

注册中心 - 数据中心 对 服务 进行 隔离

命名空间 - group 属性

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

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

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

命名空间 是 对于 开发生产 测试 环境 的划分

(比如 把 业务相似度 比较高的 服务 放在 一个 分组)

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

订单—支付 放一块

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


默认 public

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


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

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


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


添加 命名 空间的 ID

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


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

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

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_163

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

Nacos和Eureka的对比

会在 动态服务 loadbalancer 里拉取 缓存 server 列表 周期30s

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

区别 在于 提供者的 健康检测

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

划分 提供者 为 临时 实例

和非临时实例

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


临时 实例 会 直接剔除

非临时实例 会 等待 康复

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


如果 提供者 挂掉了 nacos 主动 推送 变更 消息

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

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

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


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

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


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


非临时实例 不会被 剔除掉 等待 复活

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


nacos 强调 AP 数据的 可用性

CP 强调 可靠性 和 一致性

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


Nacos 配置管理 功能

Feign 声明式远程调用 比较 Resttemplate

Nacos实现配置管理

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


配置文件 - 关联服务重启 - (热更新 不用重启 就能 配置 生效)配置管理服务 记录核心配置

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

读取配置 结合 本地配置

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

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


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

模版 类型

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

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

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_183

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

![在这里插入图片描述]()

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


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

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


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


去掉重复配置

用 Value 注解 读取配置

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

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


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


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


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

Nacos配置管理-配置热更新

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


属性刷新

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

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

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

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

配置 自动加载 注解

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_198


定义一个 成员变量

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


添加 data注解 getset 方法用 component 把这个类变成 spring 容器的 一个 bean

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


1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_201


注入进来 用getdateformat 获取

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_202

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

开发生产测试 环境 配置值 一致

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>_spring cloud_208


另起一个 spring 测试 微服务 环境

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


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


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


1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_212


配置文件 的 优先级

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


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

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

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


1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_217

以 userservice 为准

共享 与 有环境的 以 环境为准

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

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

Nacos配置管理-nacos集群搭建

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


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


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

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

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

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


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


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

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

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


1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_229

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_spring cloud_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


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>_spring_241


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


粘贴到 http 的 内部

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

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_244


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

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

1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_247


1分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>_负载均衡_248


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


举报

相关推荐

0 条评论