How to use docker to deploy spring boot and connect to skywalking

How to use docker to deploy spring boot and connect to skywalking

1. Overview

I'm studying skywalking recently. I plan to use k8s to deploy skywalking and connect the application in the pod to skywalking for service link tracking. This article does not introduce the deployment and use of skywalking in k8s, but first introduces how to use skywalking manually and in docker. During the entire practice process, I consulted a lot of documents and encountered various problems. Here I will record my own practice process, hoping to provide some help to friends with the same needs.

1. Introduction to skywalking

SkyWalking is a popular domestic APM (Application Performance Monitoring) product, mainly targeting applications with microservices, Cloud Native and containerized (Docker, Kubernetes, Mesos) architectures. The core of SkyWalking is a distributed tracing system, which is currently a top-level project of the Apache Foundation.

For a detailed introduction to skywalking, please refer to the official document: skywalking official website

2. Skywalking Architecture

Logically, SkyWalking is divided into four parts: Probe, Platform Backend, Storage and UI, as shown in the following figure:

image.png

  • The probes collect data and reformat it to match SkyWalking's requirements (different probes support different sources).
  • The platform backend supports data aggregation, analysis, and stream processing, covering traces, metrics, and logs.
  • Storage devices store SkyWalking data through open/pluggable interfaces. You can choose an existing implementation such as ElasticSearch, H2, MySQL, TiDB, InfluxDB, or roll your own.
  • The UI is a highly customizable web-based interface that allows SkyWalking end-users to visualize and manage SkyWalking data.

3. How does skywalking automatically report data?

Before using the Link Tracking Console to track the link data of an application, you need to report the application data to Link Tracking through the client. SkyWalking reports Java application data to the link tracking console, and first needs to complete the tracking work. SkyWalking supports both automatic probes (Dubbo, gRPC, JDBC, OkHttp, Spring, Tomcat, Struts, Jedis, etc.) and manual traceability (OpenTracing). This article introduces the automatic point burying method.

The principle of skywalking reporting data is shown in the following figure:

image.png

2. Use docker-compose to install skywalking-oap-server and skywalking-ui

Use the following command to install docker-compose in linux:

yum install -y docker-compose

Use the following command to create skywalking-docker-compose.yaml file:

vim skywalking-docker-compose.yaml

Here we start a standlone container, which uses H2 to store data by default. If you need other storage, you can refer to the official documentation for settings.
The contents of the skywalking-docker-compose.yaml file are as follows:

version: '3'
services:
  oap:
    image: apache/skywalking-oap-server:8.4.0-es6
    container_name: oap
    restart: always
    ports:
      - 11800:11800 # The port where agent reports data, this is the gRPC port - 12800:12800 # The port where ui reads data, this is the http port skywaling-ui:
    image: apache/skywalking-ui:8.4.0
    container_name: ui
    depends_on:
      -oap
    links:
      -oap
    ports:
      -8088:8080
    environment:
      - SW_OAP_ADDRESS=oap:12800

Use the following command to start skywalking:

docker-compose -f skywalking-docker-compose.yaml up -d

Use the following command to view the startup log:

docker-compose -f skywalking-docker-compose.yaml logs -f

After successful startup, visit: http://localhost:8088, you can see the following interface:

image.png

3. Manually connect spring boot to skywalking

1. Download skywalking agent

Skywalking official website download address: http://skywalking.apache.org/downloads/
image.png
image.png

I downloaded apache-skywalking-apm-8.4.0.tar.gz here. You can also download and decompress it in Linux system by running the following command:

wget https://archive.apache.org/dist/skywalking/8.4.0/apache-skywalking-apm-8.4.0.tar.gz

tar -zxvf apache-skywalking-apm-8.4.0.tar.gz

The directory structure after decompression is as follows:

image.png

The description of the agent directory is as follows:

image.png

2. Spring boot project automatically reports data

To report the data of the spring boot project, you need to configure the skywalking access point and service name, which can be configured in the following way:

Modify the configuration file

Open the agent/config/agent.config file downloaded earlier and find the following two configurations:

# The service name in UI
agent.service_name=${SW_AGENT_NAME:Your_ApplicationName}

# Backend service addresses.
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:127.0.0.1:11800}

Just configure it according to the actual situation. After the configuration modification is completed, you can start the spring boot project with the following command:

java -javaagent:<skywalking-agent-path> -jar spring-boot-demo

Please replace it with the absolute path of skywalking-agent.jar in the Agent folder.
Note that the -javaagent parameter must come before the -jar parameter.

Configuration via command parameters

The service name can be added by adding the -Dskywalking.agent.service_name parameter in the application startup command line.
Skywalking access point can add -Dskywalking.collector.backend_service parameter in the application startup command line.
The complete command is as follows:

java -javaagent:<skywalking-agent-path> -Dskywalking.agent.service_name=<ServiceName> -Dskywalking.collector.backend_service=<backend-service-addresses> -jar yourApp.jar

Configure in the startup parameters in idea

We can also configure the following in VM options of the idea startup configuration options:

image.png

After the configuration is complete, you can start the project and see the following information printed to the console:

image.png

Check the skywalking console, and there is no data, because you need to access the interface first before reporting the data to the console. By continuously calling the test interface and checking the console again, you can see our call status, as shown in the following figure:

image.png

4. Use docker to deploy spring boot and connect to skywalking

Here, the base image of spring boot is skywalking-base , which contains openjdk11 and skywalking-agent . For detailed information, please refer to the reference document below.

image.png

The contents of Dockerfile for spring boot are as follows:

FROM apache/skywalking-base:8.4.0-es6
WORKDIR /app
COPY target/spring-demo-0.0.1-SNAPSHOT.jar spring-demo-0.0.1-SNAPSHOT.jar
ENV SW_AGENT_COLLECTOR_BACKEND_SERVICES="127.0.0.1:11800" \
    SW_AGENT_NAME="my-spring-demo-test-adfasdf"


CMD java -javaagent:/skywalking/agent/skywalking-agent.jar \
         -jar spring-demo-0.0.1-SNAPSHOT.jar

Here, environment variables are used to set custom parameters for skywalking. For other configurations of environment variables, see the agent/config/agent.config file.

Build the image using the following command:

docker build -t spring-boot-demo .

Start the image using the following command:

docker run --rm -p 8080:8080 spring-boot-demo

After successful startup, you can access the test address and go to the skywalking console to check whether there is any data reported. If there is no data reported, we need to check the log of the skywalking agent. You can check the error information in agent/logs/skywalking-api.log file.

Reference Documentation

Skywalking official documentation
Apache SkyWalking Docker Files
Report Java application data through SkyWalking

This is the end of this article about using docker to deploy spring boot and connect to skywalking. For more relevant content about docker deploying spring boot to connect to skywalking, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to package the docker image, push it to the remote server and deploy it to k8s
  • How to deploy k8s in docker
  • Implementation of k8s deployment of docker container
  • Docker learning notes k8s deployment method
  • Skywalking containerized deployment of docker images to build k8s from testing to availability

<<:  Tools to convert static websites into RSS

>>:  The use of FrameLayout in six layouts

Recommend

Detailed process of building nfs server using Docker's NFS-Ganesha image

Table of contents 1. Introduction to NFS-Ganesha ...

Introduction to fork in multithreading under Linux

Table of contents Question: Case (1) fork before ...

jQuery implements form validation function

jQuery form validation example / including userna...

How to upload the jar package to nexus via the web page

When using Maven to manage projects, how to uploa...

Linux debugging tools that developers and operators must look at [Recommended]

System performance expert Brendan D. Gregg update...

How to upgrade https under Nginx

Purchase Certificate You can purchase it from Ali...

Sample code for configuring nginx to support https

1. Introduction Are you still leaving your websit...

JavaScript Closures Explained

Table of contents 1. What is a closure? 1.2 Memoi...

CentOS8 installation tutorial of jdk8 / java8 (recommended)

Preface At first, I wanted to use wget to downloa...

Docker implements container port binding local port

Today, I encountered a small problem that after s...

A detailed introduction to the Linux directory structure

When you first start learning Linux, you first ne...

Detailed explanation of :key in VUE v-for

When key is not added to the v-for tag. <!DOCT...

How to configure /var/log/messages in Ubuntu system log

1. Problem Description Today I need to check the ...