zipkin docker

您也可以通过 Docker 启动 Zipkin。

# Note: this is mirrored as ghcr.io/openzipkin/zipkin
docker run -d -p 9411:9411 openzipkin/zipkin

服务器运行后,您可以在 中使用 Zipkin UI 查看跟踪 http://your_host:9411/zipkin/

如果您的应用程序尚未发送跟踪,请使用Zipkin 检测配置它们或尝试我们的示例之一。

查看zipkin-server文档以获取配置详细信息,或查看Docker 示例以了解如何使用 docker-compose。

Zipkin Slim

Zipkin 的 slim build 体积更小,启动速度更快。它支持内存和 Elasticsearch 存储,但不支持 Kafka 或 RabbitMQ 等消息传递传输。如果这些约束符合您的需求,您可以像下面这样尝试 slim:

通过 Java 运行:(-D 启动zipkin时携带参数)

curl -sSL https://zipkin.io/quickstart.sh | bash -s io.zipkin:zipkin-server:LATEST:slim zipkin.jar
# 使用内存进行数据存储、通过HTTP进行链路追踪采集
java -jar zipkin.jar
# 使用MySQL进行数据存储、通过HTTP进行链路追踪采集
java -DSTORAGE_TYPE=mysql -DMYSQL_HOST=192.168.3.20 -DMYSQL_TCP_PORT=3306 -DMYSQL_DB=zipkin_db -DMYSQL_USER=zipkin -DMYSQL_PASS=zipkin -jar zipkin.jar
# 使用MySQL进行数据存储、通过RabbitMQ进行链路追踪采集
java -DSTORAGE_TYPE=mysql -DMYSQL_HOST=192.168.3.20 -DMYSQL_TCP_PORT=3306 -DMYSQL_DB=zipkin_db -DMYSQL_USER=zipkin -DMYSQL_PASS=zipkin -DRABBIT_ADDRESSES=192.168.3.20:5672 -DRABBIT_USER=admin -DRABBIT_PASSWORD=admin -jar zipkin.jar
# 使用MySQL进行数据存储、通过Kafka进行链路追踪采集
java -DSTORAGE_TYPE=mysql -DMYSQL_HOST=192.168.3.20 -DMYSQL_TCP_PORT=3306 -DMYSQL_DB=zipkin_db -DMYSQL_USER=zipkin -DMYSQL_PASS=zipkin -DKAFKA_BOOTSTRAP_SERVERS=192.168.3.20:9092 -jar zipkin.jar
# 使用Elasticsearch进行数据存储、通过HTTP进行链路追踪采集
java -DSTORAGE_TYPE=elasticsearch -DES_HOSTS=http://10.22.0.130:9200 -DKAFKA_ZOOKEEPER=10.22.0.130:2181 -jar zipkin.jar
# 使用Cassandra进行数据存储、通过HTTP进行链路追踪采集
java -DSTORAGE_TYPE=cassandra3 -DCASSANDRA_ENSURE_SCHEMA=false -DCASSANDRA_CONTACT_POINTS=http://10.22.0.130:9200 -DCASSANDRA_USERNAME=cassandra -DCASSANDRA_PASSWORD=cassandra -jar zipkin.jar

通过 Docker 运行:

# Note: this is mirrored as ghcr.io/openzipkin/zipkin-slim
# 使用内存进行数据存储、通过HTTP进行链路追踪采集
docker run -d -p 9411:9411 openzipkin/zipkin-slim
# 使用MySQL进行数据存储、通过HTTP进行链路追踪采集
docker run -d -p 9411:9411 openzipkin/zipkin-slim -STORAGE_TYPE=mysql -MYSQL_HOST=192.168.3.20 -MYSQL_TCP_PORT=3306 -MYSQL_DB=zipkin_db -MYSQL_USER=zipkin -MYSQL_PASS=123456
# 使用MySQL进行数据存储、通过RabbitMQ进行链路追踪采集
docker run -d -p 9411:9411 openzipkin/zipkin-slim -STORAGE_TYPE=mysql -MYSQL_HOST=192.168.3.20 -MYSQL_TCP_PORT=3306 -MYSQL_DB=zipkin_db -MYSQL_USER=zipkin -MYSQL_PASS=zipkin -RABBIT_ADDRESSES=192.168.3.20:5672 -RABBIT_USER=admin -RABBIT_PASSWORD=admin
# 使用Cassandra进行数据存储、通过HTTP进行链路追踪采集
docker run -d -p 9411:9411 openzipkin/zipkin-slim -STORAGE_TYPE=cassandra3 -DCASSANDRA_ENSURE_SCHEMA=false -CASSANDRA_CONTACT_POINTS=192.168.3.20 -CASSANDRA_USERNAME=zipkin -CASSANDRA_PASSWORD=123456

https://github.com/openzipkin/zipkin/tree/master/docker/examples

docker-compose.yml

version: '2.4'

services:
  # The zipkin process services the UI, and also exposes a POST endpoint that
  # instrumentation can send trace data to.
  zipkin:
    image: ghcr.io/openzipkin/zipkin-slim:${TAG:-latest}
    container_name: zipkin
    # Environment settings are defined here https://github.com/openzipkin/zipkin/blob/master/zipkin-server/README.md#environment-variables
    environment:
      - STORAGE_TYPE=mem
      # Point the zipkin at the storage backend
      - MYSQL_HOST=mysql
      # Uncomment to enable self-tracing
      # - SELF_TRACING_ENABLED=true
      # Uncomment to increase heap size
      # - JAVA_OPTS=-Xms128m -Xmx128m -XX:+ExitOnOutOfMemoryError
    ports:
      # Port used for the Zipkin UI and HTTP Api
      - 9411:9411
    # Uncomment to enable debug logging
    # command: --logging.level.zipkin2=DEBUG

docker-compose-ui.yml

version: '2.4'

services:
  zipkin-ui:
    image: ghcr.io/openzipkin/zipkin-ui:${TAG:-latest}
    container_name: zipkin-ui
    environment:
      # Change this if connecting to a different zipkin server
      - ZIPKIN_BASE_URL=http://zipkin:9411
    ports:
      - 80:80
    depends_on:
      - zipkin

初始化 MySQL

https://github.com/openzipkin/zipkin/tree/master/zipkin-storage/mysql-v1/src/main/resources

mysql.sql

--
-- Copyright 2015-2019 The OpenZipkin Authors
--
-- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
-- in compliance with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software distributed under the License
-- is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
-- or implied. See the License for the specific language governing permissions and limitations under
-- the License.
--

CREATE TABLE IF NOT EXISTS zipkin_spans (
  `trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',
  `trace_id` BIGINT NOT NULL,
  `id` BIGINT NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `remote_service_name` VARCHAR(255),
  `parent_id` BIGINT,
  `debug` BIT(1),
  `start_ts` BIGINT COMMENT 'Span.timestamp(): epoch micros used for endTs query and to implement TTL',
  `duration` BIGINT COMMENT 'Span.duration(): micros used for minDuration and maxDuration query',
  PRIMARY KEY (`trace_id_high`, `trace_id`, `id`)
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;

ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTracesByIds';
ALTER TABLE zipkin_spans ADD INDEX(`name`) COMMENT 'for getTraces and getSpanNames';
ALTER TABLE zipkin_spans ADD INDEX(`remote_service_name`) COMMENT 'for getTraces and getRemoteServiceNames';
ALTER TABLE zipkin_spans ADD INDEX(`start_ts`) COMMENT 'for getTraces ordering and range';

CREATE TABLE IF NOT EXISTS zipkin_annotations (
  `trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',
  `trace_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.trace_id',
  `span_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.id',
  `a_key` VARCHAR(255) NOT NULL COMMENT 'BinaryAnnotation.key or Annotation.value if type == -1',
  `a_value` BLOB COMMENT 'BinaryAnnotation.value(), which must be smaller than 64KB',
  `a_type` INT NOT NULL COMMENT 'BinaryAnnotation.type() or -1 if Annotation',
  `a_timestamp` BIGINT COMMENT 'Used to implement TTL; Annotation.timestamp or zipkin_spans.timestamp',
  `endpoint_ipv4` INT COMMENT 'Null when Binary/Annotation.endpoint is null',
  `endpoint_ipv6` BINARY(16) COMMENT 'Null when Binary/Annotation.endpoint is null, or no IPv6 address',
  `endpoint_port` SMALLINT COMMENT 'Null when Binary/Annotation.endpoint is null',
  `endpoint_service_name` VARCHAR(255) COMMENT 'Null when Binary/Annotation.endpoint is null'
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;

ALTER TABLE zipkin_annotations ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `span_id`, `a_key`, `a_timestamp`) COMMENT 'Ignore insert on duplicate';
ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`, `span_id`) COMMENT 'for joining with zipkin_spans';
ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTraces/ByIds';
ALTER TABLE zipkin_annotations ADD INDEX(`endpoint_service_name`) COMMENT 'for getTraces and getServiceNames';
ALTER TABLE zipkin_annotations ADD INDEX(`a_type`) COMMENT 'for getTraces and autocomplete values';
ALTER TABLE zipkin_annotations ADD INDEX(`a_key`) COMMENT 'for getTraces and autocomplete values';
ALTER TABLE zipkin_annotations ADD INDEX(`trace_id`, `span_id`, `a_key`) COMMENT 'for dependencies job';

CREATE TABLE IF NOT EXISTS zipkin_dependencies (
  `day` DATE NOT NULL,
  `parent` VARCHAR(255) NOT NULL,
  `child` VARCHAR(255) NOT NULL,
  `call_count` BIGINT,
  `error_count` BIGINT,
  PRIMARY KEY (`day`, `parent`, `child`)
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
作者:Jeebiz  创建时间:2023-03-16 11:18
最后编辑:Jeebiz  更新时间:2023-03-20 16:51