Link tracking framework
Official website: http://skywalking.apache.org/
Download: http://skywalking.apache.org/downloads/
Github: https://github.com/apache/skywalking
Documentation: https://skywalking .apache.org/docs/main/v9.4.0/readme/
Chinese document: https://skyapm.github.io/document-cn-translation-of-skywalking/
1. Download
SkyWalking OAP service, SkyWalking UI service
Official website download:
https://skywalking.apache.org/downloads/
Online download:
wget https://dlcdn.apache.org/skywalking/9.4.0/apache-skywalking-apm-9.4.0.tar.gz
Download Agents
online download:
wget https://dlcdn.apache.org/skywalking/java-agent/8.15.0/apache-skywalking-java-agent-8.15.0.tgz
2. Unzip
Get used to putting it in the local path
cd /usr/local/
tar -zxvf apache-skywalking-apm-9.4.0.tar.gz -C /usr/local
tar -zxvf apache-skywalking-java-agent-8.15.0.tgz -C /usr/local
3. Configure SkyWalking OAP
To avoid port conflicts, replace the default port 8080 of the SkyWalking UI interface:
cd apache-skywalking-apm-bin
view catalog
ll
Edit the yml file, taking port 8100 as an example:
vi webapp/application.yml
Default in-memory mode, change to MySQL connection
vi config/application.yml
:set number can view the line number
About 133 lines modify h2 to mysql
storage:
selector: ${
SW_STORAGE:mysql}
About line 183-194, confirm the MySQL connection information (address, account number, password), remember to create a new database.
mysql:
properties:
jdbcUrl: ${
SW_JDBC_URL:"jdbc:mysql://localhost:3306/swtest?rewriteBatchedStatements=true"}
dataSource.user: ${
SW_DATA_SOURCE_USER:root}
dataSource.password: ${
SW_DATA_SOURCE_PASSWORD:123456}
ESC :wq save and exit
Download the MySQL driver jar package to /oap-libs
the directory
wget -P /usr/local/apache-skywalking-apm-bin/oap-libs https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/8.0.32/mysql-connector-j-8.0.32.jar
Then新建数据库 swtest
4. Start the SkyWalking OAP service
sh bin/oapService.sh
Check the startup log: tail -f logs/skywalking-oap-server.log
the last sentence is
50 [main] INFO [] - Version of OAP: 9.4.0-520d531
After the skywalking-oap-server service starts, two ports 11800 and 12800 will be exposed, remember to release the ports.
Open port:
open the specified port
firewall-cmd --zone=public --add-port=11800/tcp --permanent
firewall-cmd --zone=public --add-port=12800/tcp --permanent
--zone #作用域
--add-port=11800/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
5. Start the SkyWalking UI service
sh bin/webappService.sh
The default is port 8080, which has been replaced above
Access:
http://192.168.20.128:8100/
The official provides a script that starts two scripts together. After the startup is correct this time, you can directly
sh bin/startup.sh
Service boot self-start configuration, refer to 8
6. Java program access SkyWalking
6.1 Access via jar package in linux
Write a shell script to configure SkyWalking Agent to track microservices through the -javaagent parameter
vi SkyWalking-Test-startup.sh
Add content:
#!/bin/sh
# SkyWalking Agent 配置
# 配置Agent名字为项目的 `spring.application.name`
export SW_AGENT_NAME=SkyWalking-Test
# 配置 Collector 地址
export SW_AGENT_COLLECTOR_BACKEND_SERVICES=127.0.0.1:11800
#配置链路的最大Span数量,默认为 300
export SW_AGENT_SPAN_LIMIT=2000
# SkyWalking Agent jar 地址
export JAVA_AGENT=-javaagent:/usr/local/skywalking-agent/skywalking-agent.jar
# jar 启动
java -jar $JAVA_AGENT -jar SkyWalking-Test-0.01-SNAPSHOT.jar
Empowerment:
chmod u+x SkyWalking-Test-startup.sh
等同于:
java ‐javaagent:usr/local/skywalking-agent/skywalking-agent.jar ‐DSW_AGENT_COLLECTOR_BACKEND_SERVICES=127.0.0.1:11800 ‐DSW_AGENT_NAME=SkyWalking-Test ‐jar SkyWalking-Test-0.01-SNAPSHOT.jar
6.2 In Windows
Configure JVM parameters in IDEA, edit VM Options, if the application and SkyWalking are deployed on the same machine, backend_service can not be written
# skywalking‐agent.jar的本地磁盘的路径
-javaagent:F:\Apache\skywalking-agent\skywalking-agent.jar
# 在skywalking上显示的服务名
-Dskywalking.agent.service_name=SkyWalking-Test
# skywalking的collector服务的IP及端口
-Dskywalking.collector.backend_service=192.168.20.128:11800
-DSW_AGENT_COLLECTOR_BACKEND_SERVICES
can specify the remote address, but -javaagent must bind the skywalking-agent.jar of the local path
The new version of IDEA adds JVM parameters:
7. SkyWalking custom link tracking
<!-- Skywalking 工具类-->
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-trace</artifactId>
<version>8.15.0</version>
</dependency>
Just add the @Trace annotation to the business method
Add @Tag or @Tags to the method.
In the @Tag annotation, key = method name; value = returnedObj return value arg[0] parameter
Then start the project, and then refresh the project, there will be a record
8. Set up SkyWalking OAP service, SkyWalking UI service to start automatically
Prepare to set up a .service, and execute this script file at startup to achieve self-starting effect.
System startup script directory /etc/systemd/system/
New service file
vi /etc/systemd/system/skyWalking.service
Add to:
[Unit]
Description=skyWalking
After=network.target remote-fs.target nss-lookup.target mysql8.service zookeeper.service kafka.service nacos-cluster.service
[Service]
Type=forking
ExecStart=sh /usr/local/apache-skywalking-apm-bin/bin/startup.sh start
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Press ESC :wq to save and exit
Empowerment:
chmod 754 /etc/systemd/system/skyWalking.service
Set up to start automatically:
systemctl enable skyWalking.service
Overload configuration
systemctl daemon-reload
Rebootable try script feasibility (reboot)
check status
systemctl status skyWalking.service
That's it for now, thanks for reading~
END