使用 springboot2.x
Zipkin服务端
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.0</modelVersion>
<groupId>com.zipkin</groupId>
<artifactId>zipkin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<!--zipkin-->
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-storage-elasticsearch-http</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-collector-rabbitmq</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.0.4.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.4.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
application.yml配置文件信息
spring:
sleuth:
enabled: false
application:
name: zipkin-server
security: #密码认证
basic:
enabled: true
user:
name: sleuth-zipkin
password: 123456
profiles:
active: local
server:
port: 10000
register:
port: 10000
#访问服务注册中心管理页面需要加密码
register-visite-name: eureka
register-visite-passwd: 123456
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
metrics:
web:
server:
auto-time-requests: false
active 本地信息 application-local.yml
zipkin:
storage:
elasticsearch:
cluster: elasticsearch-zipkin-cluster
max-requests: 64
index-replicas: 1
hosts: 192.168.19.7:9200
index: zipkin
index-shards: 5
StorageComponent: elasticsearch
type: elasticsearch
collector:
rabbitmq:
addresses: 192.168.19.7:5672
password: guest
username: guest
queue: zipkin
eureka:
instance:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ipaddress}:${server.port}
client:
service-url:
defaultZone: http://${register-visite-name}:${register-visite-passwd}@localhost:${register.port}/eureka/
registry-fetch-interval-seconds: 3 #获取服务的刷新时间
启动文件 ZipkinApplication.java
package com.zipkin;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import zipkin2.server.internal.EnableZipkinServer;
@SpringBootApplication
@EnableDiscoveryClient
@EnableZipkinServer
public class ZipkinApplication {
public static void main(String[] args) {
SpringApplication.run(ZipkinApplication.class,args);
}
}
认证文件
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// For example: Use only Http Basic and not form login.
http.authorizeRequests()
.anyRequest().authenticated()
.and()
.httpBasic();
}
}
服务端配置
pom 添加依赖项 .因为其他项目还是使用 springboot1.x版本 ,因此zipkin版本用的 1.3.3.RELEASE ,rabbit 用的1.73.RELEASE
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
</dependency>
客户端配置文件 加入rabbitmq配置 及 zipkin接收的rabbitmq 队列
spring:
rabbitmq:
addresses: 192.168.19.7
port: 5672
username: guest
password: guest
zipkin:
rabbitmq:
queue: zipkin
git 项目下载地址 https://github.com/yanzuoyu/zipkin.git