.netcore3.1使用skywalking8.1.0(docker-compose一鍵部署)


1、安裝Skywalking環境

這里我使用的是docker-compose一鍵安裝的方式,docker-compose有三種方式可安裝:

(我選擇的是第二種方式安裝)

1.1>參見官網:https://docs.docker.com/compose/install/

 

1.1.1>下載docker compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

1.1.2>添加可執行權限

sudo chmod +x /usr/local/bin/docker-compose

1.1.3>將文件copy到 /usr/bin/目錄下

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

1.1.4>查看版本

docker-compose –version

 

1.2>通過pip進行安裝

1.2.1>安裝pip

yum -y install epel-release
yum -y install python-pip

查看版本

pip –version

1.2.2>更新pip

pip install --upgrade pip

1.2.3>安裝docker-compose

pip install docker-compose

1.2.4>查看docker compose的版本

docker-compose version

 

1.3>離線安裝

訪問https://github.com/docker/compose/releases,下載 docker-compose-Linux-x86_64,將docker-compose-Linux-x86_64重命名為docker-compose

通過ssh工具MobaXterm,將剛才下載的docker-compose文件上傳到centos7的/usr/local/bin/目錄下

輸入以下命令 添加可執行權限和查看docker compose版本:

# 添加可執行權限
sudo chmod +x /usr/local/bin/docker-compose
# 查看docker-compose版本
docker-compose -v

 

2、一鍵部署skywalking

2.1>創建文件夾skywalking,並切換到該目錄下:

mkdir skywalking
cd skywalking

2.2>創建文件docker-compose.yml,寫入內容:

內容參見:https://github.com/apache/skywalking-docker/blob/master/8/8.1.0/compose-es7/docker-compose.yml,直接用即可,可視具體情況修改參數

vi docker-compose.yml

# 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.

version: '3.8'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.5.0
    container_name: elasticsearch
    restart: always
    ports:
      - 9200:9200
    healthcheck:
      test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    environment:
      - discovery.type=single-node
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
  oap:
    image: apache/skywalking-oap-server:8.1.0-es7
    container_name: oap
    depends_on:
      - elasticsearch
    links:
      - elasticsearch
    restart: always
    ports:
      - 11800:11800
      - 12800:12800
    healthcheck:
      test: ["CMD-SHELL", "/skywalking/bin/swctl"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    environment:
      SW_STORAGE: elasticsearch7
      SW_STORAGE_ES_CLUSTER_NODES: elasticsearch:9200
  ui:
    image: apache/skywalking-ui:8.1.0
    container_name: ui
    depends_on:
      - oap
    links:
      - oap
    restart: always
    ports:
      - 8080:8080
    environment:
      SW_OAP_ADDRESS: oap:12800
View Code

Insert切換插入模式;按Esc,輸入:wq,保存並退出vi編輯

2.3>執行docker-compose.yml

docker-compose up -d

(偶爾可能會因為網絡原因失敗,重新執行命令即可)

2.4>skywalking部署完成之后,可正常訪問:es和ui(IP地址根據實際情況輸入)

http://192.168.56.10:9200/

http://192.168.56.10:8080/

正常打開無報錯信息即可

 

3、.NetCore使用SkyWalking(已創建好WebAPI工程)

3.1>引用包SkyAPM.Agent.AspNetCore,記得為1.0.0版本;

在根目錄創建skyapm.json文件,並設置復制到輸出目錄:如果較新則復制

寫入內容:

{
  "SkyWalking": {
    "ServiceInstanceName": "OpenServiceInstance",
    "ServiceName": "OpenService",
    "Logging": {
      "Level": "Information",
      "FilePath": "logs\\skyapm-{Date}.log"
    },
    "Transport": {
      "Interval": 3000,
      "QueueSize": 30000,
      "BatchSize": 3000,
      "gRPC": {
        "Servers": "192.168.56.10:11800",
        "Timeout": 10000,
        "ConnectTimeout": 10000,
        "ReportTimeout": 600000
      }
    }
  }
}

ServiceName為服務名稱,ServiceInstanceName為實例名稱,Servers為skywalking收集器地址,只需要改動該三項即可

3.2> 配置啟動環境變量

在launchSettings.json中增加環境變量配置:

"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "SkyAPM.Agent.AspNetCore"

運行起來並任意訪問一個api地址,然后在skywalking-ui中可追溯api訪問記錄:

(時間范圍記得根據實際情況選擇)

 

 

大功告成

部分參考:

https://www.cnblogs.com/xwgli/p/13827042.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM