zipkin安装
下载zipkin:curl -sSL https://zipkin.io/quickstart.sh | bash -s
或者 wget -O zipkin.jar ‘https://search.maven.org/remote_content?g=io.zipkin.java&a=zipkin-server&v=LATEST&c=exec’
启动: java -jar zipkin.jar 默认使用内存存储模式
或者 java -jar zipkin.jar --STORAGE_TYPE=elasticsearch --DES_HOSTS=http://localhost:9200 指定elasticsearch做为数据存储
elasticsearch安装
参考 https://www.jianshu.com/p/85576c56700e
下载安装的压缩包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.3.tar.gz
解压安装包
tar -xvf elasticsearch-6.5.3.tar.gz
修改conf下面的elasticsearch.yml
cluster.name: elasticsearch
node.name: master
path.data: /usr/local/elasticsearch-6.5.3/data
path.logs: /usr/local/elasticsearch-6.5.3/logs
network.host: 0.0.0.0
http.port: 9200
不能以root用户启动
创建elsearch用户组及elsearch用户
groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch
启动
[elsearch@localhost bin]$ ./elasticsearch
以上错误 参考 http://www.cnblogs.com/sloveling/p/elasticsearch.html
elasticsearch head安装
1.参考 https://www.cnblogs.com/liuqi/p/6483317.html 安装nodejs
2.
下载elasticsearch head代码
[root@localhost ~]# git clone https://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
执行 npm install
如果报错:npm ERR! Failed at the phantomjs-prebuilt@2.1.16 install script.
执行
[root@localhost elasticsearch-head]# npm install phantomjs-prebuilt@2.1.16 --ignore-scripts
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ phantomjs-prebuilt@2.1.16
added 62 packages from 64 contributors, removed 4 packages and audited 1717 packages in 15.187s
found 23 vulnerabilities (16 low, 1 moderate, 6 high)
run `npm audit fix` to fix them, or `npm audit` for details
启动
[root@localhost elasticsearch-head]# npm run start
> elasticsearch-head@0.0.0 start /home/zipkin/elasticsearch-head
> grunt server
>> Local Npm module "grunt-contrib-jasmine" not found. Is it installed?
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
测试调用程序
提供四个工程,分别对应四个服务分别是:springtest1,springtest2,springtest3,springtest4;springtest1通过httpclient调用springtest2,然后springtest2通过httpclient调用springtest3和springtest4,形成一个调用链;四个服务都是基于spring-boot来实现,对应的端口分别是8081,8082,8083,8084
具体代码见:https://github.com/wlmvp/zipkindemo
运行结果
发送一次调用请求
在zipkin ui上的展示效果
###对应下载的json为:
[
{
"traceId": "20d54eaab80af0e8",
"parentId": "de431abda88bed0d",
"id": "f8e6f28160c75955",
"kind": "SERVER",
"name": "get",
"timestamp": 1545026293807000,
"duration": 541000,
"localEndpoint": {
"serviceName": "service4",
"ipv4": "172.17.0.1"
},
"tags": {
"http.status_code": "200",
"http.url": "/service4"
}
},
{
"traceId": "20d54eaab80af0e8",
"parentId": "de431abda88bed0d",
"id": "c15f33be729f2485",
"kind": "SERVER",
"name": "get",
"timestamp": 1545026293127000,
"duration": 180000,
"localEndpoint": {
"serviceName": "service3",
"ipv4": "172.17.0.1"
},
"tags": {
"http.status_code": "200",
"http.url": "/service3"
}
},
{
"traceId": "20d54eaab80af0e8",
"parentId": "20d54eaab80af0e8",
"id": "de431abda88bed0d",
"kind": "CLIENT",
"name": "get",
"timestamp": 1545026292154000,
"duration": 2471000,
"localEndpoint": {
"serviceName": "service1",
"ipv4": "172.17.0.1"
},
"tags": {
"http.url": "/service2"
}
},
{
"traceId": "20d54eaab80af0e8",
"parentId": "20d54eaab80af0e8",
"id": "de431abda88bed0d",
"kind": "SERVER",
"name": "get",
"timestamp": 1545026292502000,
"duration": 2118000,
"localEndpoint": {
"serviceName": "service2",
"ipv4": "172.17.0.1"
},
"tags": {
"http.status_code": "200",
"http.url": "/service2"
}
},
{
"traceId": "20d54eaab80af0e8",
"parentId": "de431abda88bed0d",
"id": "c15f33be729f2485",
"kind": "CLIENT",
"name": "get",
"timestamp": 1545026292818000,
"duration": 516000,
"localEndpoint": {
"serviceName": "service2",
"ipv4": "172.17.0.1"
},
"tags": {
"http.url": "/service3"
}
},
{
"traceId": "20d54eaab80af0e8",
"parentId": "de431abda88bed0d",
"id": "f8e6f28160c75955",
"kind": "CLIENT",
"name": "get",
"timestamp": 1545026293339000,
"duration": 974000,
"localEndpoint": {
"serviceName": "service2",
"ipv4": "172.17.0.1"
},
"tags": {
"http.url": "/service4"
}
},
{
"traceId": "20d54eaab80af0e8",
"id": "20d54eaab80af0e8",
"kind": "SERVER",
"name": "get",
"timestamp": 1545026291653000,
"duration": 3348000,
"localEndpoint": {
"serviceName": "service1",
"ipv4": "172.17.0.1"
},
"tags": {
"http.status_code": "200",
"http.url": "/service1"
}
}
]
###elasticsearch:
curl http://192.168.119.158:9200/
{
"name" : "master",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "m078sK79TpaDnOI17Iz21Q",
"version" : {
"number" : "6.5.3",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "159a78a",
"build_date" : "2018-12-06T20:11:28.826501Z",
"build_snapshot" : false,
"lucene_version" : "7.5.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
###elasticsearch head的显示:
通过抓包可以看到这调用的报文里增加了tranceid等:
[root@localhost ~]# ./goreplay -input-raw :8081 -input-raw :8082 -input-raw :8083 -input-raw :8084 -output-file 8000.gor
Version: 0.16.1
^C[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# cat 8000_0.gor
1 98ff93f20b5f5f8ee0c5f33e476eb6b3daef5bfb 1546616755662145000
GET /service1 HTTP/1.1
Host: 192.168.119.158:8081
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
???
1 8a08f021c8b83b18b541a708b158078cfc8d5703 1546616755928309000
GET /service2 HTTP/1.1
X-B3-Sampled: 1
X-B3-TraceId: e865783e3d562e61
X-B3-SpanId: cb4887c469aa5653
X-B3-ParentSpanId: e865783e3d562e61
Host: localhost:8082
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_191)
Accept-Encoding: gzip,deflate
???
1 bee71d98c6dd46e9f2487772ce71fb3bd3985fcd 1546616757197535000
GET /service4 HTTP/1.1
X-B3-Sampled: 1
X-B3-TraceId: e865783e3d562e61
X-B3-SpanId: 779a117dced10f19
X-B3-ParentSpanId: cb4887c469aa5653
Host: localhost:8084
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_191)
Accept-Encoding: gzip,deflate
???
1 d36d6e6116ad5c3fbc1c9dadb535cbf413d33844 1546616756722889000
GET /service3 HTTP/1.1
X-B3-Sampled: 1
X-B3-TraceId: e865783e3d562e61
X-B3-SpanId: 470151a82bcd9cf
X-B3-ParentSpanId: cb4887c469aa5653
Host: localhost:8083
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_191)
Accept-Encoding: gzip,deflate
???
[root@localhost ~]#