spring cloud zipkin2 + mysql

前言:将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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容