小白学习centos7安装skywalking

环境版本

  • centos: 7
  • skywalking: 9.0.0
  • skywalking-java-agent: 8.10.0

安装

1. 安装Elasticsearch

参考 小白学习centos7部署ELK(一):搭建ELK

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
  • 编写oapservice
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
  • 编写UIservice
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
  • 启动和停止oapUI
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. 服务器上部署

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如下图:

参考

相关推荐
bluceli8 小时前
前端监控与错误追踪实战指南:构建稳定应用的终极方案
前端·监控
JackyRoad1 天前
Prometheus-Grafana-vLLM监控实战指南
性能优化·grafana·监控
爱吃橘子橙子柚子2 天前
3CPU性能排查总结(超详细)【Linux性能优化】
运维·cpu
舒一笑4 天前
程序员效率神器:一文掌握 tmux(服务器开发必备工具)
运维·后端·程序员
NineData4 天前
数据库管理工具NineData,一年进化成为数万+开发者的首选数据库工具?
运维·数据结构·数据库
明月_清风4 天前
前端异常捕获:从“页面崩了”到“精准定位”的实战架构
前端·javascript·监控
梦想很大很大5 天前
拒绝“盲猜式”调优:在 Go Gin 项目中落地 OpenTelemetry 链路追踪
运维·后端·go
Sinclair5 天前
内网服务器离线安装 Nginx+PHP+MySQL 的方法
运维
叶落阁主5 天前
Tailscale 完全指南:从入门到私有 DERP 部署
运维·安全·远程工作
甲鱼9296 天前
MySQL 实战手记:日志管理与主从复制搭建全指南
运维