spring cloud zipkin2 + mysql

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

建立zipkin-server项目
  • pom.xml

        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        
        
        
            org.springframework.boot
            spring-boot-starter-actuator
        
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
        
            io.zipkin.java
            zipkin-server
        
        
        
            io.zipkin.java
            zipkin-autoconfigure-ui
        
       
       
        
            org.jooq
            jooq
        
       
        
            io.zipkin.java
            zipkin-autoconfigure-storage-mysql
        
        
        
            com.yuan.utils
            datasource-utils
            1.0.0
        
        
            mysql
            mysql-connector-java
        
    
  • 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)