小白学习docker compose部署skywalking

前言

Skywalking是由国内开源爱好者吴晟开源并提交到Apache孵化器的开源项目, 2017年12月SkyWalking成为Apache国内首个个人孵化项目, 2019年4月17日SkyWalking从Apache基金会的孵化器毕业成为顶级项目, 目前SkyWalking支持Java、 .Net、 Node.js、 go、 python等探针, 数据存储支持MySQL、 ElasticSearch等, SkyWalking与Pinpoint相同, 对业务代码无侵入, 不过探针采集数据粒度相较于Pinpoint来说略粗, 但性能表现优秀, 目前SkyWalking增长势头强劲, 社区活跃, 中文文档齐全, 没有语言障碍, 支持多语言探针, 这些都是 SkyWalking的优势所在, 还有就是SkyWalking支持很多框架, 包括很多国产框架, 例如, Dubbo、 gRPC、 SOFARPC 等等, 同时也有很多开发者正在不断向社区提供更多插件以支持更多组件无缝接入SkyWalking。

部署

  1. 新建目录,更改权限777
shell 复制代码
mkdir -p /usr/local/docker/skywalking/{conf}

chmod 777 /usr/local/docker/skywalking/{conf}
  1. 新建docker-compose.yml
  • SW_STORAGE: 填写elasticsearch
  • SW_STORAGE_ES_CLUSTER_NODES: elasticsearch访问地址,我之前部署了
yml 复制代码
version: '3.3'
services:
  skywalking-oap:
    image: apache/skywalking-oap-server:9.0.0
    container_name: skywalking-oap
    volumes:
      - ./conf/alarm-settings.yml:/skywalking/config/alarm-settings.yml
    ports:
      - "11800:11800"
      - "12800:12800"
    environment:
      TZ: Asia/Shanghai
      SW_STORAGE: elasticsearch
      SW_STORAGE_ES_CLUSTER_NODES: 192.168.3.5:9200

  skywalking-ui:
    image: apache/skywalking-ui:9.0.0
    container_name: skywalking-ui
    depends_on:
      - skywalking-oap
    links:
      - skywalking-oap
    ports:
      - "6395:8080"
    environment:
      TZ: Asia/Shanghai
      SW_OAP_ADDRESS: http://skywalking-oap:12800
  1. 新建conf/alarm-settings.yml
yml 复制代码
rules:
  # Rule unique name, must be ended with `_rule`.
  service_resp_time_rule:
    metrics-name: service_resp_time
    op: ">"
    threshold: 1000
    period: 10
    count: 3
    silence-period: 5
    message: Response time of service {name} is more than 1000ms in 3 minutes of last 10 minutes.
  service_sla_rule:
    # Metrics value need to be long, double or int
    metrics-name: service_sla
    op: "<"
    threshold: 8000
    # The length of time to evaluate the metrics
    period: 10
    # How many times after the metrics match the condition, will trigger alarm
    count: 2
    # How many times of checks, the alarm keeps silence after alarm triggered, default as same as period.
    silence-period: 3
    message: Successful rate of service {name} is lower than 80% in 2 minutes of last 10 minutes
  service_resp_time_percentile_rule:
    # Metrics value need to be long, double or int
    metrics-name: service_percentile
    op: ">"
    threshold: 1000,1000,1000,1000,1000
    period: 10
    count: 3
    silence-period: 5
    message: Percentile response time of service {name} alarm in 3 minutes of last 10 minutes, due to more than one condition of p50 > 1000, p75 > 1000, p90 > 1000, p95 > 1000, p99 > 1000
  service_instance_resp_time_rule:
    metrics-name: service_instance_resp_time
    op: ">"
    threshold: 1000
    period: 10
    count: 2
    silence-period: 5
    message: Response time of service instance {name} is more than 1000ms in 2 minutes of last 10 minutes
  database_access_resp_time_rule:
    metrics-name: database_access_resp_time
    threshold: 1000
    op: ">"
    period: 10
    count: 2
    message: Response time of database access {name} is more than 1000ms in 2 minutes of last 10 minutes
  endpoint_relation_resp_time_rule:
    metrics-name: endpoint_relation_resp_time
    threshold: 1000
    op: ">"
    period: 10
    count: 2
    message: Response time of endpoint relation {name} is more than 1000ms in 2 minutes of last 10 minutes
 
webhooks:
#  - http://127.0.0.1/notify/
#  - http://127.0.0.1/go-wechat/

dingtalkHooks:
  textTemplate: |-
    {
      "msgtype": "text",
      "text": {
        "content": "Apache 告警: \n %s"
      }
    }
  webhooks:
    - url: https://oapi.dingtalk.com/robot/send?access_token=416e0d73280b480d5beb6533f475e493c6be9ca9eac85d0422718b8cfdf065e8
      secret: SEC87fc4df3f024cb76e36d75cdfc090009e275b672fd6b1062e0772ad8611e5b2d
  1. 打包运行,并访问
shell 复制代码
docker compose up -d

java agent

要想springboot项目使用Skywalking,还需要使用Skywalking的java-agent插件。

  • 服务器上,需要配置Java脚本
  1. 下载并解压java-agent
shell 复制代码
wget https://archive.apache.org/dist/skywalking/java-agent/9.0.0/apache-skywalking-java-agent-9.0.0.tgz

wget https://archive.apache.org/dist/skywalking/java-agent/9.0.0/apache-skywalking-java-agent-9.0.0.tgz
  1. 配置脚本启动
shell 复制代码
# 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:/usr/local/docker/skywalking/skywalking-agent/skywalking-agent.jar
 
# Jar 启动 
java -jar $JAVA_AGENT -jar xx.jar
  • idea中使用,需要先下载java-agent
相关推荐
biubiubiu070621 小时前
SpringBoot关于外部化配置
java·spring boot·spring
zzz_236821 小时前
【Spring】面试突击系列(二):SpringBoot 入门与自动配置原理
java·spring boot·spring
我登哥MVP1 天前
Spring Boot 从“会用”到“精通”:参数解析原理
java·spring boot·后端·spring·servlet·maven·intellij-idea
小江的记录本1 天前
【Spring全家桶】Spring Cloud 2023.0.x:微服务核心理论、CAP/BASE定理(附《思维导图》+《面试高频考点清单》)
java·spring boot·后端·spring·spring cloud·微服务·面试
我登哥MVP1 天前
Spring Boot 从“会用”到“精通”:Model-Map原理
java·spring boot·后端·spring·servlet·maven·mybatis
鱼鳞_1 天前
苍穹外卖-Day12(数据统计)
java·spring boot
心之伊始1 天前
Java 后端 AI 应用网关实战:多模型路由、Fallback、超时和可观测性设计
java·spring boot·大模型·架构设计·ai网关
RuoyiOffice1 天前
2026 企业定制开发选型:从零开发、低代码、SaaS 与 RuoYi Office 怎么选?
spring boot·uni-app·开源·saas·oa·定制化·ruoyioffice
可乐ea1 天前
【知识获取与分享社区项目 | 项目日记第 24 天】终章总结:从认证、发布、计数、Feed、搜索到 RAG:完整复盘一个知识社区后端系统
java·spring boot·redis·mysql·elasticsearch·ai·kafka
Jabes.yang1 天前
Java面试实录:AIGC场景下的Stream、微服务、Redis、Kafka与安全实战
java·spring boot·redis·微服务·面试·kafka·aigc