美文网首页Spring Cloud
spring cloud zipkin2 + mysql

spring cloud zipkin2 + mysql

作者: 就怕是个demo | 来源:发表于2018-08-22 09:37 被阅读25次

前言:将springboot升级至2.0后,发现zipkin2使用mysql做日志存储出错,现将解决过程做个笔记。
注:2.0之后官方不再建议自定义zipkin,建议使用官方提供的zipkin.jar包,至于下载地址去百度吧。

建立zipkin-server项目
  • pom.xml
<dependencies>
        <!-- 2.0.1.RELEASE -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <!-- 2.0.4.RELEASE -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!-- 2.0.4.RELEASE -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- 2.11.1 -->
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-server</artifactId>
        </dependency>
        <!-- 2.11.1 -->
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-autoconfigure-ui</artifactId>
        </dependency>
       <!-- zipkin2.x 需要此包连接操作mysql -->
       <!-- 3.11.4 -->
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq</artifactId>
        </dependency>
       <!-- 2.11.1 -->
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-autoconfigure-storage-mysql</artifactId>
        </dependency>
        <!--内含druid数据源连接-->
        <dependency>
            <groupId>com.yuan.utils</groupId>
            <artifactId>datasource-utils</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
    </dependencies>
  • application.yml
spring:
  application:
    name: microservice-zipkin
  sleuth:
    enabled: false

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS
  metrics:
    web:
      server:
        auto-time-requests: false

druid:
  enable: true
  datasource:
    url: jdbc:mysql://localhost:3306/zipkin?characterEncoding=utf8&useSSL=true&verifyServerCertificate=false
    username: root
    password: 761341
    driverClassName: com.mysql.jdbc.Driver

zipkin:
  storage:
    type: mysql
  • 启动类
@SpringBootApplication
@EnableZipkinServer
public class MicroserviceZipkinApplication {

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

    @Bean
    public MySQLStorage mySQLStorage(@Qualifier("druidDatasource") DataSource dataSource) {
        return MySQLStorage.newBuilder().datasource(dataSource).executor(Runnable::run).build();
    }
}
  • 调用客户端可以看见zipkin-server


    zipkin-server.png
  • 数据库


    数据库.png
数据库.png

相关文章

网友评论

    本文标题:spring cloud zipkin2 + mysql

    本文链接:https://www.haomeiwen.com/subject/pgleiftx.html