SpringCloud之Zipkin搭建

这几天搭建zipkin,发现自己搭建服务文档都不是全面,官网也推荐使用提供jar包直接启动部署,很多博客也都是jar包启动,或者配合docker搭建,本着自己搭建的想法,立马上手。官网github地址

项目环境:SpringCloud Greewich.SR5版本、JDK1.8、Maven3.6。(其他相关组件也已经搭建投入使用)

maven项目主要是pom文件和yml文件的配置



    4.0.0

    com.yeion
    yeion-channel-zipkin
    1.0-SNAPSHOT

    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.13.RELEASE
    

    
        1.8
        Greenwich.SR5
        1.1.10
        2.2.3.RELEASE
        2.12.9
    

    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

    
        
            io.zipkin.java
            zipkin-autoconfigure-ui
            ${zipkin.version}
        
        
            io.zipkin.java
            zipkin-server
            ${zipkin.version}
            
                
                    org.springframework.boot
                    spring-boot-starter-log4j2
                
            
        
        
        
            io.zipkin.java
            zipkin-autoconfigure-collector-rabbitmq
            ${zipkin.version}
        
        
            io.zipkin.java
            zipkin-autoconfigure-storage-mysql
            ${zipkin.version}
        
        
            mysql
            mysql-connector-java
        
        
            org.springframework.boot
            spring-boot-starter-jdbc
            
                
                
                    org.apache.tomcat
                    tomcat-jdbc
                
            
        
        
        
            com.zaxxer
            HikariCP
        
        
        
            org.springframework.boot
            spring-boot-starter-actuator
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
                2.1.13.RELEASE
                
                    
                        
                            repackage
                        
                    
                
                
                    sleuth.webmvc.Backend
                    exec
                    true
                
            
        
    

#author: rhb
#date: 2020.07.17
###############################################################################################

server:
  compression:
    enabled: true

# datasoure默认使用JDBC
spring:
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: xxx
    password: xxx
    url: jdbc:mysql://x.x.x.x:3306/zipkin?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8&useAffectedRows=true&allowMultiQueries=true&autoReconnect=true&autoReconnectForPools=true
    #解决The bean 'characterEncodingFilter'
    hikari:
      maximum-pool-size: 15
      auto-commit: true
      idle-timeout: 30000
      pool-name: DatebookHikariCP
      max-lifetime: 500000
      connection-timeout: 30000
      connection-test-query: SELECT 1
  main:
    allow-bean-definition-overriding: true
    web-application-type: none
  sleuth:
    enabled: false
  rabbitmq:
    host: x.x.x.x
    port: 5672
    username: xxx
    password: xxx
  application:
    name: channel-zipkin-server

#指定存储类型:mysql
zipkin:
  storage:
    type: mysql

#解决IllegalArgumentException: Prometheus
management:
  metrics:
    web:
      server:
        auto-time-requests: false

logging:
  level:
    root: info

# 异步容器armeria取代tomcat
armeria:
  ports:
    - port: 10017
      protocols:
        - http
  gracefulShutdownQuietPeriodMillis: -1
  gracefulShutdownTimeoutMillis: -1

#注册
eureka:
  client:
    registerWithEureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://${eureka.instance.hostname}:10010/eureka/
  instance:
    hostname: localhost
    prefer-ip-address: true
    instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:10017
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import zipkin2.server.internal.EnableZipkinServer;

/**
 * @Author: rhb
 * @Date: 2020/7/16 13:49
 * @Description: Zipkin Server启动类 (采用http方式+mysql存储)
 */
@SpringBootApplication
@EnableZipkinServer
@EnableEurekaClient
public class ZipkinServerApplication {

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

}

上述3段代码就是搭建的Zipkin Server的完成样例,亲测有效。

遇到问题阐述:

1. The Bean 'characterEncodingFilter' ... 这类问题主要是Spring Bean重复导致,将Spring Bean重复开启解决:spring.main.allow-bean-definition-overriding=true。

2. ClassNotFound ... byteBuf、channelBuf、...这类问题主要是版本冲突,可以点开报错源码查看,主要是springboot或者springcloud与zipkin的版本不兼容。

3. 由于在zipkin社区推出的最新版本不再采用tomcat容器,换做armeria来替代(armeria:资料很少,可以理解为tomcat的使用异步通讯的优化),这样导致原本的server.port失效,可以查看源码发现yml文件中修改端口配置。

SpringCloud之Zipkin搭建_第1张图片

4. 搭建数据库,也可以通过查看源码找到相关脚本(就不再贴出脚本内容)

SpringCloud之Zipkin搭建_第2张图片

希望博主可以帮到大家,有错误的地方,也望大家指出。转载请标明出处*-*

你可能感兴趣的:(SpringCloud,spring,boot)