课程名称:Spring Cloud / Alibaba 微服务架构实战
课程章节:第8章-搭建 Zipkin Server 实现对跟踪信息的收集
课程讲师:张勤一
课程内容:
1. 搭建 Zipkin Server
下载安装jar包
官方地址:https://zipkin.io/pages/quickstart
curl -sSL https://zipkin.io/quickstart.sh | bash -s
//临时启动
java -jar zipkin.jar
//守护进程启动
nohup java -jar zipkin.jar &
登录查看:http://ip:9411/zipkin/
注意开放端口,否则无法访问。
配置Zipkin Server
- 默认情况下,Zipkin Server将跟踪信息存储在内存中(JVM),重启后就会丢失。
- Zipkin Server 默认采用的是HTTP方式跟踪数据,性能较差。
2.1 Zipkin Server 配置MySQL跟踪数据持久化。
-
下载sql文件,创建数据库,执行SQL文件
https://github.com/openzipkin/zipkin/blob/master/zipkin-storage/mysql-v1/src/main/resources/mysql.sql
-
启动
java -jar zipkin.jar --STORAGE_TYPE=mysql --MYSQL_HOST=127.0.0.1 --MYSQL_TCP_PORT=3306 --MYSQL_USER=root --MYSQL_PASS=xxxxx --MYSQL_DB=imooc_zipkin
启动报错,请先关闭之前启动的zipkin
netstat -lnp|grep 9411 //查看进程编号
kill -9 123456 //根据编号停用进程
2 SpringCloud Sleuth 整合 Zipkin 实现分布式链路跟踪、收集
- 利用Kafka作为跟踪数据的通信工具
//启动kakfa内置的zk
bin/zookeeper-server-start.sh config/zookeeper.properties
//启动kafak
bin/kafka-server-start.sh config/server.properties
//重启zipkin
java -DKAFKA_BOOTSTRAP_SERVERS=127.0.0.1:9092 -jar zipkin.jar --STOARGE_TYPE=mysql --MYSQL_HOST=127.0.0.1:3306 --MYSQL_USER=root --MYSQL_PASS=xxxx --MYSQL_DB=imooc_zipkin
- 添加pom依赖
<!--spring-cloud-starter-zipkin = spring-cloud-starter-sleuth + spring-cloud-sleuth-zipkin-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>2.5.0.RELEASE</version>
</dependency>
- springboot启动报关与kafka的错误信息
Connection to node 0 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
//修改kafka中server.properties的如下信息
############################# Socket Server Settings #############################
# The address the socket server listens on. It will get the value returned from
# java.net.InetAddress.getCanonicalHostName() if not configured.
# FORMAT:
# listeners = listener_name://host_name:port
# EXAMPLE:
# listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://0.0.0.0:9092
# Hostname and port the broker will advertise to producers and consumers. If not set,
# it uses the value for "listeners" if configured. Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
advertised.listeners=PLAINTEXT://公网ip:9092
按顺序重启所有服务,zk-kafka-zipkin