基础框架系列 -01:zipkin 的简单使用

本贴最后更新于 1914 天前,其中的信息可能已经时过境迁

zipkin 的使用涉及到两方面内容,一个是 zipkin-client,一个是 zipkin-server;

  1. zipkin-server 确定数据的存储方式及数据的传输方式;
  2. zipkin-client 依据 zipkin-server 的传输方式配置。

1. zipkin-client 的使用配置如下

1.1 需要在项目的 pom.xml 引入 lls-zipkin 的依赖。

dependency 依赖

<dependency>
    <groupId>com.lls.framework</groupId>
    <artifactId>lls-zipkin</artifactId>
</dependency>

1.2 需要在 application.properties 配置 zipkin 信息。

properties 配置

## zinkin开关,默认为true
#spring.zipkin.enabled=false
## zipkin地址
spring.zipkin.base-url=http://172.16.90.168:9411
## 链路跟踪采集比例,默认为0.1
spring.sleuth.sampler.probability=1

## zipkin-server默认使用http收集数据,如需使用rabbitmq收集数据时,需要配置rabbit
spring.zipkin.sender.type=rabbit
spring.zipkin.rabbitmq.queue=zipkin
spring.rabbitmq.host=127.0.0.1
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest

2. zipkin-server 的使用配置

2.1 启动参数

启动参数说明:zipkin-server

如果在 Windows 系统启动,启动参数前要增加 -D,如

## windows系统启动
java -jar -DRABBIT_ADDRESSES=localhost:5672 -DRABBIT_USER=guest -DRABBIT_PASSWORD=guest zipkin-server-2.12.0-exec.jar

## linux系统启动
RABBIT_ADDRESSES=localhost:5672 RABBIT_USER=guest RABBIT_PASSWORD=guest java -jar zipkin-server-2.12.0-exec.jar 

2.2 数据收集的传输方式

默认使用 http 方式收集,可支持 kafkarabbitmq 等,下面以 rabbitmq 为例。

配置参考 collector-rabbitmq

RABBIT_ADDRESSES=172.16.90.168:5672 RABBIT_USER=lls RABBIT_PASSWORD=lls java -jar zipkin-server-2.12.0-exec.jar 

2.3 数据的存储方式

默认使用内存方式进行存储,可支持 elasticsearchmysql 等。

2.3.1 elasticsearch

2.3.1.1. 启动命令


STORAGE_TYPE=elasticsearch ES_HOSTS=http://172.16.90.168:9200  ES_HTTP_LOGGING=BASIC java -jar zipkin-server-2.12.0-exec.jar 

2.3.1.2. 配置说明

* `ES_HOSTS`: A comma separated list of elasticsearch base urls to connect to ex. http://host:9200.
              Defaults to "http://localhost:9200".
* `ES_PIPELINE`: Indicates the ingest pipeline used before spans are indexed. No default.
* `ES_TIMEOUT`: Controls the connect, read and write socket timeouts (in milliseconds) for
                Elasticsearch Api. Defaults to 10000 (10 seconds)
* `ES_INDEX`: The index prefix to use when generating daily index names. Defaults to zipkin.
* `ES_DATE_SEPARATOR`: The date separator to use when generating daily index names. Defaults to '-'.
* `ES_INDEX_SHARDS`: The number of shards to split the index into. Each shard and its replicas
                     are assigned to a machine in the cluster. Increasing the number of shards
                     and machines in the cluster will improve read and write performance. Number
                     of shards cannot be changed for existing indices, but new daily indices
                     will pick up changes to the setting. Defaults to 5.
* `ES_INDEX_REPLICAS`: The number of replica copies of each shard in the index. Each shard and
                       its replicas are assigned to a machine in the cluster. Increasing the
                       number of replicas and machines in the cluster will improve read
                       performance, but not write performance. Number of replicas can be changed
                       for existing indices. Defaults to 1. It is highly discouraged to set this
                       to 0 as it would mean a machine failure results in data loss.
* `ES_USERNAME` and `ES_PASSWORD`: Elasticsearch basic authentication, which defaults to empty string.
                                   Use when X-Pack security (formerly Shield) is in place.
* `ES_HTTP_LOGGING`: When set, controls the volume of HTTP logging of the Elasticsearch Api.
                     Options are BASIC, HEADERS, BODY

2.3.2 mysql

2.3.2.1. 在 mysql 数据库上创建 zipkin 所需要的表,执行的 sql 语句见 mysql(需要找匹配版本的 sql)或者 ./sql/mysql.sql(对应 zipkin-server-2.12.0)

2.3.2.2. 启动 zipkin-server 时加上 mysql 的配置参数,例如

STORAGE_TYPE=mysql MYSQL_DB=zipkin MYSQL_HOST=172.16.90.168 MYSQL_TCP_PORT=3306 MYSQL_USER=root MYSQL_PASS=123456 MYSQL_MAX_CONNECTIONS=100 java -jar zipkin-server-2.12.0-exec.jar  

2.3.2.3. Mysql 的配置说明

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

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...