zipkin学习--08--Springboot 集成 Zipkin--持久化到elasticsearch

zipkin学习–08–Springboot 集成 Zipkin–持久化到elasticsearch


一、问题

生产过程中链路跟踪数据量非常的大,mysql存储并不是很好的选择,我们可以采用elasticsearch进行存储。

二、总体结构

zipkin学习--08--Springboot 集成 Zipkin--持久化到elasticsearch_第1张图片

由于虚拟机IP变更,需将zipkin-demo02-client8081 和 zipkin-demo02-client8082 的spring.rabbitmq.host 配置IP改为 192.168.1.105 其他不变

2.1、环境安装

mkdir -p /mydata/elasticsearch/config
mkdir -p /mydata/elasticsearch/data

echo "http.host: 0.0.0.0" >> /mydata/elasticsearch/config/elasticsearch.yml
# 加入跨域配置
echo "http.cors.enabled: true" >> /mydata/elasticsearch/config/elasticsearch.yml
echo 'http.cors.allow-origin: "*"' >> /mydata/elasticsearch/config/elasticsearch.yml


docker run --name elasticsearch -p 9200:9200 -p 9300:9300  -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx128m" -v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml   -d elasticsearch:5.6.16

在这里插入图片描述

2.2、安装ElasticSearch-Head管理界面进行查看ElasticSearch相关信息

# 拉取镜像
docker pull mobz/elasticsearch-head:5
# 运行容器
docker run -d --name es_admin -p 9100:9100 mobz/elasticsearch-head:5

zipkin学习--08--Springboot 集成 Zipkin--持久化到elasticsearch_第2张图片

zipkin学习--08--Springboot 集成 Zipkin--持久化到elasticsearch_第3张图片

三、zipkin 服务器修改(zipkin-demo01-es-server9411)

3.1、pom.xml依赖



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        1.5.8.RELEASE
         
    
    com.example
    zipkin-demo01-es-server9411
    0.0.1-SNAPSHOT
    zipkin-demo01-es-server9411

    
        1.8
        UTF-8
        UTF-8
        Camden.SR6
    

    
        
        
        
        
        

        
            io.zipkin.java
            zipkin-autoconfigure-ui
        
        
        
            org.springframework.cloud
            spring-cloud-sleuth-zipkin-stream
        
        
            org.springframework.cloud
            spring-cloud-starter-stream-rabbit
        
        
        
        
        
        
        
        
        
        

        
        
            io.zipkin.java
            zipkin-autoconfigure-storage-elasticsearch-http
            1.24.0
            true
        

    


    
    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    


3.2、application.properties配置

server.port=9411
spring.application.name=zipkin-demo01-server9411


#连接rabbitmq服务器配置
spring.rabbitmq.host=192.168.1.105
spring.rabbitmq.port=5672
spring.rabbitmq.username=admin
spring.rabbitmq.password=123456


#------------zipkin数据保存到elasticsearch配置-----开始-------

#表示当前程序不使用sleuth
spring.sleuth.enabled=false
#表示zipkin数据存储方式是elasticsearch
zipkin.storage.StorageComponent = elasticsearch
zipkin.storage.type=elasticsearch
zipkin.storage.elasticsearch.cluster=elasticsearch-zipkin-cluster
zipkin.storage.elasticsearch.hosts=192.168.1.105:9300
# zipkin.storage.elasticsearch.pipeline=
zipkin.storage.elasticsearch.max-requests=64
zipkin.storage.elasticsearch.index=zipkin
zipkin.storage.elasticsearch.index-shards=5
zipkin.storage.elasticsearch.index-replicas=1

#------------zipkin数据保存到elasticsearch配置-----结束-------

3.3、ZipkinDemo01EsServer9411Application

package com.example.zipkindemo01esserver9411;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.sleuth.zipkin.stream.EnableZipkinStreamServer;

@EnableZipkinStreamServer
@SpringBootApplication
public class ZipkinDemo01EsServer9411Application {

    public static void main(String[] args) {
        SpringApplication.run(ZipkinDemo01EsServer9411Application.class, args);
    }

}

四、测试

zipkin学习--08--Springboot 集成 Zipkin--持久化到elasticsearch_第4张图片

你可能感兴趣的:(zipkin,elasticsearch,rabbitmq)