Jaeger系統(tǒng)實現(xiàn)對Harbor的鏈路追蹤
前言
1.1 Harbor新功能-分布式跟蹤
Harbor在2.4.0版本后新增一個功能:向 Harbor 添加跟蹤功能,以增強故障排除、識別性能瓶頸等。目前Harbor支持Jaeger和OpenTelemetry(簡稱otel)兩種實現(xiàn)方式。
1.2 Jaeger簡單介紹
Jaeger 是一個開源的分布式追蹤系統(tǒng),它可以在復(fù)雜的分布式系統(tǒng)中進(jìn)行監(jiān)控和故障排查。Jaeger的主要功能包括分布式請求監(jiān)控、性能調(diào)優(yōu)、故障分析和服務(wù)依賴分析等。
本處并不會詳細(xì)介紹Jaeger,僅簡單部署Jaeger來實現(xiàn)對Harbor的分布式追蹤功能而做的Demo。如果是在生產(chǎn)環(huán)境,也可以參考本文,因為Harbor中關(guān)于Jaeger的配置都是類似的。
1.3 要求
- Harbor版本必須在2.4.0?及以上,本處為2.5.3;
- Jaeger版本必須為1.26?或更高版本,本處為1.35;
- 本處將Jaeger部署在Harbor服務(wù)主機上(地址為192.168.2.250);
部署Jaeger服務(wù)
本處采用Jaeger all-in-one單節(jié)點部署。其包含了3個Jaeger組件:
- agent
- collector
- query service/UI
這種方式是將數(shù)據(jù)直接存儲在內(nèi)存中,無需額外部署存儲組件,不建議在生產(chǎn)環(huán)境使用該方式進(jìn)行部署。
2.1 Docker部署Jaeger
是將數(shù)據(jù)存儲在內(nèi)存中,僅用于測試。需要注意16686等端口沒有被占用。
不同版本的Jaeger部署參數(shù)略有區(qū)別,其它版本可查看:https://www.jaegertracing.io/docs/
$ docker pull jaegertracing/all-in-one:1.35
$ docker run -d --name jaeger \
-e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
-p 5775:5775/udp \
-p 6831:6831/udp \
-p 6832:6832/udp \
-p 5778:5778 \
-p 16686:16686 \
-p 14250:14250 \
-p 14268:14268 \
-p 14269:14269 \
-p 9411:9411 \
jaegertracing/all-in-one:1.35
$ docker ps -a | grep jaeger
$ ss -ntulp | grep 16686
2.2 瀏覽器登錄Jaeger UI
然后在瀏覽器通過http://localhost:16686或者h(yuǎn)ttp://192.168.2.250:16686來訪問 Jaeger UI。
Harbor配置
因為剛才部署的Jaeger采用的是all-in-one的方式,已經(jīng)包含了jaeger-agent服務(wù)了,我們在Harbor的配置文件中啟用Jaeger功能并指定Jaeger-Agent的地址即可。
3.1 停止Harbor服務(wù)
$ cd /app/harbor/
$ docker-compose down
3.2 修改Harbor配置
在Harbor的配置文件中啟用Jaeger的分布式追蹤功能。
$ vim harbor.yml
# Trace相關(guān)配置
#同時只能啟用一個跟蹤提供程序(jaeger或otel),
#當(dāng)使用jaeger作為提供程序時,只能在代理模式或收集器模式下啟用它.
#如果使用jaeger收集器模式,則取消對endpoint的注釋,并根據(jù)需要取消對用戶名和密碼的注釋
#如果使用jaeger agetn模式,請取消注釋agent_host和agent_port
trace:
enabled: true
sample_rate: 1
# # namespace:
# attributes:
# # application: harbor
# # # jaeger應(yīng)為1.26或更高版本.
jaeger:
# endpoint: http://192.168.2.250:14268/api/traces
# # username:
# # password:
agent_host: 192.168.2.250
# # # export trace data by jaeger.thrift in compact mode
agent_port: 6831
# # otel:
# # endpoint: hostname:4318
# # url_path: /v1/traces
# # compression: false
# # insecure: true
# # timeout: 10s
sample_rate: 如果要對100%的跟蹤數(shù)據(jù)進(jìn)行采樣,請將sample_rate設(shè)置為1;如果要采樣50%的跟蹤數(shù)據(jù),請設(shè)置0.5,依此類推;
namespace: 命名空間用于區(qū)分不同Harbor服務(wù),如果你需要對多個Harbor服務(wù)進(jìn)行分布式追蹤的話建議啟用該配置;
attributes:attributes是一個鍵值對,dict包含用于初始化跟蹤提供程序的用戶定義屬性;
本處采用的是Jaeger-agent的方式,其它的配置參數(shù)請注釋掉,同時注意yaml格式對齊。
3.3 配置注入
每次修改harbor的配置文件,都需要執(zhí)行./prepare才可以使修改的配置生效。
$ ./prepare
3.4 Install安裝Harbor
執(zhí)行./install.sh重新安裝并啟動Harbor
$ ./install.sh -h
Note: Please set hostname and other necessary attributes in harbor.yml first. DO NOT use localhost or 127.0.0.1 for hostname, because Harbor needs to be accessed by external clients.
Please set --with-notary if needs enable Notary in Harbor, and set ui_url_protocol/ssl_cert/ssl_cert_key in harbor.yml bacause notary must run under https.
Please set --with-trivy if needs enable Trivy in Harbor
Please set --with-chartmuseum if needs enable Chartmuseum in Harbor
$ ./install.sh --with-trivy --with-chartmuseum
$ docker-compose ps #查看Harbor服務(wù)各個組件是否正常
Jaeger獲取Harbor追蹤信息
在部署Jaeger服務(wù)和配置Harbor服務(wù)后,可以在Jaeger的UI界面查看Harbor的追蹤信息。
在Search-Service處可以看到Jaeger已經(jīng)采集到Harbor的監(jiān)控數(shù)據(jù)了,
然后在【System Architecture】的DAG查看Harbor的鏈路追蹤圖了: