参考文章:
每天学点SpringCloud(十四):Zipkin使用SpringCloud Stream以及El
Spring Cloud(十二):分布式链路跟踪 Sleuth 与 Zipkin【Finchley 版】
服务链路追踪(Spring Cloud Sleuth)
Spring Cloud Sleuth + zipkin 实现服务追踪
全链路监控(一):方案概述与比较
Java分布式跟踪系统Zipkin(一):初识Zipkin
Spring Cloud Sleuth与Zipkin整合时遇到的问题记录
------------------------------------------------------------------------
目录
一. zipkin-server-stream 项目配置
1.pom.xml文件
2.application.yml配置:
3.springboot启动类
二. zipkin-server-stream-elasticsearch 项目配置
1.pom.xml文件
2.application.yml配置:
3.springboot启动类
三. zipkin-server-stream 项目配置
1.pom.xml文件
2.application.yml配置
3.springboot启动类
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE
zipkin-server-stream
Finchley.SR2
2.11.9
com.cloud
${project-name}
0.0.1-SNAPSHOT
jar
${project-name}
${project-name}
io.zipkin.java
zipkin-server
${zipkin.version}
io.zipkin.java
zipkin-autoconfigure-collector-rabbitmq
${zipkin.version}
io.zipkin.java
zipkin-autoconfigure-ui
2.11.12
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
# http://localhost:18210/zipkin/
server:
address: 127.0.0.1
management:
metrics:
web:
server:
auto-time-requests: false
zipkin:
collector:
rabbitmq:
addresses: 10.101.15.159:5672
password: guest
username: guest
queue: zipkin
spring:
application:
name: zipkin-server-stream #ServiceId, 配置服务命名,不区分大小写,在注册中心管理界面默认大写显示
package com.cloud;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import zipkin2.server.internal.EnableZipkinServer;
/**
* 该类必须放在一级目录下, 否则会报错
*/
@EnableZipkinServer
@SpringBootApplication
public class ZipkinServerStreamApplication {
private static Logger log = LoggerFactory.getLogger(ZipkinServerStreamApplication.class);
public static void main(String[] args) {
SpringApplication.run(ZipkinServerStreamApplication.class, args);
log.info("log4j2 start!");
}
}
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE
zipkin-server-stream-elasticsearch
2.11.9
com.cloud
${project-name}
0.0.1-SNAPSHOT
jar
${project-name}
${project-name}
io.zipkin.java
zipkin-server
${zipkin.version}
io.zipkin.java
zipkin-autoconfigure-collector-rabbitmq
${zipkin.version}
io.zipkin.java
zipkin-autoconfigure-storage-elasticsearch-http
2.8.4
io.zipkin.java
zipkin-autoconfigure-ui
2.11.12
# http://localhost:18220/zipkin/
server:
address: 127.0.0.1
management:
metrics:
web:
server:
auto-time-requests: false
zipkin:
collector:
rabbitmq:
addresses: 10.101.15.159:5672
password: guest
username: guest
queue: zipkin
storage:
type: elasticsearch
elasticsearch:
cluster: elasticsearch
hosts: http://10.101.15.159:9200
index: zipkin
index-shards: 5
index-replicas: 1
spring:
application:
name: zipkin-server-stream-elasticsearch #ServiceId, 配置服务命名,不区分大小写,在注册中心管理界面默认大写显示
package com.cloud;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import zipkin2.server.internal.EnableZipkinServer;
/**
* 该类必须放在一级目录下, 否则会报错
* @author Administrator
*/
@EnableZipkinServer
@SpringBootApplication
public class ZipkinServerStreamEsApplication {
private static Logger log = LoggerFactory.getLogger(ZipkinServerStreamEsApplication.class);
public static void main(String[] args) {
SpringApplication.run(ZipkinServerStreamEsApplication.class, args);
log.info("log4j2 start!");
}
}
4.0.0
com.cloud
cloud-parent
0.0.1-SNAPSHOT
zipkin-client-sleuth-stream
${project-name}
0.0.1-SNAPSHOT
jar
${project-name}
${project-name}
org.springframework.cloud
spring-cloud-starter-zipkin
org.springframework.amqp
spring-rabbit
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
com.alibaba
fastjson
1.1.15
#用于开发环境
server:
address: 127.0.0.1
spring:
application:
name: zipkin-client-sleuth-stream #ServiceId, 配置服务命名, 不区分大小写, 在注册中心管理界面默认大写显示
sleuth:
sampler:
probability: 1.0 #监测比例, 默认为0.1, 设置为1则为每次http动作都监控, 但是对性能会有影响 percentage probability
rabbitmq:
host: 10.101.15.159
port: 5672
username: guest
password: guest
listener:
type: direct # simple direct
zipkin:
rabbitmq:
queue: zipkin
eureka:
client:
serviceUrl:
defaultZone: http://10.101.15.159:18000/eureka/ # 47.105.58.100 - 10.101.15.59
instance:
#不使用主机名来定义注册中心的地址, 而使用IP地址的形式,
#如果设置了ipAddress 属性, 则使用该属性配置的IP, 否则自动获取除环路IP外的第一个IP地址
preferIpAddress: true #自动将IP注册到Eureka Server上, 如果不配置就是机器的主机名
#ipAddress: 192.168.1.128 # IP地址
#将Instance ID设置成IP:端口的形式
instance-id: ${spring.cloud.client.ip-address}:${server.port}
#注意:更改Eureka更新频率将打破服务器的自我保护功能, 生产环境下不建议自定义这些配置。
lease-expiration-duration-in-seconds: 30 #续约到期时间(默认90秒)
lease-renewal-interval-in-seconds: 10 #续约更新时间间隔(默认30秒)
metadata-map: # 自定义的元数据, key/value可以随便写
lpf: 123 # 自定义的元数据
package com.cloud;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
/**
* 该类必须放在一级目录下, 否则会报错
* @author Administrator
*/
@EnableEurekaClient // Eureka微服务注解
@SpringBootApplication
public class SleuthZipkinClientStreamApplication {
private static Logger log = LoggerFactory.getLogger(SleuthZipkinClientStreamApplication.class);
public static void main(String[] args) {
SpringApplication.run(SleuthZipkinClientStreamApplication.class, args);
log.info("log4j2 start!");
}
}