SkyWalking APM
tar 下载
结合自己的es版本下载对应的tar
地址:https://archive.apache.org/dist/skywalking/
由于我使用的是es7所以下载对应版本
拷贝对应链接使用wget下载
wget https://archive.apache.org/dist/skywalking/8.7.0/apache-skywalking-apm-es7-8.7.0.tar.gz
oap与webapp部署
- 解压
tar -zxvf apache-skywalking-apm-es7-8.7.0.tar.gz cd apache-skywalking-apm-bin-es7/
- 修改oap配置
vim config/application.yml
storage:selector: ${SW_STORAGE:elasticsearch7} # 我使用的是es将 h2 改为:elasticsearch7
...elasticsearch7:nameSpace: ${SW_NAMESPACE:"skywalking"} # 存储在es中索引的前缀clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:localhost:9200} # 改为对应es的ip端口
- 修改webapp配置
vim webapp/webapp.yml
server:port: 8080 # webapp 启动端口spring:cloud:gateway:routes:- id: oap-routeuri: lb://oap-servicepredicates:- Path=/graphql/**discovery:client:simple:instances:oap-service:- uri: http://127.0.0.1:12800 #oap ip端口由于我webapp和oap是本机所以使用127.0.0.1
- 启动
sh bin/startup.sh
日志默认存放目录
logs/skywalking-oap-server.log
- 访问
[webapp ip]:[webapp 启动端口]
例如 192.168.9.56:8080
agent部署
由于我使用apache-skywalking-apm-es7-8.7.0.tar.gz 自带的agent会导致日志收集ip:端口无效所以使用了8.14.0agent
下载地址 https://archive.apache.org/dist/skywalking/java-agent/8.14.0/
wget https://archive.apache.org/dist/skywalking/java-agent/8.14.0/apache-skywalking-java-agent-8.14.0.tgz
tar -zxvf apache-skywalking-java-agent-8.14.0.tgz
- spingboot项目配置 添加mvn配置
<dependency><groupId>org.apache.skywalking</groupId><artifactId>apm-toolkit-logback-1.x</artifactId><version>8.14.0</version></dependency><dependency><groupId>org.apache.skywalking</groupId><artifactId>apm-toolkit-trace</artifactId><version>8.14.0</version></dependency>
- agent 配置
再次说明配置方式有3种
我只有在第一种配置时 日志收集ip:端口才会有效后门两种无效- 方式一 修改agent配置,进入解压的agent目录
cd /usr/local/src/skywalking-agent vim config/agent.config
collector.backend_service=192.168.9.56:11800 agent.service_name=demo
-javaagent:/usr/local/src/skywalking-agent/skywalking-agent.jar
-
方式二 启动参数上添加如下配置(idea启动自行百度如何添加启动参数)
/usr/local/src/skywalking-agent/skywalking-agent.jar 改为自己的skywalking-agent.jar路径
agent.service_name 为服务名
collector.backend_service 为日志收集ip端口即上面oap的ip加上端口-javaagent:/usr/local/src/skywalking-agent/skywalking-agent.jar=agent.service_name=demo,collector.backend_service=192.168.9.56:11800
-
方式三 启动参数上添加如下配置(idea启动自行百度如何添加启动参数)
-javaagent:/usr/local/src/skywalking-agent/skywalking-agent.jar-Dskywalking.agent.service_name=demo-Dskywalking.collector.backend_service=192.168.9.56:11800
- 方式一 修改agent配置,进入解压的agent目录
- agent 日志配置示例
<!-- Logback configuration. See http://logback.qos.ch/manual/index.html -->
<configuration scan="true" scanPeriod="10 seconds"><include resource="org/springframework/boot/logging/logback/base.xml" /><property name="SERVICE_NAME" value="edm"/><springProperty scope="context" name="${SERVICE_NAME}" source="spring.application.name" /><appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"><filter class="ch.qos.logback.classic.filter.ThresholdFilter"><level>INFO</level></filter><File>${HOME}/logs/edm/${SERVICE_NAME}-info.log</File><rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><fileNamePattern>${HOME}/logs/edm/${SERVICE_NAME}-info-%d{yyyyMMdd}.log.%i</fileNamePattern><timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"><maxFileSize>500MB</maxFileSize></timeBasedFileNamingAndTriggeringPolicy><maxHistory>15</maxHistory></rollingPolicy><encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"><layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"><Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%tid] [%thread] %-5level %logger{36} -%msg%n</Pattern></layout></encoder></appender><appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"><filter class="ch.qos.logback.classic.filter.ThresholdFilter"><level>ERROR</level></filter><File>${HOME}/logs/edm/${SERVICE_NAME}-error.log</File><rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><fileNamePattern>${HOME}/logs/edm/${SERVICE_NAME}-error-%d{yyyyMMdd}.log.%i</fileNamePattern><timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"><maxFileSize>500MB</maxFileSize></timeBasedFileNamingAndTriggeringPolicy><maxHistory>15</maxHistory></rollingPolicy><encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"><layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"><Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%tid] [%thread] %-5level %logger{36} -%msg%n</Pattern></layout></encoder></appender><!-- skyWalking日志采集 --><appender name="APM_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.TraceIdPatternLogbackLayout"><Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%tid] [%thread] %-5level %logger{36} -%msg%n</Pattern></layout></encoder></appender><root level="INFO"><appender-ref ref="INFO_FILE" /><appender-ref ref="ERROR_FILE" /><appender-ref ref="APM_LOG" /></root></configuration>