版权声明:本文为博主原创文章,遵循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如下:


  1. <dependencies>
  2.          <dependency>
  3.               <groupId>org.springframework.cloud</groupId>
  4.               <artifactId>spring-cloud-starter-zipkin</artifactId>
  5.               <version>1.2.1.RELEASE</version>
  6.          </dependency>
  7.          <dependency>
  8.              <groupId>org.springframework.cloud</groupId>
  9.              <artifactId>spring-cloud-starter-zuul</artifactId>
  10.              <version>1.4.4.RELEASE</version>
  11.          </dependency>
  12.          <dependency>
  13.               <groupId>org.springframework.boot</groupId>
  14.               <artifactId>spring-boot-starter-web</artifactId>
  15.          </dependency>
  16.          <dependency>
  17.               <groupId>org.springframework.cloud</groupId>
  18.               <artifactId>spring-cloud-starter-eureka</artifactId>
  19.          </dependency>
  20.          <dependency>
  21.               <groupId>org.springframework.boot</groupId>
  22.               <artifactId>spring-boot-starter-test</artifactId>
  23.               <scope>test</scope>
  24.          </dependency>
  25.      </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如下:


  1. <dependencies>
  2.          <dependency>
  3.               <groupId>org.springframework.cloud</groupId>
  4.               <artifactId>spring-cloud-starter-zipkin</artifactId>
  5.               <version>1.2.1.RELEASE</version>
  6.          </dependency>
  7.          <dependency>
  8.               <groupId>org.springframework.boot</groupId>
  9.               <artifactId>spring-boot-starter-web</artifactId>
  10.          </dependency>
  11.          <dependency>
  12.               <groupId>org.springframework.cloud</groupId>
  13.               <artifactId>spring-cloud-starter-eureka</artifactId>
  14.          </dependency>
  15.          <dependency>
  16.               <groupId>org.springframework.boot</groupId>
  17.               <artifactId>spring-boot-starter-test</artifactId>
  18.               <scope>test</scope>
  19.          </dependency>
  20.      </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.完整的项目搭建完毕,依次启动 eurekaserverzipkinserverzipkinzuulclient zipkinclient 在浏览器上访问http://localhost:8768/sayhi/GetTest/getTest 浏览器显示:I  am from :1000    再访问 http://localhost:9411 ,即访问 Zipkin 的展示界面,点击find traces可以看到对应的链路数据,例如请求的调用时间、消耗时间,以及请求调用的链路情况。(注意:需要先访问服务产生链路记录,才能在zipkin界面查到相应的servicenamespanname

4.可以在链路中添加自定义数据,本案例在 zipkinzuulclient服务中新建一个过滤器,它的类型为 post 类型, order0,开启拦截。在过滤器的拦截逻辑方法里, 通过 Tracer addTag 方法在本案例中加上了链路的操作人,过滤器中部分代码如下:


  1. @Autowired
  2. Tracer tracer;//首先注入Tracer对象
  3.     @Override
  4.     public Object run() {
  5. //在链路中添加链路操作人员记录
  6.        tracer.addTag("user", "lucus");    
  7. return null;
  8.     }

补充:在低版本中也可以自行创建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依赖如下:


  1. <dependencies>
  2.         <dependency>
  3.             <groupId>io.zipkin.java</groupId>
  4.             <artifactId>zipkin-server</artifactId>
  5.             <version>1.27.0</version>
  6.         </dependency>
  7.         <dependency>
  8.             <groupId>io.zipkin.java</groupId>
  9.             <artifactId>zipkin-autoconfigure-ui</artifactId>
  10.             <version>1.27.0</version>
  11.         </dependency>
  12.         <dependency>
  13.             <groupId>org.springframework.boot</groupId>
  14.             <artifactId>spring-boot-starter</artifactId>
  15.         </dependency>
  16.         <dependency>
  17.             <groupId>org.springframework.boot</groupId>
  18.             <artifactId>spring-boot-starter-web</artifactId>
  19.         </dependency>
  20.         <dependency>
  21.             <groupId>org.springframework.cloud</groupId>
  22.             <artifactId>spring-cloud-starter-eureka</artifactId>
  23.             <version>1.4.6.RELEASE</version>
  24.         </dependency>
  25.         <dependency>
  26.             <groupId>org.springframework.boot</groupId>
  27.             <artifactId>spring-boot-starter-test</artifactId>
  28.             <scope>test</scope>
  29.         </dependency>
  30.     </dependencies>

b.低版本中的zipkinserver的配置文件配置内容如下:

====================

#自定义端口号

server.port=9000

#设置服务注册中心的URL,本服务要向该服务注册中心注册自己

eureka.client.serviceUrl.defaultZone=http://ipa:8761/eureka

spring.application.name=zipkinserver

====================

c.启动类添加注释如下:


  1. import org.springframework.boot.SpringApplication;
  2. import org.springframework.boot.autoconfigure.SpringBootApplication;
  3. import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
  4. import zipkin.server.EnableZipkinServer;
  5. @EnableEurekaClient
  6. @EnableZipkinServer
  7. @SpringBootApplication
  8. public class ZipkinServerApplication {
  9.     public static void main(String[] args) {
  10.         SpringApplication.run(ZipkinServerApplication.class, args);
  11.     }
  12. }

原文地址:https://blog.csdn.net/fsy9595887/article/details/84936214

初学zipkin搭建链路追踪服务注意事项的更多相关文章

  1. spring cloud 2.x版本 Sleuth+Zipkin分布式链路追踪

    前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前两篇文章eureka-server.eureka-client.eureka ...

  2. zipkin分布式链路追踪系统

    基于zipkin分布式链路追踪系统预研第一篇   分布式服务追踪系统起源于Google的论文“Dapper, a Large-Scale Distributed Systems Tracing Inf ...

  3. SpringCloud Sleuth + Zipkin 实现链路追踪

    一.Sleuth介绍   为什么要使用微服务跟踪? 它解决了什么问题? 1.微服务的现状?   随着业务的发展,单体架构变为微服务架构,并且系统规模也变得越来越大,各微服务间的调用关系也变得越来越复杂 ...

  4. 原理分析dubbo分布式应用中使用zipkin做链路追踪

    zipkin是什么 Zipkin是一款开源的分布式实时数据追踪系统(Distributed Tracking System),基于 Google Dapper的论文设计而来,由 Twitter 公司开 ...

  5. 原理分析dubbo分布式应用中使用zipkin做链路追踪(转)

    作者:@nele本文为作者原创,转载请注明出处:https://www.cnblogs.com/nele/p/10171794.html 目录 zipkin是什么为什么使用Zipkinzipkin架构 ...

  6. 基于zipkin分布式链路追踪系统预研第一篇

    本文为博主原创文章,未经博主允许不得转载. 分布式服务追踪系统起源于Google的论文“Dapper, a Large-Scale Distributed Systems Tracing Infras ...

  7. Zipkin客户端链路追踪源码解析

    我们知道,Zipkin这个工具可以帮助我们收集分布式系统中各个系统之间的调用连关系,而且除了Servlet之外还能收集:MQ.线程池.WebSocket.Feign.Hystrix.RxJava.We ...

  8. Zipkin+Sleuth 链路追踪整合

    1.Zipkin 是一个开放源代码分布式的跟踪系统 它可以帮助收集服务的时间数据,以解决微服务架构中的延迟问题,包括数据的收集.存储.查找和展现 每个服务向zipkin报告计时数据,zipkin会根据 ...

  9. 【zipkin】链路追踪

    1,安装zipkin:https://zipkin.io/pages/quickstart.html 推荐使用docker去安装zipkin服务,下载安装执行都有了.缺点是下载要等待一段时间 2,使用 ...

随机推荐

  1. GoCN每日新闻(2019-11-09)

    GoCN每日新闻(2019-11-09) 1. Go语言发行10周年庆祝 https://blog.golang.org/10years2. 容器中某Go服务GC停顿经常超过100ms排查 https ...

  2. Flutter之网络请求

    Flutter之网络请求 一,介绍与需求 1.1,介绍 1,http一个可组合的,基于Future的库,用于发出HTTP请求.包含一组高级功能和类,可轻松使用HTTP资源.它与平台无关,可以在命令行和 ...

  3. navicat提示无法连接解决办法

    1.错误如下图: 2.这个是由于mysql中user表中未设置允许该ip访问导致,解决办法: 1)查下user表:select user,host from user; 这张表就是mysql.user ...

  4. 东芝300D粉盒清零

    东芝300D粉盒清零 1:打开前盖 2:按"OK"键3秒,等 显示 "更换硒鼓"(注:不用选 是/否,直接进入第3步) 3:按"启用"键 4 ...

  5. 如何查看电脑的GPU信息

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/qq_33690342/article/ ...

  6. 命令行利用ffmpeg实现rtmp推流《转》

    ffmpeg在以前介绍过,是一个相当强大的工具,我们这次利用它实现rtmp推流(最终推流地址统一为rtmp://127.0.0.1:1935/live/123). 1.首先下载ffmpeg和ffpla ...

  7. js 计算总页数的最高效方式

    js 计算总页数的最高效方式 /** * [getTotalPageNum 获取页码总数] * @param {[type]} totalRecord [总记录] * @param {[type]} ...

  8. 解决pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path问题

    解决方案: 找到python的安装路径下的pytesseract:   例如我的是  C:\develop\Python\Lib\site-packages\pytesseract .用文本编辑器打开 ...

  9. 【452】pandas筛选出表中满足另一个表所有条件的数据

    参考:pandas筛选出表中满足另一个表所有条件的数据 参考:pandas:匹配两个dataframe 使用 pd.merge 来实现 on 表示查询的 columns,如果都有 id,那么这是很好的 ...

  10. OpenShift 4.2 etcd operatorhub离线环境部署

    本文记录在OperatorHub中存在界面但缺少镜像的环境下如何安装部署.感谢王征提供的大力支持和指导. 现在一个在线环境找到etcd所需要的镜像 quay.io/coreos/etcd-operat ...