Zipkin集成 #
一、Zipkin概述 #
1.1 什么是Zipkin #
Zipkin是一个分布式链路追踪系统,用于收集和展示服务调用链路数据。
text
┌─────────────────────────────────────────────────────────────┐
│ Zipkin架构 │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ 服务实例A │ │ 服务实例B │ │ 服务实例C │ │
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
│ │ │ │ │
│ └────────────────┼────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────┐ │
│ │ Zipkin │ │
│ │ Server │ │
│ └─────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
二、安装部署 #
2.1 Docker部署 #
bash
docker run -d -p 9411:9411 openzipkin/zipkin
2.2 访问控制台 #
三、集成使用 #
3.1 添加依赖 #
xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
3.2 配置文件 #
yaml
spring:
zipkin:
base-url: http://localhost:9411
sender:
type: web
sleuth:
sampler:
probability: 1.0
四、数据存储 #
4.1 MySQL存储 #
yaml
zipkin:
storage:
type: mysql
mysql:
host: localhost
port: 3306
username: root
password: password
db: zipkin
4.2 Elasticsearch存储 #
yaml
zipkin:
storage:
type: elasticsearch
elasticsearch:
hosts: localhost:9200
五、总结 #
| 要点 | 说明 |
|---|---|
| Zipkin Server | 链路数据收集 |
| 数据存储 | MySQL/ES |
| 可视化 | 链路展示 |
接下来让我们学习 Micrometer Tracing!
最后更新:2026-03-28