链路追踪系统 zipkin

Posted ggwow

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了链路追踪系统 zipkin相关的知识,希望对你有一定的参考价值。

一、构建项目

用到的依赖直接看pom.xml的注释吧

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>cnex.cloud</groupId>
    <artifactId>zipkin</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>cloud-zipkin</name>
    <description>zipkin</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Edgware.RELEASE</spring-cloud.version>
    </properties>

    <dependencies>
    
        <!-- 注册中心 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>

        <!-- zipkin -->
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-server</artifactId>
        </dependency>

        <!-- zipkin ui -->
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-autoconfigure-ui</artifactId>
            <scope>runtime</scope>
        </dependency>
        
        <!-- 配置中心 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

二、配置文件

因为已经有了配置中心,所以大多数配置现在开始放在SVN下,先展示一下项目内的配置文件

application.yml

只指定一个运行端口

server:  
  port: 9003

现在多引用了一个

bootstrap.yml

bootstrap.yml 是先于 application.yml 加载的,所以连接配置中心的参数需要在bootstrap.yml 设置

spring: 
  cloud: 
    config:
      uri: http://10.180.206.254:8999/ 
      profile: dev
      name: cloud-zipkin

 uri 设置的就是配置中心的地址

profile 设置版本,开发/测试/验收/生产

name 配置文件名

svn下的配置文件配置: cloud-zipkin-dev.yml

#Application name  
spring:  
  application:  
    name: cloud-zipkin
    
#注册中心      
eureka:
  client:   
    serviceUrl:
      defaultZone: http://10.180.206.254:9000/eureka/
  instance:
    ip-address: 10.180.206.254
    prefer-ip-address: true
    instance-id: ${eureka.instance.ip-address}:${server.port}

三、开启服务

package cnex.cloud.zipkin;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import zipkin.server.EnableZipkinServer;


@SpringBootApplication
@EnableZipkinServer //开启链路追踪
public class CloudZipkinApplication {

    public static void main(String[] args) {
        SpringApplication.run(CloudZipkinApplication.class, args);
    }
}

 

四、客户端

移步客户端

以上是关于链路追踪系统 zipkin的主要内容,如果未能解决你的问题,请参考以下文章

服务链路追踪

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

链路追踪系统 zipkin

zipkin链路追踪

分布式链路监控与追踪系统

分布式链路追踪系统预研第二篇