• 10分钟SkyWalking与SpringBoot融合并整合到Linux中


    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>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    这边需要排除掉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>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59

    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
    
    • 1
    • 2
    • 3

    5.请求展示
    请求查询接口,记得日志要打在service层里面
    [图片]

    6.部署到Linux中
    (1)一键安装docker,注意Centos版本要大于等于7

    curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
    
    • 1

    (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
    
    • 1

    (3)授予权限

    sudo chmod +x /usr/local/bin/docker-compose
    
    • 1

    (4)测试安装结果

    docker-compose --version
    
    • 1

    (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 
    
    • 1

    (8)测试接口即正常

  • 相关阅读:
    【OpenCV】计算视频的光流并跟踪物体calcOpticalFlowPyrLK
    各种安卓框布局颜色
    【图像分割】基于元胞自动机实现图像分割附matlab代码
    North American Hardwoods Identification Using Machine-Learning(SCI 读书笔记)
    LeetCode刷题第2周小结
    一体化伺服电机在新能源汽车充电设备中的应用
    uniapp或者vue项目环境变量的模式来自动替换网络请求的baseUrl
    Flink Batch Hash Aggregate
    Go语言高级特性解析与实践
    mall :rabbit项目源码解析
  • 原文地址:https://blog.csdn.net/m0_51001708/article/details/136363076