使用zipkin2在SpringCloud2.0环境下追踪服务调用情况
1.目的:
使用zipkin2.0在Spring Cloud 2.0环境下,追踪服务调用情况。
2.所需组件:
zipkin2.0,Spring Cloud 2.0,Eureka Server,Eureka Client.
3.项目整体组成
如下图所示:

4.详细介绍及配置:
zipkinp的pom配置为:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.</modelVersion> <groupId>com.****</groupId>
<artifactId>zipkin-p</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>customer</module>
<module>eurekaserver</module>
<module>service</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0..RELEASE</version>
</parent> <properties>
<project.build.sourceEncoding>UTF-</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<zipkin-version>2.11.</zipkin-version>
</properties> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
<version>2.0..RELEASE</version>
</dependency>
<!-- <dependency>
<artifactId>parent</artifactId>
<groupId>io.zipkin.zipkin2</groupId>
<version>${zipkin-version}</version>
<scope>import</scope>
</dependency>-->
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
<version>${zipkin-version}</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
<version>${zipkin-version}</version>
</dependency>
</dependencies>
</dependencyManagement> </project>
zipkinserver项目的pom文件配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.</modelVersion>
<parent>
<groupId>com.****</groupId>
<artifactId>zipkin-p</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.****</groupId>
<artifactId>zipkinserver</artifactId>
<version>0.0.-SNAPSHOT</version>
<name>zipkinserver</name>
<packaging>jar</packaging>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0..RELEASE</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>
配置完成后,在启动类,配置如下:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import zipkin2.server.internal.EnableZipkinServer; @EnableZipkinServer
@EnableDiscoveryClient
@SpringBootApplication
public class ZipkinserverApplication { public static void main(String[] args) {
SpringApplication.run(ZipkinserverApplication.class, args);
} }
之后,配置yaml文件:
server:
port: 9411
eureka:
instance:
prefer-ip-address: true
hostname: localhost
client:
service-url:
defaultZone: http://admin:123456@localhost:8888/eureka/
spring:
application:
name: zipkinserver
配置eurekaserver项目,pom及启动类的配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.</modelVersion>
<parent>
<groupId>com.****</groupId>
<artifactId>zipkin-p</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.****</groupId>
<artifactId>eurekaserver</artifactId>
<version>0.0.-SNAPSHOT</version>
<name>eurekaserver</name>
<description>Demo project for Spring Boot</description> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>2.0..RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @EnableEurekaServer
@SpringBootApplication
public class EurekaserverApplication { public static void main(String[] args) {
SpringApplication.run(EurekaserverApplication.class, args);
} }
配置完成后,配置yaml文件:
server:
port: 8888 eureka:
instance:
hostname: localhost
lease-expiration-duration-in-seconds: 60
lease-renewal-interval-in-seconds: 20
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://admin:123456@${eureka.instance.hostname}:${server.port}/eureka/
healthcheck:
enabled: true
spring:
application:
name: euraka-server
management:
endpoint:
health:
enabled: true
login:
user:
name: admin
password: 123456
至此Eureka配置完成,剩下配置service及customer项目,先看service项目:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.****</groupId>
<artifactId>zipkin-p</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.****</groupId>
<artifactId>service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>service</name>
<description>Demo project for Spring Boot</description> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @EnableDiscoveryClient
@SpringBootApplication
public class ServiceApplication { public static void main(String[] args) {
SpringApplication.run(ServiceApplication.class, args);
} }
eureka:
client:
serviceUrl:
defaultZone: http://admin:123456@localhost:8888/eureka/
server:
port: 8001
spring:
application:
name: user-service
zipkin:
base-url: http://localhost:9411
sleuth:
sampler:
percentage: 1.0
业务代码为:
@RestController
@RequestMapping("/home")
public class homeController { @RequestMapping(value = "/hello", method = RequestMethod.GET)
public String hello()
{
return "Hello,this is the service response.";
}
}
customer项目配置为:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.****</groupId>
<artifactId>zipkin-p</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.****</groupId>
<artifactId>customer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>customer</name>
<description>Demo project for Spring Boot</description> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients; @EnableDiscoveryClient
@SpringBootApplication
@EnableFeignClients
public class CustomerApplication { public static void main(String[] args) {
SpringApplication.run(CustomerApplication.class, args);
} }
业务代码为:
@Component
public class helloHystrix implements service {
@Override
public String hello() {
return null;
}
}
@FeignClient(value = "${service.request.name}", fallback = helloHystrix.class)
public interface service extends BaseService {
@RequestMapping(method = RequestMethod.GET, value = path + "/home/hello")
String hello();
}
@RestController
@RequestMapping("/home")
public class homeController {
@Autowired
private service service; @RequestMapping(value = "/hello", method = RequestMethod.GET)
public String hello()
{
String x = service.hello();
return "返回:"+x;
}
}
eureka:
client:
serviceUrl:
defaultZone: http://admin:123456@localhost:8888/eureka/
server:
port: 8002
spring:
application:
name: customer
zipkin:
base-url: http://localhost:9411
sleuth:
sampler:
percentage: 1.0
service:
request:
name: USER-SERVICE
5.运行及结果
全部完成后,启动4个项目,在8888端口查看3个项目的启动情况,之后打开9411端口,查看追踪页面,报如下错误:
This application has no explicit mapping for /error, so you are seeing this as a fallback. Sun Sep 15 22:19:00 CST 2019
There was an unexpected error (type=Internal Server Error, status=500).
Prometheus requires that all meters with the same name have the same set of tag keys. There is already an existing meter containing tag keys [method, status, uri]. The meter you are attempting to register has keys [exception, method, status, uri].
经过查询,发现是zipkinserver项目缺失配置所致,在配置文件中添加配置即可:
management:
metrics:
web:
server:
auto-time-requests: false
重启后,查看结果,一切正常。
、
使用zipkin2在SpringCloud2.0环境下追踪服务调用情况的更多相关文章
- [VS2015].NET4.0环境下使用.NET2.0程序集,使用sqlite时报异常 出现“混合模式程序集异常”
在.net 4.0环境下使用sqlite时报异常 混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集其调用的方法是从sqli ...
- VB6.0环境下的CATIA二次开发简介
CATIA作为CAD/CAE/CAM/PDM一体化的软件,广泛用于航空航天.汽车.船舶及电子工业,尤其在航空航天业,有八成以上厂商使用CATIA的市场[11].然而由于使用习惯和使用的侧重点不用,功能 ...
- Windows-Server-2008、IIS7.0环境下配置伪静态化
在Windows-Server-2008.IIS7.0环境下配置伪静态化 首先,是IIS7.0的配置,由于Windows Server 2008操作系统默认的IIS版本为 ...
- Window环境下,PHP调用Python脚本
参考 php调用python脚本*** php 调用 python脚本的方法 解决办法:php提供了许多调用其他脚本或程序的方法,比如exec/system/popen/proc_open/passt ...
- 微服务架构 | 10.1 使用 Sleuth 追踪服务调用链
目录 前言 1. Sleuth 基础知识 1.1 Sleuth 原理 2. 在服务中使用 Sleuth 追踪 2.1 引入 pom.xml 依赖文件 2.2 查看日志信息 最后 前言 参考资料: &l ...
- VC++6.0环境下调试c语言代码的方法和步骤_附图
1.C语言程序四步开发步骤 (1)编辑.可以用任何一种编辑软件将在纸上编写好的C语言程序输入计算机,并将C语言源程序文件*.c以纯文本文件形式保存在计算机的磁盘上(不能设置字体.字号等). (2)编译 ...
- 转 Visual C++6.0 与matlab联合编程(2)----Visual C++6.0 环境下编译和调试MEX文件
我的最初想法是利用matlab的mex命令调用C++程序生成动态链接库的,但是测试程序(文中另附)通过了,自己的实际应用程序却没有过.还是把方法贴在这儿,以便自己以后进行整理. http://shij ...
- 多网卡环境下Eureka服务注册IP选择问题
一.问题场景 服务器上分别配置了eth0, eth1和eth2三块网卡,只有eth1的地址可供其它机器访问,eth0和eth2的 IP 无效.在这种情况下,服务注册时Eureka Client会自动选 ...
- Linux环境下Gitblit服务搭建及秘钥配置
一.安装gitblit服务 1.下载地址 https://pan.baidu.com/s/1wQ3TEE_gw5xZvyFPZB9xFg 2.上传至linux服务器并解压缩 tar xvf gitbl ...
随机推荐
- 第十篇.5、python并发编程之协程
一 引子 本节的主题是基于单线程来实现并发,即只用一个主线程(很明显可利用的cpu只有一个)情况下实现并发,为此我们需要先回顾下并发的本质:切换+保存状态 cpu正在运行一个任务,会在两种情况下切走去 ...
- Tensorflowlite移植ARM平台iMX6
一.LINUX环境下操作: 1.安装交叉编译SDK (仅针对该型号:i.MX6,不同芯片需要对应的交叉编译SDK) 编译方法参考:手动编译用于i.MX6系列的交叉编译SDK 2.下载Tensorflo ...
- 10 Zabbix4.4.1系统告警“Zabbix server is not running”
点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 Zabbix4.4.1系统告警“Zabbix server is not running” 第一步 ...
- 未能加载文件或程序集“System.Web.Http.WebHost
http://blog.csdn.net/yuanzhugen/article/details/46625353(转)
- vsftpd 添加用户
方法/步骤 首先要添加一个新的ftp用户并添加访问路径 useradd -d /alidata/www/ace ceshi -d是用户的访问目录 为新添加的ftp用户设置密码 ...
- 在Nginx中使用Godaddy的SSL证书
首先在Godaddy付款购买SSL证书,成功之后打开管理面板,找到刚购买的SSL证书,点击新建证书,这个时候Godaddy会让提供CSR文件内容,可以通过下面的命令行生成csr内容: openssl ...
- dede 调取二级三级菜单栏目
{dede:channelartlist typeid='} <div class="cate-item"> <div class="cate-item ...
- Acwing-98-分形之城(递推,数学)
链接: https://www.acwing.com/problem/content/description/100/ 题意: 城市的规划在城市建设中是个大问题. 不幸的是,很多城市在开始建设的时候并 ...
- 前端js之JQuery
目录 jQuery介绍 jQuery的优势 jQuery内容 jQuery对象 jQuery基础语法结构 jQuery 使用注意事项 查找标签 基本选择器 层级选择器 基本选择器 属性选择器 表单筛选 ...
- robotframework 找出重复元素
思路 一.把需要进行比较的元素取出来组装成一个list 二.利用python函数,从list中找出重复函数 python函数: from collections import Counter #引入C ...