:你只管努力,剩下的交给时间
:小破站
在当今微服务架构的世界中,了解和监控系统的运行状态至关重要。本文将带你进入一个有趣的探险,使用Docker-Compose一键搭建起SkyWalking、Elasticsearch和Spring Cloud的完整监控平台。无需复杂的配置,让我们一起开始这场容器化监控的冒险之旅。
docker常用命令
docker-compose文件详解以及常用命令
version: "3"
services:
# SkyWalking OAP server with Elasticsearch storage
skywalking-oap:
image: apache/skywalking-oap-server:8.9.0
container_name: skywalking-oap
ports:
- "12800:12800"
- "11800:11800"
networks:
- skywalking-network
depends_on:
- skywalking-elasticsearch
environment:
- SW_STORAGE=elasticsearch
- TZ=Asia/Shanghai
- SW_STORAGE_ES_CLUSTER_NODES=192.168.100.118:19200
#volumes:
# - ./oap-config:/skywalking/config # 挂载本地目录到容器中
# Elasticsearch
skywalking-elasticsearch:
image: elasticsearch:7.16.3
container_name: skywalking-elasticsearch
ports:
- "19200:9200"
- "19300:9300"
networks:
- skywalking-network
environment:
- discovery.type=single-node
- TZ=Asia/Shanghai
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
mem_limit: 2g
#volumes:
# - ./es-data:/usr/share/elasticsearch/data/nodes # 挂载本地目录到容器中
# SkyWalking UI
skywalking-ui:
image: apache/skywalking-ui:8.9.0
container_name: skywalking-ui
ports:
- "18080:8080"
networks:
- skywalking-network
environment:
- SW_OAP_ADDRESS=http://192.168.100.118:12800
- TZ=Asia/Shanghai
volumes:
- ./ui-config:/app/config # 挂载本地目录到容器中
networks:
skywalking-network:
driver: bridge
针对上面的yml我下面提几点
因为我使用的是mac系统,本机与docker不通讯,这里如果你是linux,可以直接写service
因为11800端口是服务中gRPC端口,在整合springcloud的时候需要用到
从报错日志可以清楚的观察到,没有找到STORAGE,这里我猜测是因为es还没有完全启动导致的,即使加上depends_on
好像也没作用,你也可以设置总是重启,或者手动重启一下
skywalking-agent,找到你对应版本即可
<dependency>
<groupId>org.apache.skywalkinggroupId>
<artifactId>apm-toolkit-traceartifactId>
dependency>
<dependency>
<groupId>org.apache.skywalkinggroupId>
<artifactId>apm-toolkit-logback-1.xartifactId>
dependency>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="PATTERN_DEFAULT" value="%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- [%thread] [%tid] %-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
<pattern>${PATTERN_DEFAULT}pattern>
layout>
encoder>
appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
<pattern>${PATTERN_DEFAULT}pattern>
layout>
encoder>
<file>${LOG_FILE}file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOGBACK_ROLLINGPOLICY_FILE_NAME_PATTERN:-${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz}fileNamePattern>
<cleanHistoryOnStart>${LOGBACK_ROLLINGPOLICY_CLEAN_HISTORY_ON_START:-false}cleanHistoryOnStart>
<maxFileSize>${LOGBACK_ROLLINGPOLICY_MAX_FILE_SIZE:-10MB}maxFileSize>
<totalSizeCap>${LOGBACK_ROLLINGPOLICY_TOTAL_SIZE_CAP:-0}totalSizeCap>
<maxHistory>${LOGBACK_ROLLINGPOLICY_MAX_HISTORY:-30}maxHistory>
rollingPolicy>
appender>
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>0discardingThreshold>
<queueSize>256queueSize>
<appender-ref ref="FILE"/>
appender>
<appender name="GRPC" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
<pattern>${PATTERN_DEFAULT}pattern>
layout>
encoder>
appender>
<springProfile name="local">
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="GRPC"/>
<appender-ref ref="ASYNC"/>
root>
springProfile>
<springProfile name="dev,test,stage,prod,default">
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="ASYNC"/>
<appender-ref ref="GRPC"/>
root>
springProfile>
configuration>
这里一定要注意,配置到环境变量我的没有作用,配置到vm才可行
# 第一个是你服务名称,第二个是对应的skywalking-agent.jar,第三个是你skywalking-aop-server的gRPC地址
-Dskywalking.agent.service_name=study-gateway -javaagent:/Users/xiaobo/webSoft/skywalking-agent/skywalking-agent.jar -Dskywalking.collector.backend_service=127.0.0.1:11800
:springcloud项目启动实现效果图如下