通过上一节《微服务之分布式跟踪系统(springboot+zipkin)》我们简单熟悉了zipkin的使用,但是收集的数据都保存在内存中重启后数据丢失,不过zipkin的Storage除了内存,还有Cassandra、MYSQL、ElasticSearch。

二、zipkin的各种Storage配置简介

zipkin存在一些公用的配置,同时存在一些私有的配置(详细信息地址为:https://github.com/openzipkin/zipkin/tree/master/zipkin-server#configuration-for-the-ui),此处不做配置说明的翻译(因为都比较简单易懂),其公用的配置如下所示:

  1.  
    *`QUERY_PORT`: Listen port for the http api and web ui; Defaults to 9411
  2.  
    *`QUERY_LOG_LEVEL`: Log level written to the console; Defaults to INFO
  3.  
    *`QUERY_LOOKBACK`: How many milliseconds queries can look back from endTs;Defaults to 7 days
  4.  
    *`STORAGE_TYPE`: SpanStore implementation: one of `mem`, `mysql`, `cassandra`,`elasticsearch`
  5.  
    *`COLLECTOR_PORT`: Listen port for the scribe thrift api; Defaults to 9410
  6.  
    *`COLLECTOR_SAMPLE_RATE`: Percentage of traces to retain, defaults to alwayssample (1.0).

(1)Cassandra Storage配置

  1.  
    * `CASSANDRA_KEYSPACE`: The keyspace to use. Defaults to "zipkin".
  2.  
    * `CASSANDRA_CONTACT_POINTS`: Comma separated list of hosts / ip addresses part of Cassandra cluster. Defaults to localhost
  3.  
    * `CASSANDRA_LOCAL_DC`: Name of the datacenter that will be considered "local" for latency load balancing. When unset, load-balancing is round-robin.
  4.  
    * `CASSANDRA_ENSURE_SCHEMA`: Ensuring cassandra has the latest schema. If enabled tries to execute scripts in the classpath prefixed with `cassandra-schema-cql3`. Defaults to true
  5.  
    * `CASSANDRA_USERNAME` and `CASSANDRA_PASSWORD`: Cassandra authentication. Will throw an exception on startup if authentication fails. No default
  6.  
    * `CASSANDRA_USE_SSL`: Requires `javax.net.ssl.trustStore` and `javax.net.ssl.trustStorePassword`, defaults to false.

(2)MySQL Storage配置

  1.  
    * `MYSQL_DB`: The database to use. Defaults to "zipkin".
  2.  
    * `MYSQL_USER` and `MYSQL_PASS`: MySQL authentication, which defaults to empty string.
  3.  
    * `MYSQL_HOST`: Defaults to localhost
  4.  
    * `MYSQL_TCP_PORT`: Defaults to 3306
  5.  
    * `MYSQL_MAX_CONNECTIONS`: Maximum concurrent connections, defaults to 10
  6.  
    * `MYSQL_USE_SSL`: Requires `javax.net.ssl.trustStore` and `javax.net.ssl.trustStorePassword`, defaults to false.

(3)Elasticsearch Storage配置

  1.  
    * `ES_CLUSTER`: The name of the elasticsearch cluster to connect to. Defaults to "elasticsearch".
  2.  
    * `ES_HOSTS`: A comma separated list of elasticsearch hostnodes to connect to. When in host:port
  3.  
    format, they should use the transport port, not the http port. To use http, specify
  4.  
    base urls, ex. http://host:9200. Defaults to "localhost:9300". When not using http,
  5.  
    Only one of the hosts needs to be available to fetch the remaining nodes in the
  6.  
    cluster. It is recommended to set this to all the master nodes of the cluster.
  7.  
     
  8.  
    If the http URL is an AWS-hosted elasticsearch installation (e.g.
  9.  
    https://search-domain-xyzzy.us-west-2.es.amazonaws.com) then Zipkin will attempt to
  10.  
    use the default AWS credential provider (env variables, system properties, config
  11.  
    files, or ec2 profiles) to sign outbound requests to the cluster.
  12.  
    * `ES_PIPELINE`: Only valid when the destination is Elasticsearch 5.x. Indicates the ingest
  13.  
    pipeline used before spans are indexed. No default.
  14.  
    * `ES_MAX_REQUESTS`: Only valid when the transport is http. Sets maximum in-flight requests from
  15.  
    this process to any Elasticsearch host. Defaults to 64.
  16.  
    * `ES_AWS_DOMAIN`: The name of the AWS-hosted elasticsearch domain to use. Supercedes any set
  17.  
    `ES_HOSTS`. Triggers the same request signing behavior as with `ES_HOSTS`, but
  18.  
    requires the additional IAM permission to describe the given domain.
  19.  
    * `ES_AWS_REGION`: An optional override to the default region lookup to search for the domain
  20.  
    given in `ES_AWS_DOMAIN`. Ignored if only `ES_HOSTS` is present.
  21.  
    * `ES_INDEX`: The index prefix to use when generating daily index names. Defaults to zipkin.
  22.  
    * `ES_DATE_SEPARATOR`: The date separator to use when generating daily index names. Defaults to '-'.
  23.  
    * `ES_INDEX_SHARDS`: The number of shards to split the index into. Each shard and its replicas
  24.  
    are assigned to a machine in the cluster. Increasing the number of shards
  25.  
    and machines in the cluster will improve read and write performance. Number
  26.  
    of shards cannot be changed for existing indices, but new daily indices
  27.  
    will pick up changes to the setting. Defaults to 5.

三、zipkin环境准备与启动

在本节中,以MySQL为例进行说明,由于目前只是Mysql5.6和5.7进行测试过,所以本次我选择Mysql5.7版本。

(1)    初始化数据库

安装好Mysql5.7后新建zipkin的数据库,然后执行下面的SQL语句新建表:

  1.  
    CREATETABLE IF NOT EXISTS zipkin_spans (
  2.  
    `trace_id_high` BIGINT NOT NULL DEFAULT 0COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64bit',
  3.  
    `trace_id` BIGINT NOT NULL,
  4.  
    `id` BIGINT NOT NULL,
  5.  
    `name` VARCHAR(255) NOT NULL,
  6.  
    `parent_id` BIGINT,
  7.  
    `debug` BIT(1),
  8.  
    `start_ts` BIGINT COMMENT 'Span.timestamp():epoch micros used for endTs query and to implement TTL',
  9.  
    `duration` BIGINT COMMENT 'Span.duration():micros used for minDuration and maxDuration query'
  10.  
    )ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
  11.  
     
  12.  
    ALTERTABLE zipkin_spans ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `id`) COMMENT'ignore insert on duplicate';
  13.  
    ALTERTABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`, `id`) COMMENT 'forjoining with zipkin_annotations';
  14.  
    ALTERTABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'forgetTracesByIds';
  15.  
    ALTERTABLE zipkin_spans ADD INDEX(`name`) COMMENT 'for getTraces and getSpanNames';
  16.  
    ALTERTABLE zipkin_spans ADD INDEX(`start_ts`) COMMENT 'for getTraces ordering andrange';
  17.  
     
  18.  
    CREATETABLE IF NOT EXISTS zipkin_annotations (
  19.  
    `trace_id_high` BIGINT NOT NULL DEFAULT 0COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64bit',
  20.  
    `trace_id` BIGINT NOT NULL COMMENT 'coincideswith zipkin_spans.trace_id',
  21.  
    `span_id` BIGINT NOT NULL COMMENT 'coincideswith zipkin_spans.id',
  22.  
    `a_key` VARCHAR(255) NOT NULL COMMENT'BinaryAnnotation.key or Annotation.value if type == -1',
  23.  
    `a_value` BLOB COMMENT'BinaryAnnotation.value(), which must be smaller than 64KB',
  24.  
    `a_type` INT NOT NULL COMMENT'BinaryAnnotation.type() or -1 if Annotation',
  25.  
    `a_timestamp` BIGINT COMMENT 'Used toimplement TTL; Annotation.timestamp or zipkin_spans.timestamp',
  26.  
    `endpoint_ipv4` INT COMMENT 'Null whenBinary/Annotation.endpoint is null',
  27.  
    `endpoint_ipv6` BINARY(16) COMMENT 'Null whenBinary/Annotation.endpoint is null, or no IPv6 address',
  28.  
    `endpoint_port` SMALLINT COMMENT 'Null whenBinary/Annotation.endpoint is null',
  29.  
    `endpoint_service_name` VARCHAR(255) COMMENT'Null when Binary/Annotation.endpoint is null'
  30.  
    )ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
  31.  
     
  32.  
    ALTERTABLE zipkin_annotations ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `span_id`,`a_key`, `a_timestamp`) COMMENT 'Ignore insert on duplicate';
  33.  
    ALTERTABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`, `span_id`)COMMENT 'for joining with zipkin_spans';
  34.  
    ALTERTABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'forgetTraces/ByIds';
  35.  
    ALTERTABLE zipkin_annotations ADD INDEX(`endpoint_service_name`) COMMENT 'forgetTraces and getServiceNames';
  36.  
    ALTERTABLE zipkin_annotations ADD INDEX(`a_type`) COMMENT 'for getTraces';
  37.  
    ALTERTABLE zipkin_annotations ADD INDEX(`a_key`) COMMENT 'for getTraces';
  38.  
    ALTERTABLE zipkin_annotations ADD INDEX(`trace_id`, `span_id`, `a_key`) COMMENT 'fordependencies job';
  39.  
     
  40.  
    CREATETABLE IF NOT EXISTS zipkin_dependencies (
  41.  
    `day` DATE NOT NULL,
  42.  
    `parent` VARCHAR(255) NOT NULL,
  43.  
    `child` VARCHAR(255) NOT NULL,
  44.  
    `call_count` BIGINT
  45.  
    )ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
  46.  
     
  47.  
    ALTERTABLE zipkin_dependencies ADD UNIQUE KEY(`day`, `parent`, `child`);

(2)    启动实例

执行命令:java -jar zipkin-server-1.17.1-exec.jar --STORAGE_TYPE=mysql--MYSQL_DB=zipkin --MYSQL_USER=root --MYSQL_PASS=root --MYSQL_HOST=localhost--MYSQL_TCP_PORT=3306,启动成功如下图所示:

(3)    查看运行效果

通过上图,我们发现zipkin使用springboot,并且启动的端口为9411,然后我们通过浏览器访问,效果如下:

四、分布式跟踪系统实践(springboot+zipkin+mysql)

4.1场景设置与分析

现在有一个服务A调用服务B,服务B又分别调用服务C和D,整个链路过程的关系图如下所示:

4.2 代码编写

具体代码和上一节代码相同,源代码下载地址:https://github.com/dreamerkr/mircoservice.git文件夹springboot+zipkin下面。

4.3运行效果

(1)分别启动每个服务,然后访问服务1,浏览器访问(http://localhost:8081/service1/test

(2)输入zipkin地址,每次trace的列表

点击其中的trace,可以看trace的树形结构,包括每个服务所消耗的时间:

点击每个span可以获取延迟信息:

同时可以查看服务之间的依赖关系:

同时查看zipkin数据库表已经存在数据:

 

微服务之分布式跟踪系统(springboot+zipkin+mysql)的更多相关文章

  1. 微服务之分布式跟踪系统(springboot+pinpoint)

    这篇文章介绍一下在微服务(springboot开发)的项目中使用pintpoint监控的过程及效果展示. 背景 随着项目微服务的进行,微服务数量逐渐增加,服务间的调用也越来越复杂,我们急切需要一个AP ...

  2. 基于SkyWalking的分布式跟踪系统 - 微服务监控

    上一篇文章我们搭建了基于SkyWalking分布式跟踪环境,今天聊聊使用SkyWalking监控我们的微服务(DUBBO) 服务案例 假设你有个订单微服务,包含以下组件 MySQL数据库分表分库(2台 ...

  3. 基于SkyWalking的分布式跟踪系统 - 环境搭建

    前面的几篇文章我们聊了基于Metrics的监控Prometheus,利用Prometheus和Grafana可以全方位监控你的服务器及应用的性能指标,在出现异常时利用Alertmanager告警及时通 ...

  4. 基于SkyWalking的分布式跟踪系统 - 异常告警

    通过前面2篇文章我们搭建了SW的基础环境,监控了微服务,能了解所有服务的运行情况.但是当出现服务响应慢,接口耗时严重时我们需要立即定位到问题,这就需要我们今天的主角--监控告警,同时此篇也是SW系列的 ...

  5. 最近整理出了有关大数据,微服务,分布式,Java,Python,Web前端,产品运营,交互等1.7G的学习资料,有视频教程,源码,课件,工具,面试题等等。这里将珍藏多年的资源免费分享给各位小伙伴们

    大数据,微服务,分布式,Java,Python,Web前端,产品运营,交互 领取方式在篇尾!!! 基础篇.互联网架构,高级程序员必备视频,Linux系统.JVM.大型分布式电商项目实战视频...... ...

  6. SpringCloud微服务架构分布式组件如何共享session对象

    一.简单做一个背景说明1.为说明问题,本文简单微服务架构示例如下 2.组件说明分布式架构,每个组件都是集群或者主备.具体说明如下:zuul service:网关,API调用都走zuul service ...

  7. Go微服务全链路跟踪详解

    在微服务架构中,调用链是漫长而复杂的,要了解其中的每个环节及其性能,你需要全链路跟踪. 它的原理很简单,你可以在每个请求开始时生成一个唯一的ID,并将其传递到整个调用链. 该ID称为Correlati ...

  8. Spring Cloud(8):日志及分布式跟踪(Sleuth&Zipkin)

    简介 在微服务架构中,项目中前端发起一个请求,后端可能跨几个服务调用才能完成这个请求.如果系统越来越庞大,服务之间的调用与被调用关系就会变得很复杂,那么这时候我们需要分析具体哪一个服务出问题了就会显得 ...

  9. 面试刷题37:微服务是什么?springcloud,springboot是什么?

    面试中被问到为什么要使用微服务架构?springcloud的核心组件有哪些? 拿我们国家的兵种来说,如何把战争这个单体架构微服务化,就是根据适用的场景,拆分出不同的兵种(微服务) 然后每个兵种之间通过 ...

随机推荐

  1. centos 7 防火墙的使用 firewalld

    开启端口命令 输入firewall-cmd --query-port=6379/tcp,如果返回结果为no,那么证明6379端口确实没有开启. 输入firewall-cmd --add-port=63 ...

  2. java-多态中成员访问特点-父类引用指向子类对象

    多态前提: - 要有继承关系. - 要有方法重写. - 要有父类引用指向子类对象. 1.成员变量:编译看左边(父类),运行看左边(父类) 2.成员方法:编译看左边(父类),运行看右边(子类),动态绑定 ...

  3. 2018.4.23 pip使用

    pip打包 python setup.py check  检查setup.py是不是正确,如果正确就只输出running check python setup.py dist  会将项目打包成一个ta ...

  4. 【BZOJ3238】【AHOI2013】差异

    sam好,好写好调好ac! 原题: 图片题面好评 2<=N<=500000 在syq大神的指点下终于理解一道后缀自动姬了quq (其实是因为这道题的dp主要是在后缀树(就是拓扑序)上搞树形 ...

  5. LG2516 【[HAOI2010]最长公共子序列】

    前言 感觉这几篇仅有的题解都没说清楚,并且有些还是错的,我再发一篇吧. 分析 首先lcs(最长公共子序列)肯定是板子.但这题要求我们不能光记lcs是怎么打的,因为没这部分分,并且另外一个方程的转移要用 ...

  6. day43 数据库学习 转自egon 老师博客 单表查询和多表查询

    一 单表查询的语法 SELECT 字段1,字段2... FROM 表名 WHERE 条件 GROUP BY field HAVING 筛选 ORDER BY field LIMIT 限制条数 二 关键 ...

  7. hasura graphql-engine v1.0.0-alpha30 remote schema stitch 试用

    新的hasura graphql-engine 代码仓库中已经包含了一个基于express 的简单graphql server, 可以用来测试模式拼接 graphql server 代码 项目结构 ├ ...

  8. 利用反射--调用一个按钮的Click事件

    最基本的调用方法 (1)button1.PerformClick();(2)button1_Click(null,null);(3)button_Click(null,new EventArgs()) ...

  9. oracle-pl/sql之二

    java 触发器 包 你可以编写用户定义的函数(用pl/sql,java,c)来提供在sql中或sql内置函数中不可用的功能 有时,我们会发现有些功能通过PL/SQL完成会很麻烦,而通过C/C++语言 ...

  10. 将react升级到15之后的坑

    问题来源: 运用ant-design 的metion组件必须要使用react 15.x以上的版本,而目前所用的版本是 react 0.14.x版本,所以就不得不对react进行升级   出现的问题: ...