Skywalking部署
2022-12-04 本文已影响0人
Habit_1027
Skywalking
一、SkyWalking是什么
SkyWalking是分布式系统的应用程序性能监视工具,专为微服务、云原生架构和基于容器(Docker、K8S、Mesos)架构而设计;
SkyWalking是观察性分析平台和应用性能管理系统。提供分布式追踪、服务网格遥测分析、度量聚合和可视化一体化解决方案;
二、Skywalking架构
整个架构,分成上、下、左、右四部分:
-
上部分 Agent :负责从应用中,收集链路信息,发送给 SkyWalking OAP 服务器。目前支持 SkyWalking、Zikpin、Jaeger 等提供的 Tracing 数据信息。而我们目前采用的是,SkyWalking Agent 收集 SkyWalking Tracing 数据,传递给服务器。
-
下部分 SkyWalking OAP :负责接收 Agent 发送的 Tracing 数据信息,然后进行分析(Analysis Core) ,存储到外部存储器( Storage ),最终提供查询( Query )功能。
-
右部分 Storage :Tracing 数据存储。目前支持 ES、MySQL、Sharding Sphere、TiDB、H2 多种存储器。而我们目前采用的是 ES ,主要考虑是 SkyWalking 开发团队自己的生产环境采用 ES 为主。
-
左部分 SkyWalking UI :负责提供控台,查看链路等等
三、Skywalking部署
3.1、Skywalking单机环境
image.png3.2、ElasticSearch搭建
1.上传下载的压缩包到服务器并解压
tar -zxvf elasticsearch-7.4.2-linux-x86_64.tar.gz //解压压缩包
cd elasticsearch-7.4.2 //进入目录
mkdir data //创建data文件夹,保存数据
2.修改Elasticsearch配置:config/elasticsearch.yml
cluster.name: apm-application
node.name: node-1
path.data: /opt/elasticsearch-7.4.2/data
path.logs: /opt/elasticsearch-7.4.2/logs
# ES监听的ip地址
network.host: 0.0.0.0
cluster.initial_master_nodes: ["node-1"]
# 需要开启跨域才能给elasticsearch-head,kibana等连接
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
3.创建Elasticsearch启动用户
groupadd elsearch
useradd elsearch -g elsearch
chown -R elsearch:elsearch elasticsearch-7.4.2
4.修改系统参数,启动elasticsearch
# vi /etc/sysctl.conf
vm.max_map_count=262144
# sysctl -p
cd elasticsearch-7.4.2
su elsearch
./bin/elasticsearch -d
5.前端访问 IP:9200
查看是否启动
3.3、下载 SkyWalking 软件包
1.下载SkyWalking官方包
我们选择apache-skywalking-apm-es7-8.0.0.tar.gz版本想使用 Elasticsearch 7.X 版本作为存储
2.上传下载的压缩包到linux服务器,解压文件
tar -zxvf apache-skywalking-apm-es7-8.0.0.tar.gz
cd apache-skywalking-apm-bin-es7/
3.4、SkyWalking OAP 搭建
1.修改 OAP 配置文件 config/application.yml
storage:
selector: ${SW_STORAGE:elasticsearch7}
elasticsearch:
nameSpace: ${SW_NAMESPACE:""}
clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:localhost:9200}
protocol: ${SW_STORAGE_ES_HTTP_PROTOCOL:"http"}
trustStorePath: ${SW_STORAGE_ES_SSL_JKS_PATH:""}
trustStorePass: ${SW_STORAGE_ES_SSL_JKS_PASS:""}
user: ${SW_ES_USER:""}
password: ${SW_ES_PASSWORD:""}
secretsManagementFile: ${SW_ES_SECRETS_MANAGEMENT_FILE:""} # Secrets management file in the properties format includes the username, password, which are manag
ed by 3rd party tool.
dayStep: ${SW_STORAGE_DAY_STEP:1} # Represent the number of days in the one minute/hour/day index.
indexShardsNumber: ${SW_STORAGE_ES_INDEX_SHARDS_NUMBER:1} # The index shards number is for store metrics data rather than basic segment record
superDatasetIndexShardsFactor: ${SW_STORAGE_ES_SUPER_DATASET_INDEX_SHARDS_FACTOR:5} # Super data set has been defined in the codes, such as trace segments. Th
is factor provides more shards for the super data set, shards number = indexShardsNumber * superDatasetIndexShardsFactor. Also, this factor effects Zipkin and Jae
ger traces.
indexReplicasNumber: ${SW_STORAGE_ES_INDEX_REPLICAS_NUMBER:0}
# Batch process setting, refer to https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.5/java-docs-bulk-processor.html
bulkActions: ${SW_STORAGE_ES_BULK_ACTIONS:1000} # Execute the bulk every 1000 requests
flushInterval: ${SW_STORAGE_ES_FLUSH_INTERVAL:10} # flush the bulk every 10 seconds whatever the number of requests
concurrentRequests: ${SW_STORAGE_ES_CONCURRENT_REQUESTS:2} # the number of concurrent requests
resultWindowMaxSize: ${SW_STORAGE_ES_QUERY_MAX_WINDOW_SIZE:10000}
metadataQueryMaxSize: ${SW_STORAGE_ES_QUERY_MAX_SIZE:5000}
segmentQueryMaxSize: ${SW_STORAGE_ES_QUERY_SEGMENT_SIZE:200}
profileTaskQueryMaxSize: ${SW_STORAGE_ES_QUERY_PROFILE_TASK_SIZE:200}
advanced: ${SW_STORAGE_ES_ADVANCED:""}
elasticsearch7:
nameSpace: ${SW_NAMESPACE:""}
clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:192.168.20.200:9200}
protocol: ${SW_STORAGE_ES_HTTP_PROTOCOL:"http"}
trustStorePath: ${SW_STORAGE_ES_SSL_JKS_PATH:""}
trustStorePass: ${SW_STORAGE_ES_SSL_JKS_PASS:""}
dayStep: ${SW_STORAGE_DAY_STEP:1} # Represent the number of days in the one minute/hour/day index.
user: ${SW_ES_USER:""}
password: ${SW_ES_PASSWORD:""}
secretsManagementFile: ${SW_ES_SECRETS_MANAGEMENT_FILE:""} # Secrets management file in the properties format includes the username, password, which are manag
ed by 3rd party tool.
indexShardsNumber: ${SW_STORAGE_ES_INDEX_SHARDS_NUMBER:1} # The index shards number is for store metrics data rather than basic segment record
superDatasetIndexShardsFactor: ${SW_STORAGE_ES_SUPER_DATASET_INDEX_SHARDS_FACTOR:5} # Super data set has been defined in the codes, such as trace segments. Th
is factor provides more shards for the super data set, shards number = indexShardsNumber * superDatasetIndexShardsFactor. Also, this factor effects Zipkin and Jae
ger traces.
indexReplicasNumber: ${SW_STORAGE_ES_INDEX_REPLICAS_NUMBER:0}
# Batch process setting, refer to https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.5/java-docs-bulk-processor.html
bulkActions: ${SW_STORAGE_ES_BULK_ACTIONS:1000} # Execute the bulk every 1000 requests
flushInterval: ${SW_STORAGE_ES_FLUSH_INTERVAL:10} # flush the bulk every 10 seconds whatever the number of requests
concurrentRequests: ${SW_STORAGE_ES_CONCURRENT_REQUESTS:2} # the number of concurrent requests
resultWindowMaxSize: ${SW_STORAGE_ES_QUERY_MAX_WINDOW_SIZE:10000}
metadataQueryMaxSize: ${SW_STORAGE_ES_QUERY_MAX_SIZE:5000}
segmentQueryMaxSize: ${SW_STORAGE_ES_QUERY_SEGMENT_SIZE:200}
profileTaskQueryMaxSize: ${SW_STORAGE_ES_QUERY_PROFILE_TASK_SIZE:200}
advanced: ${SW_STORAGE_ES_ADVANCED:""}
2.启动OAP
$ bin/oapService.sh
SkyWalking OAP started successfully!
3.4 SkyWalking UI 搭建
1.由于SkyWalking UI的默认地址是8080,与很多中间件有冲突,可以修改一下
#修改webapp/webapp.yml
server:
port: 18080
2.启动 SkyWalking UI 服务
$ bin/webappService.sh
SkyWalking Web Application started successfully!
3.5 SkyWalking Agent
1.修改探针默认配置 agent/config/agent.config
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:192.168.20.200:11800}
agent.sample_n_per_3_secs=${SW_AGENT_SAMPLE:1}
采样率修改
agent.sample_n_per_3_secs配置说明:
在访问量较少时,链路全量收集不会对系统带来太大负担,能够完整的观测到系统的运行状况。但是在访问量较大时,全量的链路收集,对链路收集的客户端(agent探针)、服务端(SkyWalking OAP)、存储器(例如说 Elastcsearch)都会带来较大的性能开销,甚至会影响应用的正常运行。在访问量级较大的情况下,往往会选择抽样采样,只收集部分链路信息。SkyWalking Agent 在 agent/config/agent.config 配置文件中,定义了 agent.sample_n_per_3_secs 配置项,设置每 3 秒可收集的链路数据的数量。
2.放置探针
- 我们需要将 agent 目录,拷贝到 Java 应用所在的服务器上。这样,Java 应用才可以配置使用该 SkyWalking Agent。通过设置启动参数的方式检测系统,没有代码侵入。
#在服务的启动命令中添加参数javaagent、Dskywalking.agent.service_name
nohup java -javaagent:agent/skywalking-agent.jar -Dskywalking.agent.service_name=a -jar a.jar > a.log
- Idea 配置,如果我们是本地启动的项目,开发工具使用的IDEA,我们只需要在如下图所示地方配置启动附加信息即可
# javaagent配置的是agent对应的jar位置。
# Dskywalking.agent.service_name配置建议使用服务的spring.application.name方便区分。
-javaagent:D:\Develop\apache-skywalking-apm-bin-es7\agent\skywalking-agent.jar
-Dskywalking.agent.service_name=leimingtech-admin-api