一、 docker部署SkyWalking
使用8.5.0-ese6版本,H2数据存储
- 拉取镜像
docker pull apache/skywalking-base:8.5.0-es6
docker pull apache/skywalking-oap-server:8.5.0-es6
docker pull apache/skywalking-ui:8.5.0
- 创建容器
# 服务端
docker run --name oap --restart always -p 1234:1234 -p 11800:11800 -p 12800:12800 -d apache/skywalking-oap-server:8.5.0-es6
# UI端
docker run --name oap-ui --restart always -p 8080:8080 --link oap:oap -e SW_OAP_ADDRESS=oap:12800 -d apache/skywalking-ui:8.5.0
- 访问地址:http://127.0.0.1:8080
二、 Spring添加agent
- skywalking包下载地址
https://archive.apache.org/dist/skywalking/8.5.0/apache-skywalking-apm-8.5.0.tar.gz
- 拷贝压缩包内agent到spring项目目录下,修改config/agent.config
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:127.0.0.1:11800}
# 为了支持log4j2,日志采集
plugin.toolkit.log.grpc.reporter.server_host=${SW_GRPC_LOG_SERVER_HOST:127.0.0.1}
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}
- 创建spring容器
docker run --name ml --restart always -p 8080:8080 -v /server:/server -e TZ=Asia/Shanghai -d adoptopenjdk/openjdk8-openj9 java -javaagent:/server/agent/skywalking-agent.jar -Dskywalking.agent.service_name=serverName -jar /server/application.jar --spring.config.location=/server/application.properties
image.png
三、 skywalking 日志采集
pom.xml添加
<!--skywalking-->
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-trace</artifactId>
<version>8.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-log4j-2.x</artifactId>
<version>8.5.0</version>
</dependency>
在resources目录下,创建log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}{GMT+8} [%t] %-5level %logger{36} [%traceId] - %msg%n"/>
</Console>
<GRPCLogClientAppender name="grpc-log">
<PatternLayout pattern="%msg%n"/>
</GRPCLogClientAppender>
<RollingRandomAccessFile name="randomFile" fileName="/server/log/ml.log" filePattern="/server/log/ml-%d{yyyy-MM-dd}-%i.log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}{GMT+8} [%t] %-5level %logger{36} [%traceId] - %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="1"/>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
</RollingRandomAccessFile>
<Async name="asyncAppender">
<AppenderRef ref="randomFile"/>
</Async>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
<AppenderRef ref="grpc-log"/>
<AppenderRef ref="asyncAppender"/>
</Root>
</Loggers>
</Configuration>
使用log4j
private final Logger logger = LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);
image.png
四、 启动自检测
- 修改config/application.yml文件telemetry配置
prometheus-fetcher:
selector: ${SW_PROMETHEUS_FETCHER:default} # 改成defaulg
default:
enabledRules: ${SW_PROMETHEUS_FETCHER_ENABLED_RULES:"self"}
telemetry:
selector: ${SW_TELEMETRY:prometheus} # 改成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:""}
- 重启oap服务
docker restart oap
image.png
网友评论