初学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,使用 ...
随机推荐
- oracle 根据身份证号计算出生日期
1.情景展示 如何根据身份证号推算出出生日期? 2.解决方案 --根据身份证号计算出生日期 SELECT DECODE(LENGTH(ID_CARD), 18, SUBSTR(ID_CARD, 7 ...
- 如何新建WebAPI,生成注释,TestAPI的项目
一.新建WebAPI的项目 1. 在Web下,ASP.NET Web 应用程序,点击确定 2. 点击确定 3. 如图所示, 新建Controller 4 . 运行项目 二.注释 1. 在生成中,勾选x ...
- 设计模式概要 & 六原则一法则
参考文章 http://blog.csdn.net/sinat_26342009/article/details/46419873 继承vs组合:http://www.cnblogs.com/feic ...
- 有关于服务端模板注入(ssti攻击)——BUUCTF - easy_tornado
打开题目出现3个链接 /flag.txt 中提示flag in /fllllllllllllag /welcome.txt 中提示 render /hints.txt 中提示 md5(cookie_s ...
- vector内存释放问题
一般,如果vector中存放是的指针,那么必须先遍历一遍,释放指针所指向的内存.(如果vector的元素是内置类型,那么就没有必要做这一步) 然后在释放vector中各元素所占内存,这时候可以用swa ...
- 【Beta】Scrum meeting 5
目录 写在前面 进度情况 任务进度表 Beta-1阶段燃尽图 遇到的困难 照片 commit记录截图 小程序前端仓库 后端代码仓库 技术博客 写在前面 例会时间:5.9 22:30-23:30 例会地 ...
- C#实现图像拖拽以及锚点缩放功能
本文主要实现C#窗体图像拖拽以及锚点缩放功能 1.新建Windows窗体应用项目,添加一个panel控件,在panel控件上添加picturebox控件 代码如下: using System; usi ...
- quartus仿真提示: Can't launch the ModelSim-Altera software
quartus仿真提示: Can't launch the ModelSim-Altera software 2017年07月13日 17:54:50 小怪_tan 阅读数:3255 路径中的结尾 ...
- IIS连接数、并发连接数、最大并发工作线程数、应用程序池的队列长度、应用程序池的最大工作进程数详解
IIS:连接数.并发连接数.最大并发工作线程数.应用程序池的队列长度.应用程序池的最大工作进程数详解 iis性能指标的各种概念:连接数.并发连接数.最大并发工作线程数.应用程序池的队列长度.应用程序池 ...
- Java13新特性 -- switch表达式
引入了yield语句,用于返回值: 和return的区别在于:return会直接跳出当前循环或者方法,而yield只会跳出当前switch块. @Test public void testSwitch ...