Zipkin在微服务的使用

书接上回
1、Zipkin介绍
2、AlibabaCloud + Nacos + Sentinel使用
3、AlibabaCloud + Zuul 路由转发
我们对Zipkin有了初步的了解,接下来让我们进行实战

一、Zipkin安装

1.1 docker安装

docker run -d -p 9411:9411 openzipkin/zipkin

1.2 Java运行

curl -sSL https://zipkin.io/quickstart.sh | bash -s
java -jar zipkin.jar

1.3 源码安装

# get the latest source
git clone https://github.com/openzipkin/zipkin
cd zipkin
# Build the server and also make its dependencies
./mvnw -DskipTests --also-make -pl zipkin-server clean install
# Run the server
java -jar ./zipkin-server/target/zipkin-server-*exec.jar

1.4 项目集成

通过依赖的方式安装,本次小编将使用这种方式掩饰

二、集成Zipkin-Server

这里为甚没有采用前三种呢?因为实际项目有可能需要自定义的一些操作,这样集成会更方便些!

2.1 添加依赖

        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-server</artifactId>
            <version>${zipkin.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-log4j2</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-autoconfigure-ui</artifactId>
            <version>${zipkin.version}</version>
        </dependency>

2.2 配置文件

server:
  port: 8096
spring:
  application:
    name: javayh-zipkin-server
  profiles:
    active: provider
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
        cluster-name: javayh-nacos
      config:
        group: javayh
        server-addr: 127.0.0.1:8848
        prefix: javayh-nacos-provider
        file-extension: yml
management:
  metrics:
    web:
      server:
        auto-time-requests: false        

2.3 启动类生名

@EnableZipkinServer//开启ZipkinServe

三、Zipkin集成微服务

3.1 依赖引入

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
        </dependency>

sleuth 大加也可以了解一下

3.2配置文件

server:
  port: 8090
spring:
  application:
    name: javayh-nacos-provider
  profiles:
    active: provider
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
        cluster-name: javayh-nacos
      config:
        group: javayh
        server-addr: 127.0.0.1:8848
        prefix: javayh-nacos-provider
        file-extension: yml
  zipkin:
    base-url: http://localhost:8096
      # 关闭服务发现,否则Spring Cloud会把zipkin的url当做服务名称
    discoveryClientEnabled: false
    sender:
      type: web
  sleuth:
    sampler:
      probability: 1  # 设置抽样采集率为100%,默认为0.1,即10%

本项目在 一下两篇介绍的项目进行升级改造
1、AlibabaCloud + Nacos + Sentinel使用
2、AlibabaCloud + Zuul 路由转发

以上工作准备好,我们就可以启动项目,记得启动nacos

四、验证步骤

4.1 访问zipkin

本案例的地址
http://localhost:8096/zipkin/
在这里插入图片描述

4.2 访问provider项目

http://localhost:9090/provider/find/nacos/11111
在这里插入图片描述
选择我们的服务,点击Find
其他就是页面管理的一些操作,就是通用的大加点一下就可以,
细心的朋友可能已经发现,这个记录存在哪里了?我重启项目就没了,这是不是太不友好了?这是生产岂不是更尴尬?
其实,Zipkin默认是存在内存里的,重启项目,之前的记录就全都没有了,那么该如何操作?还记在Zipkin介绍中我们说过的吗?zipkin支持Mysql和ElasticSearch存储,下篇我们将讲解Zipkin持久化MySQL中的操作

今天的分享就当这里,希望对大家有所帮助!

关注 Java有货领取更多资料

联系小编。微信:372787553,带您进群互相学习
左侧小编微信,右侧获取免费资料
在这里插入图片描述

技术博客:https://blog.csdn.net/weixin_38937840

SpringCloud学习代码: https://github.com/Dylan-haiji/javayh-cloud

Redis、Mongo、Rabbitmq、Kafka学习代码: https://github.com/Dylan-haiji/javayh-middleware

AlibabaCloud学习代码:https://github.com/Dylan-haiji/javayh-cloud-nacos

SpringBoot+SpringSecurity实现自定义登录学习代码:https://github.com/Dylan-haiji/javayh-distribution

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小杨同学~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值