栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Docker搭建Skywalking环境

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Docker搭建Skywalking环境

搭建skywalking需要用到三个镜像:
elasticsearch:用来存储数据
skywalking-oap-server:Skywalking服务器
skywalking-ui :Skywalking的UI界面

下载镜像
docker pull elasticsearch:7.9.0
docker pull apache/skywalking-oap-server:8.9.1
docker pull apache/skywalking-ui:8.9.1
Docker 单独镜像安装 安装elasticsearch 本机创建持久化目录,官方推荐
mkdir -p /Users/admin/Documents/data/elasticsearch/data
mkdir -p /Users/admin/Documents/data/elasticsearch/logs
持久化启动elasticsearch

安装elasticsearch并挂载文件

docker run -d --name=es7 
--restart=always 
-p 9200:9200 -p 9300:9300 
-e "discovery.type=single-node" 
-v /Users/admin/Documents/data/elasticsearch/data:/usr/share/elasticsearch/data 
-v /Users/admin/Documents/data/elasticsearch/logs:/usr/share/elasticsearch/logs 
elasticsearch:7.9.0
查看启动情况
docker ps -a
查看镜像日志
docker logs -f es7
验证ES

浏览器访问:http://localhost:9200/,返回:

{
  "name" : "a0455020b01a",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "AFy_WI-iQa63pVug9XIUXQ",
  "version" : {
    "number" : "7.9.0",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "a479a2a7fce0389512d6a9361301708b92dff667",
    "build_date" : "2020-08-11T21:36:48.204330Z",
    "build_snapshot" : false,
    "lucene_version" : "8.6.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
安装skywalking-oap

需要先安装好es才能安装opa

启动 skywalking-oap
docker run --name oap --restart=always -d 
-e TZ=Asia/Shanghai 
-p 12800:12800 
-p 11800:11800 
--link es7:es7 
-e SW_STORAGE=elasticsearch7 
-e SW_STORAGE_ES_CLUSTER_NODES=es7:9200 
apache/skywalking-oap-server:8.9.0

-e TZ=Asia/Shanghai:指定时区。
--link es7:es7:关联es7容器,通过容器名字来解决ip会发生变更的问题。
-e SW_STORAGE=elasticsearch:设置环境变量,指定存储方式。
-e SW_STORAGE_ES_CLUSTER_NODES=es7:9200:设置环境变量,指定ES的地址

登录容器
docker exec -it oap bash 
安装skywalking-ui

启动UI

docker run -d --name skywalking-ui 
--restart=always 
-e TZ=Asia/Shanghai 
-p 8088:8080 
--link oap:oap 
-e SW_OAP_ADDRESS=oap:12800 
apache/skywalking-ui:8.9.0

访问UI:http://localhost:8088/

docker-compose 安装 编写docker-compose.yml文件

https://github.com/apache/skywalking/tree/master/docker 官网有示例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.

# 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-oss:${ES_VERSION}
    image: elasticsearch:7.9.0
    container_name: elasticsearch
    # --restart=always : 开机启动,失败也会一直重启;
    # --restart=on-failure:10 : 表示最多重启10次
    restart: always
    ports:
      - "9200:9200"
      - "9300:9300"
    healthcheck:
      test: [ "CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1" ]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
    environment:
      - discovery.type=single-node
      # 锁定物理内存地址,防止elasticsearch内存被交换出去,也就是避免es使用swap交换分区,频繁的交换,会导致IOPS变高;
      - bootstrap.memory_lock=true
      # 设置时区
      - TZ=Asia/Shanghai
      # - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1

  oap:
    image: apache/skywalking-oap-server:8.9.1
    container_name: oap
    restart: always
    # 设置依赖的容器
    depends_on:
      elasticsearch:
        condition: service_healthy
    # 关联ES的容器,通过容器名字来找到相应容器,解决IP变动问题
    links:
      - elasticsearch
    # 端口映射
    ports:
      - "11800:11800"
      - "12800:12800"
    # 监控检查
    healthcheck:
      test: [ "CMD-SHELL", "/skywalking/bin/swctl ch" ]
      # 每间隔30秒执行一次
      interval: 30s
      # 健康检查命令运行超时时间,如果超过这个时间,本次健康检查就被视为失败;
      timeout: 10s
      # 当连续失败指定次数后,则将容器状态视为 unhealthy,默认 3 次。
      retries: 3
      # 应用的启动的初始化时间,在启动过程中的健康检查失效不会计入,默认 0 秒。
      start_period: 10s
    environment:
      # 指定存储方式
      SW_STORAGE: elasticsearch
      # 指定存储的地址
      SW_STORAGE_ES_CLUSTER_NODES: elasticsearch:9200
      SW_HEALTH_CHECKER: default
      SW_TELEMETRY: prometheus
      TZ: Asia/Shanghai
      # JAVA_OPTS: "-Xms2048m -Xmx2048m"

  ui:
    image: apache/skywalking-ui:8.9.1
    container_name: skywalking-ui
    restart: always
    depends_on:
      oap:
        condition: service_healthy
    links:
      - oap
    ports:
      - "8088:8080"
    environment:
      SW_OAP_ADDRESS: http://oap:12800
      TZ: Asia/Shanghai
启动容器

切换到docker-compose.yml文件下,然后执行一下命令:

docker-compose up -d
查看启动镜像
docker-compose ps
浏览器验证

访问网址 http://localhost:8088/

下载agent
  1. 下载源码包,然后解压取agent目录
    https://archive.apache.org/dist/skywalking/8.9.1/

    https://skywalking.apache.org/downloads/
    解压获得agent.jar。

  2. 修改conf配置文件
    将地址改为skywalking地址

agent.service_name=${SW_AGENT_NAME:Your_ApplicationName}
agent.instance_name=${SW_AGENT_INSTANCE_NAME:}
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:127.0.0.1:11800}
  1. 启动文件配置agent
-javaagent:/skywalking-agent/skywalking-agent.jar -Dskywalking.agent.service_name=demoskywalking -Dskywalking.collector.backend_service=127.0.0.1:11800


jar包方式

java -javaagent:/skywalking-agent/agent/skywalking-agent.jar
-Dskywalking.agent.service_name=app-service 
-Dskywalking.collector.backend_service=127.0.0.1:11800
-jar app-service.jar &
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/851432.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号