书接上回
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