1.依赖配置
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
<version>2.2.0.RELEASEversion>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starterartifactId>
<version>2.2.0.RELEASEversion>
<exclusions>
<exclusion>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-loggingartifactId>
exclusion>
exclusions>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-log4j2artifactId>
<version>2.2.0.RELEASEversion>
dependency>
<dependency>
<groupId>org.apache.skywalkinggroupId>
<artifactId>apm-toolkit-log4j-2.xartifactId>
<version>9.1.0version>
dependency>
<dependency>
<groupId>org.apache.skywalkinggroupId>
<artifactId>apm-toolkit-traceartifactId>
<version>9.1.0version>
dependency>
这边需要排除掉springboot自带的日志框架,很重要
2.配置日志文件
在/src/main/resources下创建log4j2.xml文件
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d [%traceId] %-5p %c{1}:%L - %m%n"/>
Console>
<GRPCLogClientAppender name="grpc-log">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
GRPCLogClientAppender>
Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console"/>
<AppenderRef ref="grpc-log"/>
Root>
Loggers>
Configuration>
3.Dockfile文件编写
version: '3.8'
services:
elasticsearch:
image: elasticsearch:7.16.2
container_name: elasticsearch
ports:
- "9201:9200"
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
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./data/es_data:/usr/share/elasticsearch/data
oap:
image: apache/skywalking-oap-server:8.9.0
container_name: oap
depends_on:
elasticsearch:
condition: service_healthy
links:
- elasticsearch
ports:
- "11800:11800"
- "12800:12800"
healthcheck:
test: [ "CMD-SHELL", "/skywalking/bin/swctl ch" ]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
environment:
SW_STORAGE: elasticsearch
SW_STORAGE_ES_CLUSTER_NODES: elasticsearch:9200
SW_HEALTH_CHECKER: default
SW_TELEMETRY: prometheus
JAVA_OPTS: "-Xms1024m -Xmx1024m"
skywalking-ui:
image: apache/skywalking-ui:8.9.0
container_name: skywalking-ui
depends_on:
oap:
condition: service_healthy
links:
- oap
ports:
- "9090:8080"
environment:
SW_OAP_ADDRESS: http://oap:12800
dockerfile如何运行,自行查询即可
启动完成之后,打开http://127.0.0.1:9090,会出现Skywalking的UI界面
4.VM参数
在虚拟机参数里加上这段,注意skywalking-agent.jar要去官网下载,jar包外面的文件也不能丢失,否则会报错
-javaagent:C:/skywalking/skywalking-agent/skywalking-agent.jar
-Dskywalking.agent.service_name=你自己的服务名字
-Dskywalking.collector.backend_service=127.0.0.1:11800
5.请求展示
请求查询接口,记得日志要打在service层里面
6.部署到Linux中
(1)一键安装docker,注意Centos版本要大于等于7
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
(2)安装docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
(3)授予权限
sudo chmod +x /usr/local/bin/docker-compose
(4)测试安装结果
docker-compose --version
(5)之后上传之前的dockerfile文件,在当前目录下执行docker-compose up -d
(6)查看服务器的9090端口,skywalkingui是否工作正常
(7)上传测试项目,执行
java -javaagent:/root/skywalking-agent/skywalking-agent.jar -Dskywalking.agent.service_name=gwt -Dskywalking.collector.backend_service=127.0.0.1:11800 -jar TestSkyWalking.jar
(8)测试接口即正常