1.zipkin+mysql+rabbitmq储存数据。
zipkin.mysql建表语句可以百度搜索。
zipkin-server的pom文件需要引入以下依赖:
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
</dependency>
<!-- 使用消息的方式收集数据(使用rabbitmq) -->
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-collector-rabbitmq</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-storage-mysql</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<exclusions>
<!--去掉默认的tomcat-jdbc的依赖-->
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--HikariCP连接池-->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
好了之后 在配置文件中配置:
server:
port: 5113
# datasoure默认使用JDBC
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://127.0.0.1/zipkin?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
zipkin:
collector:
rabbitmq:
addresses: 192.168.33.182:5672
password: 123456
username: admin
queue: zipkin
storage:
type: mysql
启动类;
@EnableDiscoveryClient
@SpringBootApplication
@EnableZipkinServer
public class LongforZipkinDbApplication {
public static void main(String[] args) {
SpringApplication.run(LongforZipkinDbApplication.class, args);
}
好了之后再浏览器输入ip:端口 进入zipkin可视化界面。
zipkin的客户端需要引入2个依赖pom.xml:
<!--zipkin-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<!--rabbitMQ-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
配置文件:
queue和server对应。采样率为1.0 全部。rabbitmq配置。好了直接就可以直接启动客户端了。建议准备2个客户端,使用Feign调用。
spring.zipkin.rabbitmq.queue=zipkin
spring.zipkin.sleuth.sampler.percentage=1.0
spring.rabbitmq.host=127.0.0.1
spring.rabbitmq.port=5672
spring.rabbitmq.username=admin
spring.rabbitmq.password=123456
好了 有时间使用elk储存数据,db储存在后期数据量太大了,慢的很。
——————————-elasticsearch储存数据—————————
只需要将storage:mysql替换成下面这个配置就可以了,数据库配置可以去掉。 这个ip是你es的地址和端口,目前我用的是单台es。
storage:
type: elasticsearch
elasticsearch:
hosts: 127.0.0.1:9200
cluster: elasticsearch
index: zipkin
max-requests: 64
index-shards: 5
index-replicas: 1