Brief introduction
There is a correlation between multiple service calls in the micro-service architecture, when a request to slow down or unavailable, how do we quickly locate service failure point? Link tracking implementation is to solve this problem, this paper Sleuth + Zipkin + RabbitMQ + ES + Kibana achieve.
Spring Cloud Sleuth
Trace: request from a client to the system boundary, and then returned to the client in response to the system boundary.
Span: Each call record buried in a call, that is, "Span", a series of orderly Span constitute a Trace.
Zipkin
Zipkin is open source and distributed by Twitter company a tracking system for gathering timing data services, data collection, storage, search and show. Providing removable data storage: In-Memory, MySql, Cassandra and Elasticsearch.
RabbitMQ
RabbitMQ AMQP is an open source implementation, server-side using Erlang language, supports a variety of clients, for store and forward messages in a distributed system, in terms of ease of use, scalability, high availability, and so doing well.
Elasticsearch
Elasticsearch (ES) is a construct based on Lucene open source, distributed, RESTful full-text search engine interface. Elasticsearch or a distributed document database, where each field can be indexed, and the data for each field can be searched, ES can scale to hundreds of server storage and handling PB-level data. Can be stored in a very short period of time, search and analyze large amounts of data.
Kibana
Kibana can provide a friendly interface for Web log analysis Logstash and ElasticSearch, can achieve summarize, analyze and search for important data logs.
achieve
1, Zipkin server
Creating zipkin-server program (also available at the official website: https: //zipkin.io/ download jar package directly)
rely
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>io.zipkin.java</groupId> <artifactId>zipkin-server</artifactId> <version>2.11.8</version> </dependency> <dependency> <groupId>io.zipkin.java</groupId> <artifactId>zipkin-autoconfigure-ui</artifactId> <version>2.11.8</version> </dependency> <dependency> <groupId>io.zipkin.java</groupId> <artifactId>zipkin-autoconfigure-collector-rabbitmq</artifactId> <version>2.11.8</version> </dependency> <dependency> <groupId>io.zipkin.java</groupId> <artifactId>zipkin-autoconfigure-storage-elasticsearch-http</artifactId> <version>2.8.4</version> </dependency>
Configuration
spring: application: name: zipkin-server server: port: 8033 eureka: client: serviceUrl: defaultZone: http://localhost:8088/eureka/ instance: prefer-ip-address: true management: metrics: web: server: auto-time-requests: false zipkin: collector: rabbitmq: addresses: 192.168.233.128 port: 5672 username: zipkin password: zipkin virtual-host: vh1 queue: zipkin storage: StorageComponent: elasticsearch type: elasticsearch elasticsearch: hosts: 192.168.233.171:9200 cluster: elasticsearch index: zipkin index-shards: 5 index-replicas: 1
Startup class
@SpringBootApplication @EnableEurekaClient @EnableZipkinServer public class ZipkinServerApplication { public static void main(String[] args) { SpringApplication.run(ZipkinServerApplication.class, args); } }
access
2, Zipkin client
rely
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-sleuth</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zipkin</artifactId> </dependency>
配置
spring: sleuth: sampler: probability: 1.0 zipkin: sender: type: RABBIT rabbitmq: addresses: 192.168.233.128 port: 5672 username: zipkin password: zipkin virtual-host: vh1
3、测试:
访问zipkin客户端服务,如我本地user-server
查看zipkin服务端
访问Kibana,配置一个index pattern
修改默认时间格式
看一下效果
END
欢迎关注微信公众号:牧码笔记,时时获取最新技术分享。