banner
云野阁

云野阁

闲云野鹤,八方逍遥

docker 部署 SkyWalking

前言#

🔜什么是SkyWalking?🔚

是一款优秀的国产 APM 工具。

分布式系统的应用程序性能监视工具,专为微服务、云原生架构和基于容器(Docker、K8s、Mesos)架构而设计。

提供分布式追踪、服务网格遥测分析、度量聚合和可视化一体化解决方案。

SkyWalking 架构分为 UI、OAP、存储、探针 4 部分。

其中 UI 为SkyWalking UI :负责提供控台、查看链路等等;(可视化显示)

OAP 为SkyWalking OAP :负责接收 Agent(探针) 发送的 Tracing 数据信息,然后进行分析(Analysis Core) ,存储到外部存储器 ( Storage ),最终提供查询 ( Query ) 功能。(数据分析)

存储为 Tracing 数据存储。目前支持 ES、MySQL、Sharding Sphere、TiDB、H2 多种存储器。而我们目前采用的是 ES ,主要考虑是 SkyWalking 开发团队自己的生产环境采用 ES 为主。(存储数据)

探针为 Agent :负责从应用中,收集链路信息,发送给 SkyWalking OAP 服务器。目前支持 SkyWalking、Zikpin、Jaeger 等提供的 Tracing 数据信息。而我们目前采用的是,SkyWalking Agent 收集 SkyWalking Tracing 数据,传递给服务器。(收集数据)

环境准备#

(1)使用脚本安装 docker、docker-compose

bash <(curl -sSL https://linuxmirrors.cn/docker.sh)

(2)配置镜像加速

vi /etc/docker/daemon.json

{
  "data-root": "/data/dockerData",
  "registry-mirrors": ["https://registry.cn-hangzhou.aliyuncs.com",
    "https://huecker.io",
    "https://docker.rainbond.cc",
    "https://dockerhub.timeweb.cloud",
    "https://dockerhub.icu",
    "https://docker.registry.cyou",
    "https://docker-cf.registry.cyou",
    "https://dockercf.jsdelivr.fyi",
    "https://docker.jsdelivr.fyi",
    "https://dockertest.jsdelivr.fyi",
    "https://mirror.aliyuncs.com",
    "https://dockerproxy.com",
    "https://mirror.baidubce.com",
    "https://docker.m.daocloud.io",
    "https://docker.nju.edu.cn",
    "https://docker.mirrors.sjtug.sjtu.edu.cn",
    "https://docker.mirrors.ustc.edu.cn",
    "https://mirror.iscas.ac.cn",
    "https://docker.rainbond.cc",
    "https://docker.kubesre.xyz"],
    "log-driver":"json-file",
    "log-opts":{"max-size" :"50m","max-file":"3"}
}

(3)启动 docker 服务

systemctl start docker
systemctl enable docker
systemctl status docker

(4)设置与内存映射相关的内核参数为 262144,查看应用到系统的内核参数。

echo "vm.max_map_count=262144" >> /etc/sysctl.conf
sysctl -p

部署步骤#

(1)创建部署文件所需的存储目录

mkdir -p /data/elasticsearch/data /data/elasticsearch/logs /data/skywalking/oap
chmod -R 777 /data/elasticsearch

(2)创建临时 skywalking-oap-server 容器,将 skywalking 配置文件拷贝到映射目录中。

cd /data/skywalking/oap
# 创建临时skywalking-oap-server容器,拷贝skywalking配置文件到主机目录
docker run -itd --name=oap-temp apache/skywalking-oap-server:9.5.0
docker cp  oap-temp:/skywalking/config/. .
docker rm -f oap-temp

(3)修改 skywalking 的配置文件 application.yml,将 elasticsearch 作为数据存储。

vi application.yml

storage:
  selector: ${SW_STORAGE:elasticsearch} #将h2修改为elasticsearch
  elasticsearch:
    namespace: ${SW_NAMESPACE:""}
    clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:本机ip:9200} #localhost修改为主机ip
    protocol: ${SW_STORAGE_ES_HTTP_PROTOCOL:"http"}
    connectTimeout: ${SW_STORAGE_ES_CONNECT_TIMEOUT:3000}
    socketTimeout: ${SW_STORAGE_ES_SOCKET_TIMEOUT:30000}
    responseTimeout: ${SW_STORAGE_ES_RESPONSE_TIMEOUT:15000}
    numHttpClientThread: ${SW_STORAGE_ES_NUM_HTTP_CLIENT_THREAD:0}
    user: ${SW_ES_USER:"elastic"} #填写es的账号
    password: ${SW_ES_PASSWORD:"elastic"} #填写es密码
    trustStorePath: ${SW_STORAGE_ES_SSL_JKS_PATH:""}
    trustStorePass: ${SW_STORAGE_ES_SSL_JKS_PASS:""}

(4)创建 docker-compose 文件,编排部署 skywalking、es、skywalking-ui。

vi skywalking.yml

services:
  elasticsearch:
    image: elasticsearch:8.15.0
    container_name: elasticsearch
    restart: always
    environment:
      - discovery.type=single-node
      - ES_JAVA_OPTS=-Xms1g -Xmx1g
      - ELASTIC_PASSWORD=elastic
      - TZ=Asia/Shanghai
    ports:
      - "9200:9200"
      - "9300:9300"
    healthcheck:
      test: [ "CMD-SHELL", "curl --silent --fail -u elastic:elasitc localhost:9200/_cluster/health || exit 1" ]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
  logging:
      driver: "json-file"
      options:
        max-size: "50m"
        max-file: "3"
    volumes:
      - /data/elasticsearch/data:/usr/share/elasticsearch/data
      - /data/elasticsearch/logs:/usr/share/elasticsearch/logs
      - /data/elasticsearch/plugins:/usr/share/elasticsearch/plugins
    networks:
      skywalking-network:
        ipv4_address: 172.20.110.11
    ulimits:
      memlock:
        soft: -1
        hard: -1

  skywalking-oap:
    image: apache/skywalking-oap-server:9.5.0
    container_name: skywalking-oap
    restart: always
    ports:
      - "11800:11800"
      - "12800:12800"
      - "1234:1234"  
    healthcheck:
      test: [ "CMD-SHELL", "/skywalking/bin/swctl health" ]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
    depends_on:
      elasticsearch:
        condition: service_healthy
    environment:
      - SW_STORAGE=elasticsearch
      - SW_HEALTH_CHECKER=default
      - TZ=Asia/Shanghai
      - JVM_Xms=512M
      - JVM_Xmx=1024M
      - SW_STORAGE_ES_CLUSTER_NODES=本机ip:9200
    volumes:
      - /data/skywalking/oap:/skywalking/config
    networks:
      skywalking-network:
        ipv4_address: 172.20.110.12


  skywalking-ui:
    image: apache/skywalking-ui:9.5.0
    container_name: skywalking-ui
    restart: always
    environment:
      - SW_OAP_ADDRESS=http://本机ip:12800
      - SW_ZIPKIN_ADDRESS=http://本机ip:9412
      - TZ=Asia/Shanghai
    ports:
      - "8080:8080"
    depends_on:
      skywalking-oap:
        condition: service_healthy
    networks:
      skywalking-network:
        ipv4_address: 172.20.110.13

networks:
  skywalking-network:
    driver: bridge
    ipam:
      config:
        - subnet: 172.20.110.0/24
docker compose -f skywalking.yml up -d

Skywalking 可通过以下两种方式连接 es,作为存储。(使用其中一种即可)

Skywalking 通过 HTTP 认证连接 Elasticsearch

#关闭es的ssl证书认证
docker exec -it elasticsearch bash -c ' sed -i "s/  enabled: true/  enabled: false/g" /usr/share/elasticsearch/config/elasticsearch.yml'
docker exec -it elasticsearch bash -c 'cat /usr/share/elasticsearch/config/elasticsearch.yml'
docker restart elasticsearch
docker restart skywalking-oap

Skywalking 通过 HTTPS SSL 认证连接 Elasticsearch

(1) 将 es 的 crt 和 key 证书文件,转化为 p12 格式

openssl pkcs12 -export -in ca.crt -inkey ca.key -out es.p12 -name esca -CAfile es.crt

输入两次 keypass,其中 - name 参数为别名。

openssl pkcs12 -export -in ca.crt -inkey ca.key -out es.p12 -name esca -CAfile es.crt
Enter Export Password:
Verifying - Enter Export Password:

(2)将 p12 格式证书转化为 jks 证书

安装 JDK。keytool 是 JDK 中的一部分,需要安装 JDK,进行证书转化操作。

 yum install - java-11-openjdk-devel

storepass 参数为 jks 证书密码,srcstorepass 参数为 p12 证书密码。

keytool -importkeystore -v -srckeystore es.p12 -srcstoretype PKCS12  -srcstorepass wasd2345  -deststoretype JKS -destkeystore es.jks -storepass qiswasd2345

storage:
selector: ${SW_STORAGE}
elasticsearch:
namespace: ${SW_NAMESPACE:""}
clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:es 所在服务器地址:443}
protocol: 443${SW_STORAGE_ES_HTTP_PROTOCOL:"https"}
connectTimeout: ${SW_STORAGE_ES_CONNECT_TIMEOUT:3000}
socketTimeout: ${SW_STORAGE_ES_SOCKET_TIMEOUT:30000}
responseTimeout: ${SW_STORAGE_ES_RESPONSE_TIMEOUT:15000}
numHttpClientThread: ${SW_STORAGE_ES_NUM_HTTP_CLIENT_THREAD:0}
user: ${SW_ES_USER:"es 用户名"}
password: ${SW_ES_PASSWORD:"es 密码"}
trustStorePath: ${SW_STORAGE_ES_SSL_JKS_PATH:"jks 证书地址"}
trustStorePass: ${SW_STORAGE_ES_SSL_JKS_PASS:"jks 证书密码"}

开启 Linux 监控#

安装 Prometheus node-exporter 从 VM 收集指标数据。(源码方式)#

yum install -y wget
wget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz
tar -xvzf node_exporter-1.8.2.linux-amd64.tar.gz
cd 
mv node_exporter-1.8.2.linux-amd64/node_exporter /usr/sbin/
cd /usr/sbin/
./node_exporter

验证是否运行

curl http://localhost:9100/metrics

创建 node_exporter 服务文件

vi /usr/lib/systemd/system/node_exporter.service

[Unit]
Description=node exporter service
Documentation=https://prometheus.io
After=network.target

[Service]
Type=simple
User=root
Group=root
#node_exporter的存放位置
ExecStart=/usr/sbin/node_exporter  
Restart=on-failure

[Install]
WantedBy=multi-user.target

重新加载系统管理器配置文件,启动 node_exporter 服务并设置开机自启

systemctl daemon-reload
systemctl start node_exporter
systemctl enable node_exporter
systemctl status node_exporter

安装 Prometheus node-exporter(容器方式)#

services:
  node-exporter:
    image: quay.io/prometheus/node-exporter
    container_name: node-exporter
    volumes:
      - /proc:/host/proc:ro
      - /sys:/host/sys:ro
      - /:/rootfs:ro
    command:
      - '--path.procfs=/host/proc'
      - '--path.rootfs=/rootfs'
      - '--path.sysfs=/host/sys'
    restart: always
    environment:
      - TZ=Asia/Shanghai
    ports:
      - 9100:9100
    networks:
       linux_exporter:
        ipv4_address: 172.20.104.11

networks:
  linux_exporter:
    driver: bridge
    ipam:
      config:
        - subnet: 172.20.104.0/24

安装 OpenTelemetry Collector#

创建 OpenTelemetry Collector 配置文件

mkdir /data/opentelemetry-collector
vi /data/opentelemetry-collector/config.yaml

receivers:
  prometheus:
    config:
     scrape_configs:
       - job_name: 'vm-monitoring' #要与skywalking-oap中的otel-rules的vm.yaml中的名称保持一致
         scrape_interval: 5s
         static_configs:
           - targets: ['10.10.2.145:9100']
             labels:
               host_name: 10.10.2.145
               service: oap-server
processors:
  batch:

exporters:
  otlp:
    endpoint: 10.10.2.145:11800
    tls:
      insecure: true
  logging:
    loglevel: debug

service:
  pipelines:
    metrics:
      receivers: [prometheus]
      processors: [batch]
      exporters: [otlp, logging]
services:
  otelcol:
    image: otel/opentelemetry-collector
    container_name: otelcol
    restart: always
    environment:
      - TZ=Asia/Shanghai
    volumes:
      - /data/opentelemetry-collector/config.yaml:/etc/otelcol/config.yaml
    networks:
       opentelemetry:
        ipv4_address: 172.20.101.11

networks:
  opentelemetry:
    driver: bridge
    ipam:
      config:
        - subnet: 172.20.101.0/24

opentelemetry-collector 最新镜像配置文件变更在最新版的容器镜像中(0.113.0)中使用导出器 exporters 中使用 debug 代替 logging
即在 v0.86.0 版本之前使用 logging

exporters:
otlp:
endpoint: ip + 端口
tls:
insecure: true
logging:
loglevel: debug

之后使用 debug

exporters:
otlp:
endpoint: ip + 端口
tls:
insecure: true
debug:
verbosity: detailed

SkyWalking 服务自监控开启#

开启后端遥测,在 skywalking-oap 的配置文件 application.yml 中,找到 promethus 的部分,修改参数。

telemetry:
  selector: ${SW_TELEMETRY:prometheus} #将none修改为prometheus
  none:
  prometheus:
    host: ${SW_TELEMETRY_PROMETHEUS_HOST:0.0.0.0}
    port: ${SW_TELEMETRY_PROMETHEUS_PORT:1234}
    sslEnabled: ${SW_TELEMETRY_PROMETHEUS_SSL_ENABLED:false}
    sslKeyPath: ${SW_TELEMETRY_PROMETHEUS_SSL_KEY_PATH:""}
    sslCertChainPath: ${SW_TELEMETRY_PROMETHEUS_SSL_CERT_CHAIN_PATH:""}

在 OpenTelemetry Collector 配置文件中加入自监控的参数

receivers:
  prometheus:
    config:
     scrape_configs:
       - job_name: 'vm-monitoring'
         scrape_interval: 5s
         static_configs:
           - targets: ['10.10.2.145:9100']
             labels:
               host_name: 10.10.2.145
               service: skywalking-oap-server
  prometheus/2:  #新增
    config:
     scrape_configs:
       - job_name: 'skywalking-so11y'  #要与skywalking-oap中的otel-rules的oap.yaml中的名称保持一致
         scrape_interval: 5s
         static_configs:
           - targets: ['10.10.2.145:1234']   #端口为1234
             labels:
               host_name: 10.10.2.145_self
               service: skywalking-oap


processors:
  batch:
  batch/2:

exporters:
  otlp:
    endpoint: 10.10.2.145:11800
    tls:
      insecure: true
  logging:
    loglevel: debug
  otlp/2:
    endpoint: 10.10.2.145:11800
    tls:
      insecure: true
  logging/2:
    loglevel: debug

service:
  pipelines:
    metrics:
      receivers: [prometheus, prometheus/2]
      processors: [batch, batch/2]
      exporters: [otlp, otlp/2, logging, logging/2]

依次重启 otelcol 容器和 skywalking-oap,查看是否生成自监控。

开启数据库 MySQL/MariaDB 监控#

(1)部署 mysqld_exporter

services:
  mysqld_exporter:
    image: prom/mysqld-exporter
    container_name: mysqld_exporter
    restart: always
    environment:
      - TZ=Asia/Shanghai
    ports:
      - "9104:9104"
    command:
      - "--mysqld.username=user:password"   #用户名和密码
      - "--mysqld.address=10.10.2.145:3306"   #ip和端口号
    networks:
       sw-mysql:
        ipv4_address: 172.20.102.11

networks:
  sw-mysql:
    driver: bridge
    ipam:
      config:
        - subnet: 172.20.102.0/24

(2) 在 OpenTelemetry Collector 配置文件中 mysql 的监控参数

receivers:
  prometheus:
    config:
     scrape_configs:
       - job_name: 'vm-monitoring'
         scrape_interval: 5s
         static_configs:
           - targets: ['10.10.2.145:9100']
             labels:
               host_name: 10.10.2.145
               service: skywalking-oap-server
  prometheus/2:
    config:
     scrape_configs:
       - job_name: 'skywalking-so11y'
         scrape_interval: 5s
         static_configs:
           - targets: ['10.10.2.145:1234']
             labels:
               host_name: 10.10.2.145_self
               service: skywalking-oap

  prometheus/3:  #mysql、mariadb的监控部分
    config:
     scrape_configs:
       - job_name: 'mysql-monitoring' #要与skywalking-oap中的otel-rules/mysql目录中的yaml文件中的名称保持一致
         scrape_interval: 5s
         static_configs:
           - targets: ['10.10.2.145:9104']
             labels:
               host_name: mariadb-monitoring

processors:
  batch:
  batch/2:
  batch/3:

exporters:
  otlp:
    endpoint: 10.10.2.145:11800
    tls:
      insecure: true
  logging:
    loglevel: debug
  otlp/2:
    endpoint: 10.10.2.145:11800
    tls:
      insecure: true
  logging/2:
    loglevel: debug
  otlp/3:
    endpoint: 10.10.2.145:11800
    tls:
      insecure: true
  logging/3:
    loglevel: debug

service:
  pipelines:
    metrics:
      receivers:
      - prometheus
      - prometheus/2
      - prometheus/3
      processors:
      - batch
      - batch/2
      - batch/3
      exporters:
      - otlp
      - otlp/2
      - otlp/3
      - logging
      - logging/2
      - logging/3

依次重启 otelcol 容器和 skywalking-oap,查看是否生成 mysql 或 mariadb 的监控数据。

开启 Elasticsearch 监控#

(1)部署 elasticsearch_exporter

services:
  elasticsearch_exporter:
    image: quay.io/prometheuscommunity/elasticsearch-exporter:latest
    container_name: elasticsearch_exporter
    restart: always
    environment:
      - TZ=Asia/Shanghai
    ports:
      - "9114:9114"
    command:
      #- '--es.uri=http://elastic:[email protected]:9200'   #es使用http协议
      - '--es.uri=https://elastic:[email protected]:9200' 
      - "--es.ssl-skip-verify"   #连接到es时跳过SSL验证
    networks:
       es_exporter:
        ipv4_address: 172.20.103.11

networks:
  es_exporter:
    driver: bridge
    ipam:
      config:
        - subnet: 172.20.103.0/24

(2)在 OpenTelemetry Collector 配置文件中 es 的监控参数

receivers:
  prometheus:
    config:
     scrape_configs:
       - job_name: 'elasticsearch-monitoring'
         scrape_interval: 5s
         static_configs:
           - targets: ['10.10.2.145:9114']
             labels:
               host_name: elasticsearch-monitoring


processors:
  batch:

exporters:
  otlp:
    endpoint: 10.10.2.145:11800
    tls:
      insecure: true
  logging:
    loglevel: debug

service:
  pipelines:
    metrics:
      receivers:
      - prometheus
      processors:
      - batch
      exporters:
      - otlp
      - logging

依次重启 otelcol 容器和 skywalking-oap,查看是否生成 es 的监控数据。

开启数据库 PostgreSQL 监控#

(1)部署 postgres-exporter

services:
  postgres-exporter:
    image: quay.io/prometheuscommunity/postgres-exporter
    container_name: postgres-exporter
    restart: always
    environment:
      TZ: "Asia/Shanghai"
      DATA_SOURCE_URI: "localhost:5432/postgres?sslmode=disable"
      DATA_SOURCE_USER: "postgres"
      DATA_SOURCE_PASS: "password"
    ports:
      - "9187:9187"
    networks:
       sw-pgsql:
        ipv4_address: 172.20.105.11

networks:
  sw-pgsql:
    driver: bridge
    ipam:
      config:
        - subnet: 172.20.105.0/24

(2)在 OpenTelemetry Collector 配置文件中 postgres sql 的监控参数

receivers:
  prometheus:
    config:
     scrape_configs:
       - job_name: 'postgresql-monitoring'
         scrape_interval: 5s
         static_configs:
           - targets: ['10.10.2.145:9187']
             labels:
               host_name: postgresql-monitoring


processors:
  batch:

exporters:
  otlp:
    endpoint: 10.10.2.145:11800
    tls:
      insecure: true
  logging:
    loglevel: debug

service:
  pipelines:
    metrics:
      receivers:
      - prometheus
      processors:
      - batch
      exporters:
      - otlp
      - logging

依次重启 skywalking-oap 容器和 otelcol,查看是否生成 postgres sql 的监控数据。

开启数据库 MongoDB 监控#

(1)部署 mongodb_exporter

services:
  mongodb_exporter:
    image: percona/mongodb_exporter:0.40
    container_name: mongodb_exporter
    restart: always
    ports:
      - "9216:9216"
    environment:
      - TZ=Asia/Shanghai
      - MONGODB_URI=mongodb://user:[email protected]:27017/?authSource=admin
    command:
      - --collect-all
      - --web.listen-address=:9216
    networks:
       sw-mongodb:
        ipv4_address: 172.20.106.11

networks:
  sw-mongodb:
    driver: bridge
    ipam:
      config:
        - subnet: 172.20.106.0/24

(2) 在 OpenTelemetry Collector 配置文件中 mongodb 的监控参数

receivers:
  prometheus:
    config:
     scrape_configs:
       - job_name: 'mongodb-monitoring'
         scrape_interval: 5s
         static_configs:
           - targets: ['10.10.2.145:9216']
             labels:
               host_name: mongodb-monitoring


processors:
  batch:

exporters:
  otlp:
    endpoint: 10.10.2.145:11800
    tls:
      insecure: true
  logging:
    loglevel: debug

service:
  pipelines:
    metrics:
      receivers:
      - prometheus
      processors:
      - batch
      exporters:
      - otlp
      - logging

.NET 项目服务链路追踪#

安装 SkyWalking .NET Core Agent(Windows 环境)#

(1)在 Visual Studio 中的项目中安装nugetSkyAPM.Agent.AspNetCore

(2)在launchSettings.json文件中新增环境变量"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "SkyAPM.Agent.AspNetCore""SKYWALKING__SERVICENAME": "服务名(与执行的dll程序的名称一致)"

  "profiles": {
    "http": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "http://localhost:5205",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        //新增环境变量
        "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "SkyAPM.Agent.AspNetCore",
        "SKYWALKING__SERVICENAME": "服务名(与执行的dll程序的名称一致)"
      }
    },
    "https": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "https://localhost:7105;http://localhost:5205",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        //新增环境变量
        "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "SkyAPM.Agent.AspNetCore",
        "SKYWALKING__SERVICENAME": "服务名(与执行的dll程序的名称一致)"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
         //新增环境变量
        "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "SkyAPM.Agent.AspNetCore",
        "SKYWALKING__SERVICENAME": "服务名(与执行的dll程序的名称一致)"
      }
    }
  }
,

(3)在 Program.cs 中添加配置参数。

//SkyApm
builder.Services.AddSkyApmExtensions();
Environment.SetEnvironmentVariable
("ASPNETCORE_HOSTINGSTARTUPASSEMBLIES", "SkyAPM.Agent.AspNetCore");
Environment.SetEnvironmentVariable("SKYWALKING__SERVICENAME", "服务名(与执行的dll程序的名称一致)");

(4)添加 skyapm.json 文件,添加方式有两种:

一是在 dll 运行程序的同目录下创建 skyapm.json,并写入以下内容。

{
  "SkyWalking": {
    "ServiceName": "服务名(与执行的dll程序的名称一致)",
    "Namespace": "",
    "HeaderVersions": [
      "sw8"
    ],
    "Sampling": {
      "SamplePer3Secs": -1,
      "Percentage": -1.0
    },
    "Logging": {
      "Level": "Information",
      "FilePath": "logs\\skyapm-{Date}.log"
    },
    "Transport": {
      "Interval": 3000,
      "ProtocolVersion": "v8",
      "QueueSize": 30000,
      "BatchSize": 3000,
      "gRPC": {
        "Servers": "SkyWalking服务ip:11800",
        "Timeout": 10000,
        "ConnectTimeout": 10000,
        "ReportTimeout": 600000,
        "Authentication": ""
      }
    }
  }
}

二是在 Visual Studio 的控制台中输入命令创建 skyapm.json。

dotnet tool install -g SkyAPM.DotNet.CLI
dotnet skyapm config 服务名(与执行的dll程序的名称一致) SkyWalking服务ip:11800

(5)配置完成后,在运行的服务器中加入环境变量

方式一:在服务器添加

vi  ~/.bashrc


export ASPNETCORE_ENVIRONMENT=development
export ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=SkyAPM.Agent.AspNetCore
export SKYWALKING__SERVICENAME=服务名


#使得配置生效
source ~/.bashrc

方式二:在容器中添加,可在 Dockerfile 文件中添加

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
......
ENV ASPNETCORE_ENVIRONMENT=development
ENV ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=SkyAPM.Agent.AspNetCore
ENV SKYWALKING__SERVICENAME=服务名
#容器入口点
ENTRYPOINT ["dotnet", "xxx"]

(6)访问.NET 项目,查看 Skywalking 中常规服务 - 服务中生成的服务监控。(效果图在最后)

安装 SkyWalking .NET Core Agent(Linux 环境)#

适用于在 Linux 上创建的.NET 项目

(1)安装 SkyWalking .NET Core Agent

dotnet add package SkyAPM.Agent.AspNetCore
export ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=SkyAPM.Agent.AspNetCore
export SKYWALKING__SERVICENAME=服务名(与执行的dll程序的名称一致)

(2)安装 SkyAPM.DotNet.CLI,用于生成 skyapm.json

dotnet tool install -g SkyAPM.DotNet.CLI
dotnet skyapm config 服务名(与执行的dll程序的名称一致) SkyWalking服务ip:11800

(3)配置完成后,在运行的服务器中加入环境变量

方式一:在服务器添加

vi  ~/.bashrc


export ASPNETCORE_ENVIRONMENT=development
export ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=SkyAPM.Agent.AspNetCore
export SKYWALKING__SERVICENAME=服务名


#使得配置生效
source ~/.bashrc

方式二:在容器中添加,可在 Dockerfile 文件中添加

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
......
ENV ASPNETCORE_ENVIRONMENT=development
ENV ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=SkyAPM.Agent.AspNetCore
ENV SKYWALKING__SERVICENAME=服务名
#容器入口点
ENTRYPOINT ["dotnet", "xxx"]

(4)访问.NET 项目,查看 Skywalking 中常规服务 - 服务中生成的服务监控。

1

接入前端监控#

(1)项目中添加 skywalking-client-js 包

npm install skywalking-client-js --save

(2)在 vue.config.js 中配置代理

proxy:{
      '/browser': {
        target:'SkyWalking服务ip:12800',//这里是路由和报错报告的代理
        changeOrigin: true
      },
      '/v3':{
        target:'SkyWalking服务ip:12800',
        changeOrigin: true//这里是追踪报告的代理
      }
}

(3)在 main.js 中接入 skywalking-client-js

//skywalking监控系统
import ClientMonitor from 'skywalking-client-js';
//注册skywalking
ClientMonitor.register({
    service: '服务名',//服务名称        
    serviceVersion:'',//应用版本号
    traceSDKInternal:true,//追踪sdk
    pagePath: location.href,//当前路由地址
    useFmp: true
});

(4) 在对应业务系统的服务器中,在对应发布 nignx 代理服务中加入对应的代理配置。

    location /browser/ {
        proxy_pass http://SkyWalking服务ip:12800/browser/;
        client_max_body_size 1000M;
    }
        location /v3/ {
        proxy_pass http://SkyWalking服务ip:12800/v3/;
        client_max_body_size 1000M;
    }
加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。