image-20240521211151890

  • 多种监控手段:通过语言探针和 Service Mesh 等手段,获得链路、日志、指标等监控数据

  • 多个语言探针:Java、.Net Core、PHP、NodeJS、Golang、LUA、Rust、C++ 等

  • 轻量级高性能:无需大数据组件,无需大量的硬件资源,且对应用实例的负载消耗极低

  • 模块化架构:数据传输、数据存储,注册发现等模块,可替换不同的基础设施实现

  • 端到端的监控:Vue、React 等前端,Java、.Net Core、PHP、NodeJS、Golang、Istio 等后端

  • 告警机制:内置 Webhooks 发送事件通知,支持通过 HTTP、gRPC、Slack 等方式

  • 可视化界面:好用的监控后台,可支持自定义配置,或是集成你自己的

中文文档:

https://github.com/SkyAPM/document-cn-translation-of-skywalking

搭建步骤:

1、搭建 Elasticsearch

2.下载 SkyWalking 发布版

http://skywalking.apache.org/downloads/ 下,我们下载 SkyWalking 发布版

下载 SkyWalking OAP

image-20240521211516758

# 创建目录
mkdir -p /Users/yunai/skywalking
cd /Users/yunai/skywalking

# 下载
wget https://dlcdn.apache.org/skywalking/xxx/apache-skywalking-apm-xxx.tar.gz

# 解压
tar -zxvf apache-skywalking-apm-xxx.tar.gz
# 查看目录
cd apache-skywalking-apm-bin
ls -ls
# 查看目录(结果)
56 -rw-r--r--@   1 yunai  staff  27987 Feb 18 06:08 LICENSE
64 -rw-r--r--@   1 yunai  staff  30503 Feb 18 06:08 NOTICE
 8 -rw-r--r--@   1 yunai  staff   1951 Feb 18 06:08 README.txt
 0 drwxr-xr-x   12 yunai  staff    384 Apr 16 23:53 bin # 执行脚本
 0 drwxr-xr-x   21 yunai  staff    672 Apr 16 23:53 config # SkyWalking OAP Server 配置文件
 0 drwxr-xr-x    5 yunai  staff    160 Apr 16 23:53 config-examples
 0 drwxr-xr-x@  29 yunai  staff    928 Feb 18 06:08 licenses
 0 drwxr-xr-x@ 221 yunai  staff   7072 Feb 18 06:08 oap-libs # SkyWalking OAP Server
 0 drwxr-xr-x    3 yunai  staff     96 Apr 16 23:53 tools
 0 drwxr-xr-x    4 yunai  staff    128 Apr 16 23:53 webapp # SkyWalking UI

下载 SkyWalking Java Agent

# 创建目录
mkdir -p /Users/yunai/skywalking
cd /Users/yunai/skywalking

# 下载地址
https://dlcdn.apache.org/skywalking/java-agent/xxx/apache-skywalking-java-agent-xxx.tgz

# 解压
tar -zxvf apache-skywalking-java-agent-xxx.tgz
# 查看目录
cd skywalking-agent
ls -ls
# 查看目录(结果)
   32 -rw-r--r--@   1 yunai  staff     12911 Apr 12 23:51 LICENSE
   24 -rw-r--r--@   1 yunai  staff     10003 Apr 12 23:51 NOTICE
    0 drwxr-xr-x@  10 yunai  staff       320 Apr 12 23:52 activations
    0 drwxr-xr-x@   5 yunai  staff       160 Apr 12 23:52 bootstrap-plugins
    0 drwxr-xr-x@   3 yunai  staff        96 Apr 12 23:51 config # SkyWalking Java Agent 配置文件
    0 drwxr-xr-x@   3 yunai  staff        96 Apr 12 23:51 licenses
    0 drwxr-xr-x@   2 yunai  staff        64 Apr 12 23:51 logs # SkyWalking Java Agent 日志文件
    0 drwxr-xr-x@  21 yunai  staff       672 Apr 12 23:52 optional-plugins # SkyWalking Java Agent 的可选插件
    0 drwxr-xr-x@   6 yunai  staff       192 Apr 12 23:52 optional-reporter-plugins
    0 drwxr-xr-x@ 118 yunai  staff      3776 Apr 12 23:52 plugins # SkyWalking Java Agent 的开启插件
39808 -rw-r--r--@   1 yunai  staff  20378894 Apr 12 23:51 skywalking-agent.jar # SkyWalking Java Agent

3、搭建 SkyWalking OAP Server

修改 OAP 配置文件 apache-skywalking-apm-bin/config/application.yml

存储器配置:

image-20240521211546888

集群-nacos配置:

image-20240521211646662

configuration配置器配置:

image-20240521211714017

core 模块的选择器配置:

image-20240521211756168

4、启动 SkyWalking OAP 服务

依赖于JDK17以上版本

bin/oapService.sh #前台运行

查看 logs/skywalking-oap-server.log 日志文件,查看是否有错误日志

后台运行脚本:

#!/usr/bin/env sh# 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.​PRG="$0"PRGDIR=$(dirname "$PRG")[ -z "$OAP_HOME" ] && OAP_HOME=$(cd "$PRGDIR/.." > /dev/null || exit 1; pwd)​OAP_LOG_DIR="${OAP_LOG_DIR:-${OAP_HOME}/logs}"JAVA_OPTS="${JAVA_OPTS:-  -Xms256M -Xmx4096M}"​if [ ! -d "${OAP_LOG_DIR}" ]; then    mkdir -p "${OAP_LOG_DIR}"fi​_RUNJAVA=/usr/local/jdk-17.0.9/bin/java[ -z "/usr/local/jdk-17.0.9" ] && _RUNJAVA=java​if [ -z "$CLASSPATH" ]; then  CLASSPATH="$OAP_HOME/config"else  CLASSPATH="$OAP_HOME/config:$CLASSPATH"fi​for i in "$OAP_HOME"/oap-libs/*.jardo    CLASSPATH="$i:$CLASSPATH"done​OAP_OPTIONS=" -Doap.logDir=${OAP_LOG_DIR}"​eval exec "\\"$_RUNJAVA\\" ${JAVA_OPTS} ${OAP_OPTIONS} -classpath $CLASSPATH org.apache.skywalking.oap.server.starter.OAPServerStartUp \\        2>${OAP_LOG_DIR}/oap.log 1> /dev/null &"​#如果机器有多个jdk环境可自定义java路径,最后加了 &,在后台运行

5、SkyWalking UI 搭建

启动 SkyWalking UI 服务

bin/webappService.sh #前台启动

【可选】如果想要修改 SkyWalking UI 服务的参数,可以编辑 webapp/webapp.yml 配置文件。例如说:

  • server.port :SkyWalking UI 服务端口

  • spring.cloud.discovery.client.simple.instances.oap-service :SkyWalking OAP 服务地址数组。因为 SkyWalking UI 界面的数据,是通过请求 SkyWalking OAP 服务来获得的。

后台运行脚本:

#!/usr/bin/env sh
# 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.

PRG="$0"
PRGDIR=$(dirname "$PRG")
[ -z "$OAP_HOME" ] && OAP_HOME=$(cd "$PRGDIR/.." > /dev/null || exit 1; pwd)

OAP_LOG_DIR="${OAP_LOG_DIR:-${OAP_HOME}/logs}"
JAVA_OPTS="${JAVA_OPTS:-  -Xms256M -Xmx4096M}"

if [ ! -d "${OAP_LOG_DIR}" ]; then
    mkdir -p "${OAP_LOG_DIR}"
fi

_RUNJAVA=/usr/local/jdk-17.0.9/bin/java
[ -z "/usr/local/jdk-17.0.9" ] && _RUNJAVA=java

if [ -z "$CLASSPATH" ]; then
  CLASSPATH="$OAP_HOME/config"
else
  CLASSPATH="$OAP_HOME/config:$CLASSPATH"
fi

for i in "$OAP_HOME"/oap-libs/*.jar
do
    CLASSPATH="$i:$CLASSPATH"
done

OAP_OPTIONS=" -Doap.logDir=${OAP_LOG_DIR}"

eval exec "\"$_RUNJAVA\" ${JAVA_OPTS} ${OAP_OPTIONS} -classpath $CLASSPATH org.apache.skywalking.oap.server.starter.OAPServerStartUp \
        2>${OAP_LOG_DIR}/oap.log 1> /dev/null &"

#如果机器有多个jdk环境可自定义java路径,最后加了 &,在后台运行

6、访问 UI 界面:

浏览器打开 http://127.0.0.1:8080 地址,进行访问

7、SkyWalking Java Agent

在启动项目的 Shell 脚本上,可以通过 -javaagent 参数进行配置 SkyWalking Java Agent

注意:agent文件夹里面的plugins如果没有gateway的相关jar包,要把optional-plugins里面的gateway插件复制进去,不然链路追踪不到网关

配置 Java 启动脚本

注意:如果使用group server ,格式为export SW_AGENT_NAME=zhyl::jjsm_zl

#!/usr/bin/env sh
# 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.

PRG="$0"
PRGDIR=$(dirname "$PRG")
[ -z "$WEBAPP_HOME" ] && WEBAPP_HOME=$(cd "$PRGDIR/.." > /dev/null || exit 1; pwd)

WEBAPP_LOG_DIR="${WEBAPP_LOG_DIR:-${WEBAPP_HOME}/logs}"
JAVA_OPTS="${JAVA_OPTS:-  -Xms256M -Xmx1024M} -Dwebapp.logDir=${WEBAPP_LOG_DIR}"
JAR_PATH="${WEBAPP_HOME}/webapp"

if [ ! -d "${WEBAPP_LOG_DIR}" ]; then
    mkdir -p "${WEBAPP_LOG_DIR}"
fi

LOG_FILE_LOCATION=${WEBAPP_LOG_DIR}/webapp.log

_RUNJAVA=/usr/local/jdk-17.0.9/bin/java
[ -z "/usr/local/jdk-17.0.9" ] && _RUNJAVA=java

eval exec "\"$_RUNJAVA\" ${JAVA_OPTS} -cp ${JAR_PATH}/skywalking-webapp.jar:$JAR_PATH \
         org.apache.skywalking.oap.server.webapp.ApplicationStartUp \
        2>${WEBAPP_LOG_DIR}/webapp-console.log 1> /dev/null &"

#如果机器有多个jdk环境可自定义java路径,最后加了 &,在后台运行
  • 通过环境变量,进行配置。

  • 更多的变量,可以在 [skywalking-agent/config/agent.config](<https://github.com/apache/skywalking-java/blob/main/apm-sniffer/config/agent.config>) 查看

最终示例图

![image-20240521211931544](https://cdn.jsdelivr.net/gh/yushui1995/img/202405212121402.png)image-20240521211931544

搭建一个 SkyWalking 集群环境,步骤如下:

  • 第一步,搭建一个 Elasticsearch 服务的集群

  • 第二步,搭建一个注册中心的集群。目前 SkyWalking 支持 Zookeeper、Kubernetes、Consul、Nacos 作为注册中心。

  • 第三步,搭建一个 SkyWalking OAP 服务的集群,同时参考 ,将 SkyWalking OAP 服务注册到注册中心上

  • 第四步,启动一个 Spring Boot 应用,并配置 SkyWalking Agent。另外,在设置 SkyWaling Agent 的 SW_AGENT_COLLECTOR_BACKEND_SERVICES 地址时,需要设置多个 SkyWalking OAP 服务的地址数组

  • 第五步,搭建一个 SkyWalking UI 服务的集群,同时使用 Nginx 进行负载均衡。另外,在设置 SkyWalking UI 的 spring.cloud.discovery.client.simple.instances.oap-service 地址时,也需要设置多个 SkyWalking OAP 服务的地址数组