初学zipkin搭建链路追踪服务注意事项
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。
</div>
<!--一个博主专栏付费入口-->
<!--一个博主专栏付费入口结束-->
<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-833878f763.css">
<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-833878f763.css">
<div class="htmledit_views" id="content_views">
<p><strong>1.zipkinserver的搭建</strong></p>
注意:因为关于 Zipkin 的服务端,在Spring Boot 2.x 版本后,官方就不推荐自行定制编译了(自行搭建方式在本文末补充),反而是直接提供了编译好的 jar 包来给我们使用(下载zipkin-server-xxx.jar ,使用JAVA命令启动该JAR,zipkin-server.jar是一个打包好的springBoot应用,springBoot自带tomcat因此只要启动JAR包就可以访问了。 java -jar zipkin-server-xxx.jar 启动完后访问localhost:9411可以查看统计界面)。还有其他两种方式搭建zipkinserver方式,详细情况参看
2.构件网关工程以及服务提供工程,这两个工程作为Zipkin 客户端, 需要将链路数据上传给Zipkin Server,同时它也作为 EurekaClient。
a.网关pom如下:
-
<dependencies>
-
-
<dependency>
-
-
<groupId>org.springframework.cloud</groupId>
-
-
<artifactId>spring-cloud-starter-zipkin</artifactId>
-
-
<version>1.2.1.RELEASE</version>
-
-
</dependency>
-
-
<dependency>
-
-
<groupId>org.springframework.cloud</groupId>
-
-
<artifactId>spring-cloud-starter-zuul</artifactId>
-
-
<version>1.4.4.RELEASE</version>
-
-
</dependency>
-
-
<dependency>
-
-
<groupId>org.springframework.boot</groupId>
-
-
<artifactId>spring-boot-starter-web</artifactId>
-
-
</dependency>
-
-
<dependency>
-
-
<groupId>org.springframework.cloud</groupId>
-
-
<artifactId>spring-cloud-starter-eureka</artifactId>
-
-
</dependency>
-
-
<dependency>
-
-
<groupId>org.springframework.boot</groupId>
-
-
<artifactId>spring-boot-starter-test</artifactId>
-
-
<scope>test</scope>
-
-
</dependency>
-
-
</dependencies>
b.网关的配置文件如下:
====================================
server.port=8768
spring.application.name=zipkinzuulclient
#指定 Zipkin Server 地址
spring.zipkin.base-url=http://localhost:9411
#通过配置这个参数来决定了日志记录发送给采集器的概率,0-1交给使用者自己配置。开发阶段和运行初期,
#一般配置成1全量收集日志,在默认情况下,该值为 0.1
spring.sleuth.sampler.percentage=1.0
#以下两个配置就可以将以"/sayhi/**"开头的 Url路由指定的url
zuul.routes.sayhi.path=/sayhi/**
zuul.routes.sayhi.url=http://localhost:1000
===================================
c.服务提供工程的pom如下:
-
<dependencies>
-
-
<dependency>
-
-
<groupId>org.springframework.cloud</groupId>
-
-
<artifactId>spring-cloud-starter-zipkin</artifactId>
-
-
<version>1.2.1.RELEASE</version>
-
-
</dependency>
-
-
<dependency>
-
-
<groupId>org.springframework.boot</groupId>
-
-
<artifactId>spring-boot-starter-web</artifactId>
-
-
</dependency>
-
-
<dependency>
-
-
<groupId>org.springframework.cloud</groupId>
-
-
<artifactId>spring-cloud-starter-eureka</artifactId>
-
-
</dependency>
-
-
<dependency>
-
-
<groupId>org.springframework.boot</groupId>
-
-
<artifactId>spring-boot-starter-test</artifactId>
-
-
<scope>test</scope>
-
-
</dependency>
-
-
</dependencies>
d.服务提供工程的配置
=====================================
spring.application.name=zipkinclient
server.port=1000
#设置服务注册中心的URL,本服务要向该服务注册中心注册自己
eureka.client.serviceUrl.defaultZone=http://ipa:8761/eureka
#指定 Zipkin Server 地址
spring.zipkin.base-url=http://localhost:9411
#通过配置这个参数来决定了日志记录发送给采集器的概率,0-1交给使用者自己配置。开发阶段和运行初期,
#一般配置成1全量收集日志,在默认情况下,该值 为 0.1
spring.sleuth.sampler.percentage=1.0
============================================
3.完整的项目搭建完毕,依次启动 eurekaserver、zipkinserver、zipkinzuulclient 和 zipkinclient。 在浏览器上访问http://localhost:8768/sayhi/GetTest/getTest, 浏览器显示:I am from :1000 再访问 http://localhost:9411 ,即访问 Zipkin 的展示界面,点击find traces可以看到对应的链路数据,例如请求的调用时间、消耗时间,以及请求调用的链路情况。(注意:需要先访问服务产生链路记录,才能在zipkin界面查到相应的servicename和spanname)
4.可以在链路中添加自定义数据,本案例在 zipkinzuulclient服务中新建一个过滤器,它的类型为 post 类型, order为0,开启拦截。在过滤器的拦截逻辑方法里, 通过 Tracer 的 addTag 方法在本案例中加上了链路的操作人,过滤器中部分代码如下:
-
@Autowired
-
-
Tracer tracer;//首先注入Tracer对象
-
-
@Override
-
-
public Object run() {
-
-
//在链路中添加链路操作人员记录
-
-
tracer.addTag("user", "lucus");
-
-
return null;
-
-
}
补充:在低版本中也可以自行创建zipkinserver工程,搭建zipkinserver服务,但是官方在2017年6月已经停止使用这种方式,并且要求链路追踪案例中所有案例工程(网关工程、服务提供工程)的搭建都是在低版本中进行,不能使用springboot 2.x,如:
springboot 1.5.9、
spring-cloud.version Dalston.SR1、
spring-cloud-starter-zipkin 1.2.1.RELEASE、
zipkin-server 1.27.0、
zipkin-autoconfigure-ui 1.27.0 等。
a.zipkinserver中引入pom依赖如下:
-
<dependencies>
-
<dependency>
-
<groupId>io.zipkin.java</groupId>
-
<artifactId>zipkin-server</artifactId>
-
<version>1.27.0</version>
-
</dependency>
-
<dependency>
-
<groupId>io.zipkin.java</groupId>
-
<artifactId>zipkin-autoconfigure-ui</artifactId>
-
<version>1.27.0</version>
-
</dependency>
-
-
<dependency>
-
<groupId>org.springframework.boot</groupId>
-
<artifactId>spring-boot-starter</artifactId>
-
</dependency>
-
<dependency>
-
<groupId>org.springframework.boot</groupId>
-
<artifactId>spring-boot-starter-web</artifactId>
-
</dependency>
-
<dependency>
-
<groupId>org.springframework.cloud</groupId>
-
<artifactId>spring-cloud-starter-eureka</artifactId>
-
<version>1.4.6.RELEASE</version>
-
</dependency>
-
-
<dependency>
-
<groupId>org.springframework.boot</groupId>
-
<artifactId>spring-boot-starter-test</artifactId>
-
<scope>test</scope>
-
</dependency>
-
</dependencies>
b.低版本中的zipkinserver的配置文件配置内容如下:
====================
#自定义端口号
server.port=9000
#设置服务注册中心的URL,本服务要向该服务注册中心注册自己
eureka.client.serviceUrl.defaultZone=http://ipa:8761/eureka
spring.application.name=zipkinserver
====================
c.启动类添加注释如下:
-
import org.springframework.boot.SpringApplication;
-
import org.springframework.boot.autoconfigure.SpringBootApplication;
-
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
-
-
import zipkin.server.EnableZipkinServer;
-
@EnableEurekaClient
-
@EnableZipkinServer
-
@SpringBootApplication
-
public class ZipkinServerApplication {
-
-
public static void main(String[] args) {
-
SpringApplication.run(ZipkinServerApplication.class, args);
-
}
-
}
原文地址:https://blog.csdn.net/fsy9595887/article/details/84936214
初学zipkin搭建链路追踪服务注意事项的更多相关文章
- spring cloud 2.x版本 Sleuth+Zipkin分布式链路追踪
前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前两篇文章eureka-server.eureka-client.eureka ...
- zipkin分布式链路追踪系统
基于zipkin分布式链路追踪系统预研第一篇 分布式服务追踪系统起源于Google的论文“Dapper, a Large-Scale Distributed Systems Tracing Inf ...
- SpringCloud Sleuth + Zipkin 实现链路追踪
一.Sleuth介绍 为什么要使用微服务跟踪? 它解决了什么问题? 1.微服务的现状? 随着业务的发展,单体架构变为微服务架构,并且系统规模也变得越来越大,各微服务间的调用关系也变得越来越复杂 ...
- 原理分析dubbo分布式应用中使用zipkin做链路追踪
zipkin是什么 Zipkin是一款开源的分布式实时数据追踪系统(Distributed Tracking System),基于 Google Dapper的论文设计而来,由 Twitter 公司开 ...
- 原理分析dubbo分布式应用中使用zipkin做链路追踪(转)
作者:@nele本文为作者原创,转载请注明出处:https://www.cnblogs.com/nele/p/10171794.html 目录 zipkin是什么为什么使用Zipkinzipkin架构 ...
- 基于zipkin分布式链路追踪系统预研第一篇
本文为博主原创文章,未经博主允许不得转载. 分布式服务追踪系统起源于Google的论文“Dapper, a Large-Scale Distributed Systems Tracing Infras ...
- Zipkin客户端链路追踪源码解析
我们知道,Zipkin这个工具可以帮助我们收集分布式系统中各个系统之间的调用连关系,而且除了Servlet之外还能收集:MQ.线程池.WebSocket.Feign.Hystrix.RxJava.We ...
- Zipkin+Sleuth 链路追踪整合
1.Zipkin 是一个开放源代码分布式的跟踪系统 它可以帮助收集服务的时间数据,以解决微服务架构中的延迟问题,包括数据的收集.存储.查找和展现 每个服务向zipkin报告计时数据,zipkin会根据 ...
- 【zipkin】链路追踪
1,安装zipkin:https://zipkin.io/pages/quickstart.html 推荐使用docker去安装zipkin服务,下载安装执行都有了.缺点是下载要等待一段时间 2,使用 ...
随机推荐
- mark一下咕掉的题目
蒟蒻才普及组呀~ 大佬别D我 等集中补一下 CF980F:咋说捏,我觉得要联赛了做这题有点浪费时间,等想颓废了再来写写叭qwq 215E/279D/288E/331C3/431D/433E/750G/ ...
- [技术博客] Android 自动化测试
[技术博客] Android 自动化测试 安卓自动化测试工具与平台的搭建 类似于网页端自动化,安卓测试的自动化也主要是针对控件的自动化.其原理就是通过python(其他语言) 的脚本来代替我们手动完成 ...
- Salt States概览
作者言 我也只是SaltStack的初学者,如果文中有错误的地方,请不吝赐教. 在学习的过程,我也做了不少实验,犯了不少错,积累了一些经验,对SaltStack的运行也有一定了解,如果有什么问题,或是 ...
- 一句命令激活windows/office (https://03k.org/kms.html)
https://03k.org/kms.html 本站上线KMS服务~一句命令激活windows/office kissshot2015年11月1日 装机必备, 软件下载 240 条评论 服务器地址: ...
- ssh scp 上传下载文件
scp username@servername:/path/filename 例如scp codinglog@192.168.0.101:/home/kimi/test.txt 把192.168. ...
- Vscode 修改主题颜色
首先向大家演示如何使用VSCode自带的颜色主题:依次点击左上角的文件-首选项-颜色主题,出现如下的主题选取界面.
- Mysql 查询一个月当前时间一个月之前的数据
sql: AND date_format(createDTM, MONTH),'%Y-%m-%d')
- 为什么JDK代码这样写?final ReentrantLock takeLock = this.takeLock
在CopyOnWriteArrayList的源码中有一个细节值得学习,就是在addIfAbsent方法中ReentrantLock的用法,先是将一个这个成员变量this.lock重新赋值给一个局部变量 ...
- PHP Y2K38 (2038年) 问题
PHP 的 strtotime('2100-01-01'); 转换失败:经查询是因为32位系统的 Y2K38问题: Y2K38 问题:当时间大于 2038年01月19日03:14:07 时,strto ...
- ThinkPHP 5.0.x、5.1.x、5.2.x 全版本远程命令执行漏洞
ThinkPHP 5.0.x.5.1.x.5.2.x 全版本远程代码执行漏洞 作者:SoulCat. 来源:CSDN 原文:https://blog.csdn.net/csacs/article/de ...