说明:
springboot项目加入skywalking,达到链路日志监控的目的.
Skywalking OAP后端服务
和SkyWalking UI前端
服务; OAP服务数据存储采用H2(默认),不选esSkyWailking Agent
参考:https://www.iocoder.cn/SkyWalking/install/?skywalkinng
https://blog.csdn.net/AliEnCheng/article/details/126529335
官网安装包下载地址:https://skywalking.apache.org/downloads/#KubernetesHelm
https://dlcdn.apache.org/skywalking/9.3.0/apache-skywalking-apm-9.3.0.tar.gz
https://dlcdn.apache.org/skywalking/java-agent/8.14.0/apache-skywalking-java-agent-8.14.0.tgz
在服务器/usr/local
目录新建skywalking
文件夹,将apm
压缩包传输到该文件夹,并解压:
tar -zxcf apache-skywalking-java-agent-8.14.0.tgz
解压后文件夹:
-bash-4.2$ ll apache-skywalking-apm-bin/
total 108
drwxrwxr-x 2 paasops paasops 241 Mar 8 10:15 bin --> 存放服务的启动脚本
drwxrwxr-x 12 paasops paasops 4096 Mar 10 15:00 config --> 存放配置文件
drwxrwxr-x 2 paasops paasops 68 Mar 8 10:15 config-examples
-rw-r--r-- 1 paasops paasops 43740 Feb 18 2022 LICENSE
drwxr-xr-x 3 paasops paasops 4096 Mar 8 10:15 licenses
-rw-r--r-- 1 paasops paasops 1393 Feb 18 2022 LICENSE.tpl
drwxrwxr-x 2 paasops paasops 109 Mar 8 10:34 logs
-rw-r--r-- 1 paasops paasops 30503 Feb 18 2022 NOTICE
drwxr-xr-x 2 paasops paasops 12288 Feb 18 2022 oap-libs
-rw-r--r-- 1 paasops paasops 1947 Feb 18 2022 README.txt
drwxrwxr-x 4 paasops paasops 52 Mar 8 10:15 tools
drwxrwxr-x 2 paasops paasops 76 Mar 10 16:48 webapp --> 与skywalking UI有关
在apache-skywalking-apm-bin
文件夹新建一个agent
文件夹,将agent压缩包放到此处并解压:
tar -zxcf apache-skywalking-java-agent-8.14.0.tgz
解压后的文件夹
-bash-4.2$ ll skywalking-agent/
total 21348
drwxrwxr-x 2 paasops paasops 4096 Jan 12 11:38 activations
drwxrwxr-x 2 paasops paasops 131 Jan 12 11:39 bootstrap-plugins
drwxrwxr-x 2 paasops paasops 26 Mar 8 11:48 config
-rw-rw-r-- 1 paasops paasops 12911 Jan 12 11:36 LICENSE
drwxrwxr-x 2 paasops paasops 29 Jan 12 11:36 licenses
drwxrwxr-x 2 paasops paasops 32 Mar 8 12:37 logs
-rw-rw-r-- 1 paasops paasops 10003 Jan 12 11:36 NOTICE
drwxrwxr-x 2 paasops paasops 4096 Jan 12 11:39 optional-plugins
drwxrwxr-x 2 paasops paasops 131 Jan 12 11:39 optional-reporter-plugins
drwxrwxr-x 2 paasops paasops 8192 Jan 12 11:38 plugins
-rw-rw-r-- 1 paasops paasops 21808716 Jan 12 11:36 skywalking-agent.jar --> 待使用的jar包
skywalking/apache-skywalking-apm-bin/config
文件夹下的application.yml
文件:
默认存储使用h2,不做修改
启动oap, 进入skywalking/apache-skywalking-apm-bin/bin
,执行脚本:./oapService.sh
可在skywalking/apache-skywalking-apm-bin/logs
文件夹查看日志:
注意:
SkyWalking-oap-server服务启动后会暴露11800
和12800
两个端口,分别为收集监控数据
的端口11800和接收前端请求
的端口12800
/usr/local/skywalking/apache-skywalking-apm-bin/webapp/application.yaml
配置文件:
启动UI:进入/usr/local/skywalking/apache-skywalking-apm-bin/bin
目录执行启动脚本:./webappService.sh
启动命令添加参数:
-javaagent:/usr/local/skywalking/apache-skywalking-apm-bin/agent/skywalking-agent/skywalking-agent.jar --> agent包的位置
-DSW_AGENT_NAME=secondalert-test --> 应用名
-DSW_AGENT_COLLECTOR_BACKEND_SERVICES=127.0.0.1:11800 --> 收集数据的地址
example:
java -javaagent:/usr/local/skywalking/apache-skywalking-apm-bin/agent/skywalking-agent/skywalking-agent.jar -DSW_AGENT_NAME=secondalert-test -DSW_AGENT_COLLECTOR_BACKEND_SERVICES=127.0.0.1:11800 -Dspring.profiles.active=test -Dlogging.file.path=/data/paasops/logs/paas/paas-service-secondalert -jar /data/paasops/paas/service-secondAlert/paas-ops-secondalert-0.0.1.jar
访问UI地址:服务器ip:端口
(xxx.xxx.xxx.162:8080)
看到对应的服务名表示成功:
参考:
https://cloud.tencent.com/developer/article/1695427
官方文档:
https://skywalking.apache.org/docs/main/v9.3.0/en/setup/backend/backend-docker/
docker pull apache/skywalking-oap-server:9.0.0
-> oap镜像
docker pull apache/skywalking-ui:9.0.0
-> UI镜像
docker run --name oap --restart always -d apache/skywalking-oap-server:9.0.0
–> 启动oap
docker run -d --name skywalking-ui -e TZ=Asia/Shanghai -p 8088:8080 --link oap:oap -e SW_OAP_ADDRESS=http://oap:12800 apache/skywalking-ui:9.0.0
--> 启动UI
docker logs 容器id
注意:
因为UI需要访问oap的相应端口,需要设置变量SW_OAP_ADDRESS
那么两个容器之间该如何访问?
1. 可以采用 --link 参数,然后直接使用容器名访问
2. 也可以直接通过ip地址访问,:
如果两个容器在同一台服务器上运行(ip为:121.1xx.12x.162),那么SW_OAP_ADDRESS=http://121.1xx.12x.162:12800
ip地址需要加上http:// , 否则会不成功
常见错误:
启动UI失败,查看容器日志,docker logs 容器id
:
Exception in thread "main" java.lang.NullPointerException: authority
at java.base/java.util.Objects.requireNonNull(Unknown Source)
at com.linecorp.armeria.client.Endpoint.parse(Endpoint.java:96)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.base/java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.apache.skywalking.oap.server.webapp.OapProxyService.(OapProxyService.java:50)
此问题是由于SW_OAP_ADDRESS
变量错误
引起的,检查后端收集地址和端口是否正确,并在前面加上http://
官方文档:
https://docs.docker.com/compose/compose-file/
使用参考文章:
https://blog.csdn.net/pushiqiang/article/details/78682323
事先准备好两个镜像,oap和ui。参考 本文目录 2.1.1
。
新建一个docker-compose.yml文件:
version: '3' # 根据dokcer-compose版本确定
services:
sw-oap:
container_name: sw-oap-container
image: df2ce85c228d
expose: # 暴露端口,但不映射到宿主机,只被连接的服务访问
- "11800"
- "12800"
ports: # 映射到主机11801端口
- "11801:11800"
sw-ui:
container_name: sw-ui-container
depends_on: # 依赖sw-oap服务,让sw-aop服务先启动完成再启本服务
- sw-oap
image: 8ed36461dc01
ports:
- "8089:8080"
links: # 连接sw-oap服务,实现容器之间直接通过服务名访问
- sw-oap
environment: # 环境变量
SW_OAP_ADDRESS: http://sw-oap:12800
启动命令:docker-compose up -d
之后便可以使用docker方式查看容器的启动情况
参考:
https://www.jianshu.com/p/4f4c182bcbd8
将三个服务放到一个pod中:
新建一个deployment.yml
文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: oap-deployment --> deployment名字
namespace: kube-tracing -->命名空间
labels:
app: oap-tag --> 标签
spec:
selector:
matchLabels:
app: oap-tag
template:
metadata:
labels:
app: oap-tag
release: skywalking
spec:
containers:
- name: oap
image: 192.168.116.126:18080/skywalking/skywalking-oap-server:latest -->镜像位置
imagePullPolicy: Always
ports:
- containerPort: 11800
name: grpc
- containerPort: 12800
name: rest
resources:
requests:
memory: 2Gi
limits:
memory: 2Gi
env:
- name: JAVA_OPTS
value: "-Xmx1g -Xms1g"
- name: demo
image: 192.168.116.126:18080/skywalking/demo:latest
imagePullPolicy: Always
ports:
- containerPort: 8079
env:
- name: SW_AGENT_COLLECTOR_BACKEND_SERVICES
value: 127.0.0.1:11800
- name: SW_AGENT_NAME
value: test-demo-2
- name: sk-ui
image: 192.168.116.126:18080/skywalking/skywalking-ui:6.6.0
imagePullPolicy: Always
ports:
- containerPort: 8080
env:
- name: SW_OAP_ADDRESS
value: 127.0.0.1:12800
启动:
kubectl apply -f deployment.yml
查看:
kubectl get deployment -n kube-tracing
kubectl get pod -n kube-tracing
新建一个oap-service.yml
文件
apiVersion: v1
kind: Service
metadata:
name: oap-service
namespace: kube-tracing
spec:
type: NodePort
selector:
app: oap-tag
ports:
- name: rest
port: 8080
nodePort: 30081
- name: back
port: 8079
nodePort: 30079
启动:
kubectl apply -f oap-service.yml