日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用 docker 构建分布式调用链跟踪框架skywalking

發(fā)布時間:2023/12/4 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用 docker 构建分布式调用链跟踪框架skywalking 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一旦你的程序docker化之后,你會遇到各種問題,比如原來采用的本地記日志的方式就不再方便了,雖然你可以掛載到宿主機(jī),但你使用 --scale 的話,會導(dǎo)致記錄日志異常,所以最好的方式還是要做日志中心化,另一個問題,原來一個請求在一個進(jìn)程中的痙攣失敗,你可以在日志中巡查出調(diào)用堆棧,但是docker化之后,原來一個進(jìn)程的東西會拆成幾個微服務(wù),這時候最好就要有一個分布式的調(diào)用鏈跟蹤,類似于wcf中的svctraceview工具。

一:搭建skywalking

gihub地址是:https://github.com/apache/incubator-skywalking 從文檔中大概看的出來,大體分三個部分:存儲,收集器,探針,存儲這里就選用推薦的 elasticsearch。收集器準(zhǔn)備和es部署在一起,探針就有各自語言的實現(xiàn)了,總之這里就有三個docker container:es,kibana,skywalking, 如果不用容器編排工具的話就比較麻煩。

下面是本次搭建的一個目錄結(jié)構(gòu):

1. ?elasticsearch.yml

es的配置文件,不過這里有一個坑,就是一定要將 network.publish_host:0.0.0.0 ,否則skywalking會連不上 9300端口。

network.publish_host: 0.0.0.0 transport.tcp.port: 9300 network.host: 0.0.0.0

2. elasticsearch.dockerfile

在up的時候,將這個es文件copy到 容器的config文件夾下。

FROM?elasticsearch:5.6.4EXPOSE?9200?9300COPY?elasticsearch.yml?/usr/share/elasticsearch/config/

3. application.yml

skywalking的配置文件,這里也有一個坑:連接es的地址中,配置的 clustername一定要修改成和es的clustername保持一致,否則會連不上,這里容器之間用link進(jìn)行互聯(lián),所以es的ip改成elasticsearch就可以了,其他的ip改成0.0.0.0 。

#?Licensed?to?the?Apache?Software?Foundation?(ASF)?under?one #?or?more?contributor?license?agreements.??See?the?NOTICE?file #?distributed?with?this?work?for?additional?information #?regarding?copyright?ownership.??The?ASF?licenses?this?file #?to?you?under?the?Apache?License,?Version?2.0?(the #?"License");?you?may?not?use?this?file?except?in?compliance #?with?the?License.??You?may?obtain?a?copy?of?the?License?at # #?????http://www.apache.org/licenses/LICENSE-2.0 # #?Unless?required?by?applicable?law?or?agreed?to?in?writing,?software #?distributed?under?the?License?is?distributed?on?an?"AS?IS"?BASIS, #?WITHOUT?WARRANTIES?OR?CONDITIONS?OF?ANY?KIND,?either?express?or?implied. #?See?the?License?for?the?specific?language?governing?permissions?and #?limitations?under?the?License.#cluster: #??zookeeper: #????hostPort:?localhost:2181 #????sessionTimeout:?100000 naming:jetty:host:?0.0.0.0port:?10800contextPath:?/ cache: #??guava:caffeine: remote:gRPC:host:?0.0.0.0port:?11800 agent_gRPC:gRPC:host:?0.0.0.0port:?11800#Set?these?two?setting?to?open?ssl#sslCertChainFile:?$path#sslPrivateKeyFile:?$path#Set?your?own?token?to?active?auth#authentication:?xxxxxx agent_jetty:jetty:host:?0.0.0.0port:?12800contextPath:?/ analysis_register:default: analysis_jvm:default: analysis_segment_parser:default:bufferFilePath:?../buffer/bufferOffsetMaxFileSize:?10MbufferSegmentMaxFileSize:?500MbufferFileCleanWhenRestart:?true ui:jetty:host:?0.0.0.0port:?12800contextPath:?/ storage:elasticsearch:clusterName:?elasticsearchclusterTransportSniffer:?trueclusterNodes:?elasticsearch:9300indexShardsNumber:?2indexReplicasNumber:?0highPerformanceMode:?truettl:?7 #storage: #??h2: #????url:?jdbc:h2:~/memorydb #????userName:?sa configuration:default: #?????namespace:?xxxxx #?alarm?thresholdapplicationApdexThreshold:?2000serviceErrorRateThreshold:?10.00serviceAverageResponseTimeThreshold:?2000instanceErrorRateThreshold:?10.00instanceAverageResponseTimeThreshold:?2000applicationErrorRateThreshold:?10.00applicationAverageResponseTimeThreshold:?2000 #?thermodynamicthermodynamicResponseTimeStep:?50thermodynamicCountOfResponseTimeSteps:?40

4. ?skywalking.dockerfile

接下來就是 skywalking的 下載安裝,使用dockerfile流程化。

FROM?centos:7LABEL?username="hxc@qq.com"WORKDIR?/appRUN?yum?install?-y?wget?&&?\yum?install?-y?java-1.8.0-openjdkADD?http://mirrors.hust.edu.cn/apache/incubator/skywalking/5.0.0-RC2/apache-skywalking-apm-incubating-5.0.0-RC2.tar.gz?/appRUN?tar?-xf?apache-skywalking-apm-incubating-5.0.0-RC2.tar.gz?&&?\mv?apache-skywalking-apm-incubating?skywalkingRUN?ls?/app#copy文件 COPY?application.yml?/app/skywalking/config/application.ymlWORKDIR?/app/skywalking/binUSER?rootRUN??echo?"tail?-f?/dev/null"?>>?/app/skywalking/bin/startup.shCMD?["/bin/sh","-c","/app/skywalking/bin/startup.sh"?]

5. docker-compose.yml

最后就是將這三個容器進(jìn)行編排,要注意的是,因為收集器會將數(shù)據(jù)放入到es中,所有一定要將es的data掛載到宿主機(jī)的大硬盤下,否則你的空間會不足的。

version:?'3.1'services:#elastic?鏡像elasticsearch:build:context:?.dockerfile:?elasticsearch.dockerfile#?ports:#???-?"9200:9200"#???-?"9300:9300"volumes:-?"/data/es2:/usr/share/elasticsearch/data"#kibana?可視化查詢,暴露?5601kibana:image:?kibanalinks:-?elasticsearchports:-?5601:5601depends_on:-?"elasticsearch"#skywalkingskywalking:build:context:?.dockerfile:?skywalking.dockerfileports:-?"10800:10800"-?"11800:11800"-?"12800:12800"-?"8080:8080"links:-?elasticsearchdepends_on:-?"elasticsearch"

二:一鍵部署

要部署在docker中,你還得需要安裝docker-ce 和 docker-compose,大家可以參照官方安裝一下。

1. Docker-ce 的安裝

sudo?yum?remove?docker?\ docker-client?\ docker-client-latest?\ docker-common?\ docker-latest?\ docker-latest-logrotate?\ docker-logrotate?\ docker-selinux?\ docker-engine-selinux?\ docker-enginesudo?yum?install?-y?yum-utils?\ device-mapper-persistent-data?\ lvm2sudo?yum-config-manager?\ --add-repo?\ https://download.docker.com/linux/centos/docker-ce.reposudo?yum?install?docker-ce

然后啟動一下docker 服務(wù),可以看到版本是18.06.1

[root@localhost?~]#?service?docker?start Redirecting?to?/bin/systemctl?start??docker.service [root@localhost?~]#?docker?-v Docker?version?18.06.1-ce,?build?e68fc7a

2. docker-compose的安裝

sudo?curl?-L?"https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname?-s)-$(uname?-m)"?-o?/usr/local/bin/docker-composesudo?chmod?+x?/usr/local/bin/docker-compose

3. ?最后在centos上執(zhí)行 docker-compopse up --build 就可以了,如果不想terminal上運行,可以加 -d 使用后臺執(zhí)行。

[root@localhost?docker]#?docker-compose?up?--build Creating?network?"docker_default"?with?the?default?driver Building?elasticsearch Step?1/3?:?FROM?elasticsearch:5.6.4--->?7a047c21aa48 Step?2/3?:?EXPOSE?9200?9300--->?Using?cache--->?8d66bb57b09d Step?3/3?:?COPY?elasticsearch.yml?/usr/share/elasticsearch/config/--->?Using?cache--->?02b516c03b95 Successfully?built?02b516c03b95 Successfully?tagged?docker_elasticsearch:latest Building?skywalking Step?1/12?:?FROM?centos:7--->?5182e96772bf Step?2/12?:?LABEL?username="hxc@qq.com"--->?Using?cache--->?b95b96a92042 Step?3/12?:?WORKDIR?/app--->?Using?cache--->?afdf4efe3426 Step?4/12?:?RUN?yum?install?-y?wget?&&?????yum?install?-y?java-1.8.0-openjdk--->?Using?cache--->?46be0ca0f7b5 Step?5/12?:?ADD?http://mirrors.hust.edu.cn/apache/incubator/skywalking/5.0.0-RC2/apache-skywalking-apm-incubating-5.0.0-RC2.tar.gz?/app--->?Using?cache--->?d5c30bcfd5ea Step?6/12?:?RUN?tar?-xf?apache-skywalking-apm-incubating-5.0.0-RC2.tar.gz?&&?????mv?apache-skywalking-apm-incubating?skywalking--->?Using?cache--->?1438d08d18fa Step?7/12?:?RUN?ls?/app--->?Using?cache--->?b594124672ea Step?8/12?:?COPY?application.yml?/app/skywalking/config/application.yml--->?Using?cache--->?10eaf0805a65 Step?9/12?:?WORKDIR?/app/skywalking/bin--->?Using?cache--->?bc0f02291536 Step?10/12?:?USER?root--->?Using?cache--->?4498afca5fe6 Step?11/12?:?RUN??echo?"tail?-f?/dev/null"?>>?/app/skywalking/bin/startup.sh--->?Using?cache--->?1c4be7c6b32a Step?12/12?:?CMD?["/bin/sh","-c","/app/skywalking/bin/startup.sh"?]--->?Using?cache--->?ecfc97e4c97d Successfully?built?ecfc97e4c97d Successfully?tagged?docker_skywalking:latest Creating?docker_elasticsearch_1?...?done Creating?docker_skywalking_1????...?done Creating?docker_kibana_1????????...?done Attaching?to?docker_elasticsearch_1,?docker_kibana_1,?docker_skywalking_1 elasticsearch_1??|?[2018-09-17T23:51:57,886][INFO?][o.e.c.m.MetaDataCreateIndexService]?[FC_bOh1]?[service_metric_day]?creating?index,?cause?[api],?templates?[],?shards?[2]/[0],?mappings?[type] elasticsearch_1??|?[2018-09-17T23:51:57,962][INFO?][o.e.c.r.a.AllocationService]?[FC_bOh1]?Cluster?health?status?changed?from?[YELLOW]?to?[GREEN]?(reason:?[shards?started?[[service_metric_day][0]]?...]). elasticsearch_1??|?[2018-09-17T23:51:58,115][INFO?][o.e.c.m.MetaDataCreateIndexService]?[FC_bOh1]?[application_metric_hour]?creating?index,?cause?[api],?templates?[],?shards?[2]/[0],?mappings?[type] elasticsearch_1??|?[2018-09-17T23:51:58,176][INFO?][o.e.c.r.a.AllocationService]?[FC_bOh1]?Cluster?health?status?changed?from?[YELLOW]?to?[GREEN]?(reason:?[shards?started?[[application_metric_hour][1]]?...]). elasticsearch_1??|?[2018-09-17T23:51:58,356][INFO?][o.e.c.m.MetaDataCreateIndexService]?[FC_bOh1]?[application_metric_month]?creating?index,?cause?[api],?templates?[],?shards?[2]/[0],?mappings?[type] elasticsearch_1??|?[2018-09-17T23:51:58,437][INFO?][o.e.c.r.a.AllocationService]?[FC_bOh1]?Cluster?health?status?changed?from?[YELLOW]?to?[GREEN]?(reason:?[shards?started?[[application_metric_month][0]]?...]). elasticsearch_1??|?[2018-09-17T23:51:58,550][INFO?][o.e.c.m.MetaDataCreateIndexService]?[FC_bOh1]?[instance_mapping_month]?creating?index,?cause?[api],?templates?[],?shards?[2]/[0],?mappings?[type] elasticsearch_1??|?[2018-09-17T23:52:05,544][INFO?][o.e.c.m.MetaDataCreateIndexService]?[FC_bOh1]?[gc_metric_minute]?creating?index,?cause?[api],?templates?[],?shards?[2]/[0],?mappings?[type]

從上圖中可以看到 es,kibana,skywalking都啟動成功了,你也可以通過docker-compose ps 看一下是否都起來了,netstat 看一下宿主機(jī)開放了哪些端口。

[root@localhost?docker]#?docker?ps CONTAINER?ID????????IMAGE??????????????????COMMAND??????????????????CREATED?????????????STATUS??????????????PORTS??????????????????????????????????????????????????????????????????????????????????????????????????NAMES 9aa90401ca16????????kibana?????????????????"/docker-entrypoint.…"???2?minutes?ago???????Up?2?minutes????????0.0.0.0:5601->5601/tcp?????????????????????????????????????????????????????????????????????????????????docker_kibana_1 c551248e32af????????docker_skywalking??????"/bin/sh?-c?/app/sky…"???2?minutes?ago???????Up?2?minutes????????0.0.0.0:8080->8080/tcp,?0.0.0.0:10800->10800/tcp,?0.0.0.0:11800->11800/tcp,?0.0.0.0:12800->12800/tcp???docker_skywalking_1 765d38469ff1????????docker_elasticsearch???"/docker-entrypoint.…"???2?minutes?ago???????Up?2?minutes????????9200/tcp,?9300/tcp?????????????????????????????????????????????????????????????????????????????????????docker_elasticsearch_1 [root@localhost?docker]#?netstat?-tlnp Active?Internet?connections?(only?servers) Proto?Recv-Q?Send-Q?Local?Address???????????Foreign?Address?????????State???????PID/Program?name???? tcp????????0??????0?192.168.122.1:53????????0.0.0.0:*???????????????LISTEN??????2013/dnsmasq???????? tcp????????0??????0?0.0.0.0:22??????????????0.0.0.0:*???????????????LISTEN??????1141/sshd??????????? tcp????????0??????0?127.0.0.1:631???????????0.0.0.0:*???????????????LISTEN??????1139/cupsd?????????? tcp????????0??????0?127.0.0.1:25????????????0.0.0.0:*???????????????LISTEN??????1622/master????????? tcp6???????0??????0?:::8080?????????????????:::*????????????????????LISTEN??????38262/docker-proxy?? tcp6???????0??????0?:::10800????????????????:::*????????????????????LISTEN??????38248/docker-proxy?? tcp6???????0??????0?:::22???????????????????:::*????????????????????LISTEN??????1141/sshd??????????? tcp6???????0??????0?::1:631?????????????????:::*????????????????????LISTEN??????1139/cupsd?????????? tcp6???????0??????0?:::11800????????????????:::*????????????????????LISTEN??????38234/docker-proxy?? tcp6???????0??????0?::1:25??????????????????:::*????????????????????LISTEN??????1622/master????????? tcp6???????0??????0?:::12800????????????????:::*????????????????????LISTEN??????38222/docker-proxy?? tcp6???????0??????0?:::5601?????????????????:::*????????????????????LISTEN??????38274/docker-proxy?? [root@localhost?docker]#

然后就可以看一些8080端口的可視化UI,默認(rèn)用戶名密碼admin,admin,一個比較耐看的UI就出來了。

三:net下的探針

從nuget上拉取一個SkyWalking.AspNetCore探針進(jìn)行代碼埋點,github地址:https://github.com/OpenSkywalking/skywalking-netcore

在startup類中進(jìn)行注入,在頁面請求中進(jìn)行一次cnblogs.com的請求操作,然后仔細(xì)觀察一下調(diào)用鏈跟蹤是一個什么樣子?

namespace?WebApplication1 {public?class?Startup{//?This?method?gets?called?by?the?runtime.?Use?this?method?to?add?services?to?the?container.//?For?more?information?on?how?to?configure?your?application,?visit?https://go.microsoft.com/fwlink/?LinkID=398940public?void?ConfigureServices(IServiceCollection?services){services.AddSkyWalking(option?=>{//?Application?code?is?showed?in?sky-walking-uioption.ApplicationCode?=?"10001?測試站點";//Collector?agent_gRPC/grpc?service?addresses.option.DirectServers?=?"192.168.23.183:11800";});}//?This?method?gets?called?by?the?runtime.?Use?this?method?to?configure?the?HTTP?request?pipeline.public?void?Configure(IApplicationBuilder?app,?IHostingEnvironment?env){if?(env.IsDevelopment()){app.UseDeveloperExceptionPage();}app.Run(async?(context)?=>{WebClient?client?=?new?WebClient();var?str?=?client.DownloadString("http://cnblogs.com");await?context.Response.WriteAsync(str);});}} }

可以看到這張圖還是蠻漂亮的哈,也方便我們快速的跟蹤代碼,發(fā)現(xiàn)問題,找出問題, 還有更多的功能期待你的挖掘啦。好了,本篇就說到這里,希望對你有幫助。

總結(jié)

以上是生活随笔為你收集整理的使用 docker 构建分布式调用链跟踪框架skywalking的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。