依赖的环境:mysq rabbit elasticsearch
1、zipkin 服务端 pom 需要引入的jar
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
<version>2.8.4</version>
<exclusions>
<exclusion>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-collector-rabbitmq</artifactId>
<version>2.8.4</version>
</dependency>
<!-- elasticsearch 存储方式 -->
<!--<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-storage-elasticsearch-http</artifactId>
<version>2.8.4</version>
</dependency>-->
<!-- mysql 存储方式 -->
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-storage-mysql</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.9</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
2、zipkin 服务端 application.yml 中的配置
server:
port: 9411
spring:
application:
name: jplat-zipkin-server
datasource:
name: zipkin
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://10.130.5.109:3306/zipkin?characterEncoding=utf8&useSSL=true
username: root
password: 123456
schema: classpath:/zipkin.sql
continue-on-error: true
rabbitmq:
host: 192.168.213.130
port: 5672
username: rabbit
password: 123456
sleuth:
sampler:
percentage: 1.0 #默认的采样比率为0.1,不能看到所有请求数据,可以在每个客户端的application.yml中加入下面的配置,更改采样比率为1,就能看到所有的请求数据了,但是这样会增加接口调用延迟
enabled: false
zipkin:
storage:
type: mysql
#type: elasticsearch
#StorageComponent: elasticsearch
#elasticsearch:
#cluster: elasticsearch
#hosts: 192.168.213.130:9200
#hosts: 192.168.0.102:9200
#max-requests: 64
#index: zipkin
#index-shards: 5
#index-replicas: 1
collector:
rabbitmq:
uri: amqp://rabbit:123456@192.168.213.130:5672
#uri: amqp://rabbit:123456@192.168.0.102:5672
queue: zipkin
eureka:
client:
service-url:
defaultZone: http://localhost:28080/eureka/
3、zipkin 服务端 启动类中配置
image.png
4、每个微服务端的pom中需要引入的jar
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
<version>1.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
5、每个微服务端的application.yml 中新增配置项
rabbitmq:
host: 192.168.213.130
#host: 192.168.0.102
port: 5672
username: rabbit
password: 123456
zipkin:
service:
name: ${spring.application.name}
sender:
type: rabbit
sleuth:
#messaging:
#rabbit:
#enabled: true
sampler:
percentage: 1.0
6、访问zipkin
http://127.0.0.1:9411/zipkin/
网友评论