环境版本
- centos: 7
- skywalking: 9.0.0
- skywalking-java-agent: 8.10.0
安装
1. 安装Elasticsearch
2. 下载skywalking
下载好skywalking,将资源上传到服务器
3. 将skywalking解压到指定目录
shell
cd /home/download
tar -zxvf apache-skywalking-apm-9.0.0.tar.gz -C /opt
4. 修改 OAP 配置文件 /opt/apache-skywalking-apm-bin/config/application.yml
shell
vi /opt/apache-skywalking-apm-bin/config/application.yml
通过storage.selector
配置项来设置具体使用的存储器。修改内容如下:
5. 启动 SkyWalking OAP 服务
shell
/opt/apache-skywalking-apm-bin/bin/oapService.sh
是否真正 启动成功,胖友打开 logs/skywalking-oap-server.log
日志文件,查看是否有错误日志。 首次启动时,因为 SkyWalking OAP 会创建 Elasticsearch 的索引,所以会"疯狂"的打印日志。 最终,我们看到如下日志,基本可以代表 SkyWalking OAP 服务启动成功:
log
2022-04-17 00:41:53,692 - org.apache.skywalking.oap.server.starter.OAPServerBootstrap - 53 [main] INFO [] - Version of OAP: 9.0.0-89644fe (20220217220813)
6. 安装SkyWalking UI
- 修改
/opt/apache-skywalking-apm-bin/webapp/webapp.yml
,内容如下:
vi
# 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.
server:
port: 6395
spring:
cloud:
gateway:
routes:
- id: oap-route
uri: lb://oap-service
predicates:
- Path=/graphql/**
discovery:
client:
simple:
instances:
oap-service:
- uri: http://127.0.0.1:12800
# - uri: http://<oap-host-1>:<oap-port1>
# - uri: http://<oap-host-2>:<oap-port2>
mvc:
throw-exception-if-no-handler-found: true
web:
resources:
add-mappings: true
management:
server:
base-path: /manage
【可选】如果想要修改 SkyWalking UI
服务的参数,可以编辑 webapp/webapp.yml
配置文件。例如说:
-
server.port
:SkyWalking UI 服务端口。默认的端口号为8080
,修改为6395
。 -
spring.cloud.discovery.client.simple.instances.oap-service
:SkyWalking OAP 服务地址数组。因为 SkyWalking UI 界面的数据,是通过请求 SkyWalking OAP 服务来获得的。 -
启动SkyWalking UI 服务
shell
bin/webappService.sh
- 访问 UI 界面 ,浏览器输入ip:port
7. 开机自启动
- 编写
oap
的停止脚本
shell
vi /opt/apache-skywalking-apm-bin/bin/oapShutdown.sh
内容如下:
vi
#!/bin/bash
# Stop SkyWalking-oap 9.0.0 by killing the process
PID=$(ps aux | grep skywalking-oap | grep -v grep | awk '{print $2}')
if [ -n "$PID" ]; then
sudo kill $PID
echo "SkyWalking-oap stopped successfully."
else
echo "SkyWalking-oap is not running."
fi
- 编写
UI
的停止脚本
shell
vi /opt/apache-skywalking-apm-bin/bin/webappShutdown.sh
内容如下:
vi
#!/bin/bash
# Stop SkyWalking 9.0.0 by killing the process
PID=$(ps aux | grep skywalking-webapp | grep -v grep | awk '{print $2}')
if [ -n "$PID" ]; then
sudo kill $PID
echo "SkyWalking-ui stopped successfully."
else
echo "SkyWalking-ui is not running."
fi
- 编写
oap
的service
shell
vi /etc/systemd/system/skywalking-oap.service
内容如下:
vi
[Unit]
Description=skywalking oap
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
User=root
Group=root
Environment="JAVA_HOME=/opt/jdk-11"
ExecStart=/opt/apache-skywalking-apm-bin/bin/oapService.sh
ExecStop=/opt/apache-skywalking-apm-bin/bin/oapShutdown.sh
Restart=always
PrivateTmp=true
LimitNOFILE=65536
WorkingDirectory=/opt/apache-skywalking-apm-bin/bin
- 编写
UI
的service
shell
cat /etc/systemd/system/skywalking-ui.service
内容如下:
vi
[Unit]
Description=skywalking
After=network.target
[Service]
Type=forking
User=root
Environment="JAVA_HOME=/opt/jdk-11"
ExecStart=/opt/apache-skywalking-apm-bin/bin/webappService.sh
ExecStop=/opt/apache-skywalking-apm-bin/bin/webappShutdown.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
- 启动和停止
oap
和UI
shell
systemctl start skywalking-oap
systemctl start skywalking-ui
systemctl stop skywalking-oap
systemctl stop skywalking-ui
- 设置自启动
shell
systemctl enable skywalking-oap
systemctl enable skywalking-ui
使用SkyWalking Java Agent【Shell】
1. 服务器上部署
- 下载skywalking-agent,将其上传到服务器。
- 配置环境变量
shell
vi /etc/profile
添加如下内容:
vi
# SkyWalking Agent 配置
# 配置 Agent 名字。一般来说,我们直接使用 Spring Boot 项目的 `spring.application.name` 。
export SW_AGENT_NAME=demo-application
# 配置 Collector 地址。
export SW_AGENT_COLLECTOR_BACKEND_SERVICES=127.0.0.1:11800
# 配置链路的最大 Span 数量。一般情况下,不需要配置,默认为 300 。主要考虑,有些新上 SkyWalking Agent 的项目,代码可能比较糟糕。
export SW_AGENT_SPAN_LIMIT=2000
# SkyWalking Agent jar 地址。
export JAVA_AGENT=-javaagent:/opt/skywalking-agent/skywalking-agent.jar
更多的变量,可以在 /Users/yunai/skywalking/skywalking-agent/config/agent.config
查看。要注意,可能有些变量是被注释掉的,例如说 SW_AGENT_SPAN_LIMIT
对应的 agent.span_limit_per_segment
。
- 使变量生效
shell
source /etc/profile
2. idea部署
参考下图配置: 运行springboot项目,查看skywalking如下图: