docker run --name skywalking-oap \
--restart always \
-p 11800:11800 -p 12800:12800 -d \
-e TZ=Asia/Shanghai \
-e SW_ES_USER= \
-e SW_ES_PASSWORD= \
-e SW_STORAGE=elasticsearch7 \
-e SW_STORAGE_ES_CLUSTER_NODES=172.16.0.213:9200 \
-v /etc/localtime:/etc/localtime:ro \
apache/skywalking-oap-server:8.6.0-es7
docker run -d \
--name skywalking-ui \
--restart always \
-p 9898:8080 \
--link skywalking-oap:skywalking-oap \
-e TZ=Asia/Shanghai \
-e SW_OAP_ADDRESS=skywalking-oap:12800 \
-v /etc/localtime:/etc/localtime:ro \
apache/skywalking-ui:8.6.0
docker run -d \
-p 9200:9200 \
-p 9300:9300 \
--name='elasticsearch' \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms512m -Xmx512m" \
-e TZ=Asia/Shanghai \
-v /etc/localtime:/etc/localtime:ro \
elasticsearch:7.6.2
更新Dockerfile配置
FROM java
MAINTAINER xxxx@qq.com
WORKDIR /workspace
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
COPY agent /agent/
ADD demo1-0.0.1-SNAPSHOT.jar /workspace/
ENTRYPOINT ["java","-javaagent:/agent/skywalking-agent.jar","-Dskywalking.agent.service_name=demo-api","-Duser.timezone=GMT+08","-Xms4096m","-Xmx4096m", "-jar", "/workspace/demo1-0.0.1-SNAPSHOT.jar"]
去官网下载包 拷贝其中的agent目录 到Dockerfile同级目录下
https://archive.apache.org/dist/skywalking/8.6.0/apache-skywalking-apm-8.6.0.tar.gz
修改agent/config/agent.config如下配置:
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:172.16.0.213:11800}
agent/config/agent.config 新增如下配置:
plugin.toolkit.log.grpc.reporter.server_host=${SW_GRPC_LOG_SERVER_HOST:172.16.0.213}
plugin.toolkit.log.grpc.reporter.server_port=${SW_GRPC_LOG_SERVER_PORT:11800}
plugin.toolkit.log.grpc.reporter.max_message_size=${SW_GRPC_LOG_MAX_MESSAGE_SIZE:10485760}
plugin.toolkit.log.grpc.reporter.upstream_timeout=${SW_GRPC_LOG_GRPC_UPSTREAM_TIMEOUT:30}
pom.xml
在<dependencies>标签中 新增如下依赖:
<dependencies>
<!-- logback-spring.xml skywalking链路追踪日志依赖-->
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-trace</artifactId>
<version>8.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-logback-1.x</artifactId>
<version>8.6.0</version>
</dependency>
</dependencies>
新增文件logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 引入 Spring Boot 默认的 logback XML 配置文件 -->
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<appender name="console" 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>-%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} [%tid] %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}</Pattern>
</layout>
</encoder>
</appender>
<appender name="grpc‐log" 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.mdc.TraceIdMDCPatternLogbackLayout">
<Pattern>%d{yyyy‐MM‐dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} ‐%msg%n</Pattern>
</layout>
</encoder>
</appender>
<!-- 指定获取日志类型 -->
<root level="INFO">
<appender-ref ref="console"/>
<appender-ref ref="grpc‐log"/>
</root>
</configuration>
更新配置application.yml 指定es存储 / 也可选择mysql持久化存储
我用ES7版本存储
elasticsearch7:
nameSpace: ${SW_NAMESPACE:""}
clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:172.16.0.213:9200}
nacos:
# Nacos Server Host
serverAddr: ${SW_CONFIG_NACOS_SERVER_ADDR:172.16.0.213}
# Nacos auth username
username: ${SW_CONFIG_NACOS_USERNAME:"xxx"}
password: ${SW_CONFIG_NACOS_PASSWORD:"xxx"}
观察TID
image.png
之后可配置如下 选择不输出TID在控制台
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
image.png
image.png
网友评论