Skywalking是分布式系统的应用程序性能监视工具,专为微服务,云原生架构和基于容器(Docker, K8S, Mesos)架构而设计,它是一款优秀的APM性能分析、链路分析工具。
官网下载:https://skywalking.apache.org/downloads/
官网下载:https://www.elastic.co/cn/downloads/past-releases#elasticsearch
Elastic 中文社区:https://elasticsearch.cn/download/
下载elasticsearch-7.17.3-windows-x86_64.zip
修改elasticsearch.yml文件
cluster.name: elasticsearch
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
cluster.initial_master_nodes: ["node-1"]
在elasticsearch-7.17.3-no-jdk-windows-x86_64\bin执行启动命令
./elasticsearch
下载apache-skywalking-apm-9.5.0.tar.gz:https://archive.apache.org/dist/skywalking/9.5.0/apache-skywalking-apm-9.5.0.tar.gz
当前版本需要JDK11或JDK17才能运行,选一个喜欢的品牌JDK下载安装:jvm-and-jdk
使用bin/startup.sh(或cmd)以默认设置启动后端服务和管理后台UI,设置如下:
修改配置config/application.yml
storage:
# selector: ${SW_STORAGE:h2} # 默认存储
selector: ${SW_STORAGE:elasticsearch}
elasticsearch:
namespace: ${SW_NAMESPACE:"elasticsearch"}
# clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:localhost:9200}
clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:192.168.245.1:9200}
protocol: ${SW_STORAGE_ES_HTTP_PROTOCOL:"http"}
connectTimeout: ${SW_STORAGE_ES_CONNECT_TIMEOUT:3000}
socketTimeout: ${SW_STORAGE_ES_SOCKET_TIMEOUT:30000}
responseTimeout: ${SW_STORAGE_ES_RESPONSE_TIMEOUT:15000}
numHttpClientThread: ${SW_STORAGE_ES_NUM_HTTP_CLIENT_THREAD:0}
user: ${SW_ES_USER:""}
password: ${SW_ES_PASSWORD:""}
trustStorePath: ${SW_STORAGE_ES_SSL_JKS_PATH:""}
trustStorePass: ${SW_STORAGE_ES_SSL_JKS_PASS:""}
secretsManagementFile: ${SW_ES_SECRETS_MANAGEMENT_FILE:""}
dayStep: ${SW_STORAGE_DAY_STEP:1}
indexShardsNumber: ${SW_STORAGE_ES_INDEX_SHARDS_NUMBER:1}
indexReplicasNumber: ${SW_STORAGE_ES_INDEX_REPLICAS_NUMBER:1}
官方安装说明:https://skywalking.apache.org/docs/main/v9.5.0/en/setup/backend/backend-setup/
下载apache-skywalking-java-agent-9.0.0.tgz:https://www.apache.org/dyn/closer.cgi/skywalking/java-agent/9.0.0/apache-skywalking-java-agent-9.0.0.tgz
同一台主机的,可以使用同一份apache-skywalking-java-agent-9.0.0.tgz,也可以复制多份apache-skywalking-java-agent-9.0.0.tgz部署。
修改config/agent.config
#指定服务名称,本文是同一台机上部署三个服务,改为运行中指定服务器
agent.service_name=${SW_AGENT_NAME:Your_ApplicationName}
#每3s的采样率,0表示不采样,负数表示100%采样
agent.sample_n_per_3_secs=${SW_AGENT_SAMPLE:-1}
#指定链路数据的传送地址,默认127.0.0.1:11800
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:192.168.245.1:11800}
本文使用Spring Cloud 2022.x版本使用gateway和nacos实现动态路由和负载均衡的示例代码
工程App1服务加入监控,启动命令
java -javaagent:/usr/local/skywalking/skywalking-agent/skywalking-agent.jar -Dskywalking.agent.service_name=app1 -jar gateway-app1-1.0-SNAPSHOT.jar
工程App2服务加入监控,启动命令
java -javaagent:/usr/local/skywalking/skywalking-agent/skywalking-agent.jar -Dskywalking.agent.service_name=app2 -jar gateway-app2-1.0-SNAPSHOT.jar
plugins中默认没有Spring Cloud Gateway插件,不支持监控springcloud gateway网关服务。同时当前版本也不支持2022.x,需要把前文示例的Spring Cloud版本降为
com.alibaba.cloud
spring-cloud-alibaba-dependencies
2021.0.5.0
pom
import
org.springframework.cloud
spring-cloud-dependencies
2021.0.8
pom
import
org.springframework.boot
spring-boot-dependencies
2.7.15
pom
import
把optional-plugins中的apm-spring-cloud-gateway-3.x-plugin-9.0.0.jar、apm-spring-webflux-5.x-plugin-9.0.0.jar拷贝到plugins中。
工程gateway网关加入监控,启动命令
java -javaagent:/usr/local/skywalking/skywalking-agent/skywalking-agent.jar -Dskywalking.agent.service_name=gateway -jar gateway-nacos-1.0-SNAPSHOT.jar