javascript
Spring cloud(Finchley)微服务框架,sleuth整合zipkin链路追踪失效的问题
一、首先說問題:
- 1、springCloud在使用鏈路追蹤組件sleuth整合zipkin的過程中鏈路追蹤信息切都是正常;
- 2、微服務太多需要使用組件Config對每個微服務的的配置文件進行統一管理;
- 3、config對微服務進行管理,但是如果某一個配置發生改變,如果每個微服務都要重啟才能獲取最新的配置文件就不合理,那么springCloud提供了spring cloud Bus組件來刷新配置,使用消息中間件(官方推薦RabbitMQ)不需要重啟微服務就可以獲取最新配置。
- 4、當spring cloud Bus 配置完成之后zipkin完全收集不到鏈路追蹤信息了。。。
二、尋找解決方案
最開始遇到這個問題時,認為是自己配置在哪里有問題,反復確認沒有問題。然后開始狂論壇,問大牛。得到的答案是springcloud不成熟,可能存在bug,既然有bug(我也不知道該怎么解決),但是如果鏈路追蹤不能使用,對整個微服務的調用依賴,每個微服務的調用請求耗時就沒有辦法定位,對后期的維護是不利的。只能放棄分布式配置,但是也不好,如果修改了一個配置文件,每個微服務都要重啟,對于后期的維護也是不利的。只能繼續尋找解決方案。
三、問題分析
- 1、出現這個問題,首先想到的是要去官方文檔上尋找答案;丟一個springcloud文檔:springcloud Finchley SR2。
- 2、使用springcloud Bus需要使用rabbitMQ,但是zipkin收集信息是http(文檔)
同時zipkin也支持使用RabbitMQ來收集鏈路信息,猜想是不是在配置中使用了RabbitMQ收集,而HTTP的方式失效了,那么就有兩個解決方案:其中一就是只是用HTTP的方式,不是用RabbitMQ;二:就是將zipkin收集鏈路信息的方式修改為RabbitMQ。方式一簡單有效,但是沒有找到相應的配置,那么就使用方案二,在官方文檔中也有描述將zipkin的獲取方式修改為rabbitMq或者kafka:
If you want to use RabbitMQ or Kafka instead of HTTP, add the spring-rabbit or spring-kafka dependency. The default destination name is zipkin.If using Kafka, you must set the property spring.zipkin.sender.type property accordingly:spring.zipkin.sender.type: kafka [Caution] Caution spring-cloud-sleuth-stream is deprecated and incompatible with these destinations.If you want Sleuth over RabbitMQ, add the spring-cloud-starter-zipkin and spring-rabbit dependencies.The following example shows how to do so for Gradle:Maven. <dependencyManagement> 1<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${release.train.version}</version><type>pom</type><scope>import</scope></dependency></dependencies> </dependencyManagement><dependency> 2<groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-zipkin</artifactId> </dependency> <dependency> 3<groupId>org.springframework.amqp</groupId><artifactId>spring-rabbit</artifactId> </dependency> 1、We recommend that you add the dependency management through the Spring BOM so that you need not manage versions yourself.2、Add the dependency to spring-cloud-starter-zipkin. That way, all nested dependencies get downloaded.3、To automatically configure RabbitMQ, add the spring-rabbit dependency.通過官方文檔的說明按照上述的三個步驟就能實現,但是按照上述的步驟依舊是沒有追蹤到鏈路信息。
上述的配置說明微服務的客戶端應該是沒有問題的,那么問題可能出現在zipkin服務器上。
四、zipkin服務器的問題
從spring boot 2.0開始官方就官方不再支持使用自建Zipkin Server的方式進行服務鏈路追蹤,而是直接提供了編譯好的 jar 包來給我們使用。
但是從1.0時代的配置中應該是可以看出問題,在1.0的Zipkin Service中需要加入sleuth和rabbit的依賴,同時需要配置rabbitMQ消息的地址,但是使用jar包直接啟動,并沒有指定rabbit的地址。
查詢spring-cloud-sleuth在github上的源碼,在源碼中會有一些人遇到一些問題,會不會有同樣的問題,解決方案。其中有一個問題:
有一個回答:
I also have the same problem and the workaround provided in Gitter has helped me to solve it until the permanent solution is in place. For the benefit of others here is the workaround.Explicitly configure spring.rabbitmq.addresses property to point to the credentials of the bounded RabbitMQ service. For example, if the bounded service is called rabbitmq the following configuration will work:spring.rabbitmq.addresses=${vcap.services.rabbitmq.credentials.uri}也就是說在啟動zipkin的時候指定一下rabbitMq的地址。問題
五、解決方案
1、在需要收集鏈路追蹤的客戶端添加依賴:
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-zipkin</artifactId></dependency><dependency><groupId>org.springframework.amqp</groupId><artifactId>spring-rabbit</artifactId></dependency>2、下載zipk的jar包這里使用了zipkin-server-2.11.1-exec
在啟動zipkin的之后設置參數
或者使用docker
添加參數
在docker啟動后還是有問題,最后發現是localhost的問題,將localhost修改成rabbit對應的服務器IP地址就好了。
啟動之后在RabbitMq中會出現一個zipkin的隊列。
另一種方式,使用http就比較簡單,在項目中加入
zipkin:base-url: http://ip:9411# 使用http的方式收集鏈路追蹤信息,默認是使用rabbitMQ,這樣在使用了spring cloud Bus之后鏈路追蹤就不會失效了sender:type: web但是推薦使用rabbit。
最后在zipkin的頁面上就可以看到鏈路追蹤的信息了
總結
以上是生活随笔為你收集整理的Spring cloud(Finchley)微服务框架,sleuth整合zipkin链路追踪失效的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 会员钻是什么
- 下一篇: Android 蓝牙4.0(BLE)开发