项目集成SkyWalking,基于k8s搭建

2024-05-24 08:44

本文主要是介绍项目集成SkyWalking,基于k8s搭建,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、搭建SkyWalking

官方文档(英文):skywalking/docs at master · apache/skywalking 

中文可以使用:GitHub - SkyAPM/document-cn-translation-of-skywalking: [已过期,请使用官网AI文档] The CN translation version of Apache SkyWalking document

需要搭建服务:SkyWalkingOAP,SkyWalkingUi, Elastisearch

1.先搭建SkyWalkingOAP服务.

SkyWalkingOAP 负责数据的收集、分析和存储。通过部署oap来启动SkyWalking的基础服务。

1.1首先搭建工作负载:

kind: Deployment
apiVersion: apps/v1
metadata:
  name: skywalk-970-oap
  namespace: common
  labels:
    app: skywalk-970-oap
  annotations:
    deployment.kubernetes.io/revision: '4'
    kubesphere.io/creator: fly
spec:
  replicas: 1
  selector:
    matchLabels:
      app: skywalk-970-oap
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: skywalk-970-oap
        release: skywalking
      annotations:
        kubesphere.io/creator: fly
        kubesphere.io/restartedAt: '2024-05-22T03:21:09.886Z'
    spec:
      volumes:
        - name: host-time
          hostPath:
            path: /etc/localtime
            type: ''
      containers:
        - name: oap
          image: '159.75.136.188:40080/szqc2023002/skywalking-oap-server:9.7.0'
          ports:
            - name: grpc
              containerPort: 11800
              protocol: TCP
            - name: rest
              containerPort: 12800
              protocol: TCP
          env:
            - name: JAVA_OPTS
              value: '-Xmx1g -Xms1g'
            - name: SW_CORE_RECORD_DATA_TTL
              value: '2'
            - name: SW_CORE_METRICS_DATA_TTL
              value: '2'
            - name: SW_STORAGE
              value: elasticsearch
            - name: SW_STORAGE_ES_CLUSTER_NODES
              value: 'elasticsearch762.common:9200'
          resources:
            limits:
              memory: 2Gi
            requests:
              memory: 1Gi
          volumeMounts:
            - name: host-time
              readOnly: true
              mountPath: /etc/localtime
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext: {}
      schedulerName: default-scheduler
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600
我们存储日志的方式是使用es.

1.2然后搭建SkyWalking服务

kind: Service
apiVersion: v1
metadata:
  name: skywalk-970-oap
  namespace: common
  labels:
    app: skywalk-970-oap
  annotations:
    kubesphere.io/creator: fly
spec:
  ports:
    - name: tcp-11800
      protocol: TCP
      port: 11800
      targetPort: 11800
      nodePort: 30876
    - name: tcp-12800
      protocol: TCP
      port: 12800
      targetPort: 12800
      nodePort: 31012
  selector:
    app: skywalk-970-oap
    release: skywalking
  clusterIP: 10.233.43.222
  clusterIPs:
    - 10.233.43.222
  type: NodePort
  sessionAffinity: None
  externalTrafficPolicy: Cluster
  ipFamilies:
    - IPv4
  ipFamilyPolicy: SingleStack
  internalTrafficPolicy: Cluster
至此,SkyWalkingOAP服务完成。

2.搭建SkyWalkingUi服务

SkyWalkibgUi是SkyWalking的可视化界面服务。用于展示分布式系统的监控数据。我们可以通过WebUi来访问和使用SkyWalking。

2.1首先搭建SkyWalkingUi的工作负载

kind: Deployment
apiVersion: apps/v1
metadata:
  name: skywalk-970-ui
  namespace: common
  labels:
    app: skywalk-970-ui
  annotations:
    deployment.kubernetes.io/revision: '4'
    kubesphere.io/creator: fly
spec:
  replicas: 1
  selector:
    matchLabels:
      app: skywalk-970-ui
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: skywalk-970-ui
        release: skywalking
      annotations:
        kubesphere.io/creator: fly
        kubesphere.io/restartedAt: '2024-05-22T03:10:50.693Z'
    spec:
      containers:
        - name: sk-ui
          image: 'apache/skywalking-ui:9.7.0'
          ports:
            - containerPort: 8080
              protocol: TCP
          env:
            - name: SW_OAP_ADDRESS
              value: 'http://skywalk-970-oap.common:12800'
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext: {}
      schedulerName: default-scheduler
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600
2.2搭建SkyWalkingUi服务

kind: Service
apiVersion: v1
metadata:
  name: skywalk-970-ui
  namespace: common
  labels:
    app: skywalk-970-ui
  annotations:
    kubesphere.io/creator: fly
spec:
  ports:
    - name: http-8080
      protocol: TCP
      port: 8080
      targetPort: 8080
      nodePort: 31195
  selector:
    app: skywalk-970-ui
    release: skywalking
  clusterIP: 10.233.2.227
  clusterIPs:
    - 10.233.2.227
  type: NodePort
  sessionAffinity: None
  externalTrafficPolicy: Cluster
  ipFamilies:
    - IPv4
  ipFamilyPolicy: SingleStack
  internalTrafficPolicy: Cluster
至此SkyWalkingUi服务搭建完成。

3.搭建Es服务,用于存储SkyWalking日志。

3.1搭建Es服务的工作负载

kind: Deployment
apiVersion: apps/v1
metadata:
  name: elasticsearch762
  namespace: common
  labels:
    app: elasticsearch762
  annotations:
    deployment.kubernetes.io/revision: '4'
    kubesphere.io/creator: fly
    kubesphere.io/description: 未提供nodeport服务,供Skywalking做数据源
spec:
  replicas: 1
  selector:
    matchLabels:
      app: elasticsearch762
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: elasticsearch762
      annotations:
        kubesphere.io/creator: fly
        kubesphere.io/restartedAt: '2024-05-22T03:41:36.061Z'
        logging.kubesphere.io/logsidecar-config: '{}'
    spec:
      volumes:
        - name: host-time
          hostPath:
            path: /etc/localtime
            type: ''
        - name: volume-m5uec2
          configMap:
            name: elasticsearch760
            items:
              - key: elasticsearch.yml
                path: elasticsearch.yml
            defaultMode: 420
        - name: volume-vcbpgy
          configMap:
            name: elasticsearch760
            items:
              - key: jvm.options
                path: jvm.options
            defaultMode: 420
      containers:
        - name: container-3sukk2
          image: 'elasticsearch:7.6.2'
          ports:
            - name: tcp-9200
              containerPort: 9200
              protocol: TCP
            - name: tcp-9300
              containerPort: 9300
              protocol: TCP
          env:
            - name: discovery.type
              value: single-node
            - name: ES_JAVA_OPTS
              value: '-Xms1024m -Xmx1024m'
          resources: {}
          volumeMounts:
            - name: host-time
              readOnly: true
              mountPath: /etc/localtime
            - name: volume-m5uec2
              readOnly: true
              mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
              subPath: elasticsearch.yml
            - name: volume-vcbpgy
              readOnly: true
              mountPath: /usr/share/elasticsearch/config/jvm.options
              subPath: jvm.options
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      nodeSelector:
        kubernetes.io/hostname: worker1
      serviceAccountName: default
      serviceAccount: default
      securityContext: {}
      schedulerName: default-scheduler
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600
3.2搭建Es的服务

kind: Service
apiVersion: v1
metadata:
  name: elasticsearch762
  namespace: common
  labels:
    app: elasticsearch762
  annotations:
    kubesphere.io/creator: fly
spec:
  ports:
    - name: tcp-9200
      protocol: TCP
      port: 9200
      targetPort: 9200
    - name: tcp-9300
      protocol: TCP
      port: 9300
      targetPort: 9300
  selector:
    app: elasticsearch762
  clusterIP: 10.233.7.71
  clusterIPs:
    - 10.233.7.71
  type: ClusterIP
  sessionAffinity: None
  ipFamilies:
    - IPv4
  ipFamilyPolicy: SingleStack
  internalTrafficPolicy: Cluster
至此Es搭建服务完成。需要注意的点是:SkyWalkingAOP配置的Es的变量值,要对应Es的Dns服务名称。           

- name: SW_STORAGE_ES_CLUSTER_NODES
value: 'elasticsearch762.common:9200'

二、项目集成Skywalking

在需要集成SkyWalking服务的deploy.yml添加initContainer,达到无侵入方式集成。

kind: Deployment
apiVersion: apps/v1
metadata:
  name: zhqc-frame-gateway
  namespace: szqc2023002-dev
  labels:
    app: zhqc-frame-gateway
  annotations:
    deployment.kubernetes.io/revision: '86'
    kubectl.kubernetes.io/last-applied-configuration: >
      {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"labels":{"app":"zhqc-frame-gateway"},"name":"zhqc-frame-gateway","namespace":"szqc2023002-dev"},"spec":{"progressDeadlineSeconds":600,"replicas":1,"selector":{"matchLabels":{"app":"zhqc-frame-gateway"}},"strategy":{"rollingUpdate":{"maxSurge":"50%","maxUnavailable":"50%"},"type":"RollingUpdate"},"template":{"metadata":{"labels":{"app":"zhqc-frame-gateway"}},"spec":{"containers":[{"env":[{"name":"JAVA_TOOL_OPTIONS","value":"-javaagent:/skywalking/agent/skywalking-agent.jar"},{"name":"SW_AGENT_NAME","value":"zhqc-frame-gateway"},{"name":"SW_AGENT_COLLECTOR_BACKEND_SERVICES","value":"192.168.10.222:30876"},{"name":"SW_AGENT_TRACE_IGNORE_PATH","value":"GET:/actuator/**,Lettuce/**"},{"name":"SPRING_PROFILES_ACTIVE","value":"dev_k8s"},{"name":"NACOS_ENABLED","value":"true"},{"name":"NACOS_SERVER_ADDR","value":"192.168.10.222"},{"name":"NACOS_SERVER_PORT","value":"32064"},{"name":"NACOS_SERVER_USERNAME","value":"nacos"},{"name":"NACOS_SERVER_PASSWORD","value":"nacos"},{"name":"NACOS_DISCOVERY_NAMESPACE","value":"ff54f1f9-5b3f-432e-addc-0b006b2646c7"},{"name":"NACOS_CONFIG_NAMESPACE","value":"016dcce2-92c4-4ae4-b2e3-3375d790c43a"}],"image":"159.75.136.188:40080/szqc2023002/zhqc-frame-gateway:SNAPSHOT-87","imagePullPolicy":"Always","name":"app","ports":[{"containerPort":8080,"protocol":"TCP"}],"resources":{"limits":{"memory":"1000Mi"},"requests":{"cpu":"100m","memory":"200Mi"}},"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","volumeMounts":[{"mountPath":"/skywalking","name":"skywalking-agent"}]}],"dnsPolicy":"ClusterFirst","imagePullSecrets":[{"name":"zhqc-dockerhub"}],"initContainers":[{"args":["-c","cp
      -R /skywalking/agent /agent/;cp
      /skywalking/agent/optional-plugins/apm-trace-ignore-plugin-9.0.0.jar
      /agent/agent/plugins/apm-trace-ignore-plugin-9.0.0.jar;rm
      /agent/agent/plugins/apm-redisson-3.x-plugin-9.0.0.jar;echo
      trace.ignore_path=\\${SW_AGENT_TRACE_IGNORE_PATH:Lettuce/**} \u003e
      /agent/agent/config/apm-trace-ignore-plugin.config; cp
      /skywalking/agent/optional-plugins/apm-spring-cloud-gateway-3.x-plugin-9.0.0.jar
      /agent/agent/plugins/apm-spring-cloud-gateway-3.x-plugin-9.0.0.jar; cp
      /skywalking/agent/optional-plugins/apm-spring-webflux-5.x-plugin-9.0.0.jar
      /agent/agent/plugins/apm-spring-webflux-5.x-plugin-9.0.0.jar;"],"command":["/bin/sh"],"image":"apache/skywalking-java-agent:9.0.0-alpine","name":"agent-container","volumeMounts":[{"mountPath":"/agent","name":"skywalking-agent"}]}],"restartPolicy":"Always","terminationGracePeriodSeconds":30,"volumes":[{"emptyDir":{},"name":"skywalking-agent"}]}}}}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: zhqc-frame-gateway
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: zhqc-frame-gateway
        pod-template-hash: 788dd5dc8b
      annotations:
        kubesphere.io/restartedAt: '2024-05-20T05:52:23.124Z'
    spec:
      volumes:
        - name: skywalking-agent
          emptyDir: {}
      initContainers:
        - name: agent-container
          image: 'apache/skywalking-java-agent:9.0.0-alpine'
          command:
            - /bin/sh
          args:
            - '-c'
            - >-
              cp -R /skywalking/agent /agent/;cp
              /skywalking/agent/optional-plugins/apm-trace-ignore-plugin-9.0.0.jar
              /agent/agent/plugins/apm-trace-ignore-plugin-9.0.0.jar;rm
              /agent/agent/plugins/apm-redisson-3.x-plugin-9.0.0.jar;echo
              trace.ignore_path=\${SW_AGENT_TRACE_IGNORE_PATH:Lettuce/**} >
              /agent/agent/config/apm-trace-ignore-plugin.config; cp
              /skywalking/agent/optional-plugins/apm-spring-cloud-gateway-3.x-plugin-9.0.0.jar
              /agent/agent/plugins/apm-spring-cloud-gateway-3.x-plugin-9.0.0.jar;
              cp
              /skywalking/agent/optional-plugins/apm-spring-webflux-5.x-plugin-9.0.0.jar
              /agent/agent/plugins/apm-spring-webflux-5.x-plugin-9.0.0.jar;
          resources: {}
          volumeMounts:
            - name: skywalking-agent
              mountPath: /agent
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      containers:
        - name: app
          image: '159.75.136.188:40080/szqc2023002/zhqc-frame-gateway:SNAPSHOT-2'
          ports:
            - containerPort: 8080
              protocol: TCP
          env:
            - name: JAVA_TOOL_OPTIONS
              value: '-javaagent:/skywalking/agent/skywalking-agent.jar'
            - name: SW_AGENT_NAME
              value: zhqc-frame-gateway
            - name: SW_AGENT_COLLECTOR_BACKEND_SERVICES
              value: '192.168.10.222:30876'
            - name: SW_AGENT_TRACE_IGNORE_PATH
              value: 'GET:/actuator/**,Lettuce/**'
            - name: SPRING_PROFILES_ACTIVE
              value: dev_k8s
            - name: NACOS_ENABLED
              value: 'true'
            - name: NACOS_SERVER_ADDR
              value: nacos223.szqc2023002-dev
            - name: NACOS_SERVER_PORT
              value: '8848'
            - name: NACOS_SERVER_USERNAME
              value: nacos4app
            - name: NACOS_SERVER_PASSWORD
              value: nacos@2024
            - name: NACOS_DISCOVERY_NAMESPACE
              value: ff54f1f9-5b3f-432e-addc-0b006b2646c7
            - name: NACOS_CONFIG_NAMESPACE
              value: 016dcce2-92c4-4ae4-b2e3-3375d790c43a
          resources:
            limits:
              memory: 1000Mi
            requests:
              cpu: 100m
              memory: 200Mi
          volumeMounts:
            - name: skywalking-agent
              mountPath: /skywalking
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: Always
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext: {}
      imagePullSecrets:
        - name: zhqc-dockerhub
      schedulerName: default-scheduler
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 50%
      maxSurge: 50%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600
 

添加了挂载点:

    spec:
      volumes:
        - name: skywalking-agent
          emptyDir: {}

添加了initContainer

  initContainers:
        - name: agent-container
          image: 'apache/skywalking-java-agent:9.0.0-alpine'
          command:
            - /bin/sh
          args:
            - '-c'
            - >-
              cp -R /skywalking/agent /agent/;cp
              /skywalking/agent/optional-plugins/apm-trace-ignore-plugin-9.0.0.jar
              /agent/agent/plugins/apm-trace-ignore-plugin-9.0.0.jar;rm
              /agent/agent/plugins/apm-redisson-3.x-plugin-9.0.0.jar;echo
              trace.ignore_path=\${SW_AGENT_TRACE_IGNORE_PATH:Lettuce/**} >
              /agent/agent/config/apm-trace-ignore-plugin.config; cp
              /skywalking/agent/optional-plugins/apm-spring-cloud-gateway-3.x-plugin-9.0.0.jar
              /agent/agent/plugins/apm-spring-cloud-gateway-3.x-plugin-9.0.0.jar;
              cp
              /skywalking/agent/optional-plugins/apm-spring-webflux-5.x-plugin-9.0.0.jar
              /agent/agent/plugins/apm-spring-webflux-5.x-plugin-9.0.0.jar;
          resources: {}
          volumeMounts:
            - name: skywalking-agent
              mountPath: /agent
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent

增加了SkyWalking的相关配置:

          env:
            - name: JAVA_TOOL_OPTIONS
              value: '-javaagent:/skywalking/agent/skywalking-agent.jar'
            - name: SW_AGENT_NAME
              value: zhqc-frame-gateway
            - name: SW_AGENT_COLLECTOR_BACKEND_SERVICES
              value: '192.168.10.222:30876'
            - name: SW_AGENT_TRACE_IGNORE_PATH
              value: 'GET:/actuator/**,Lettuce/**'

SkyWalking忽略的接口

  - name: SW_AGENT_TRACE_IGNORE_PATH
 value: 'GET:/actuator/**,Lettuce/**'

SkyWalking的收集服务,即SkyWalkingAOP暴漏的服务

   - name: SW_AGENT_COLLECTOR_BACKEND_SERVICES
   value: '192.168.10.222:30876'

部署服务之后,就可以在SKyWalking看到该服务。

三、项目将日志集成到SkyWalking中。

1.引入pom包

<!-- https://mvnrepository.com/artifact/org.apache.skywalking/apm-toolkit-trace -->
<dependency><groupId>org.apache.skywalking</groupId><artifactId>apm-toolkit-trace</artifactId><version>9.0.0</version>
</dependency><!-- https://mvnrepository.com/artifact/org.apache.skywalking/apm-toolkit-logback-1.x -->
<dependency><groupId>org.apache.skywalking</groupId><artifactId>apm-toolkit-logback-1.x</artifactId><version>9.0.0</version>
</dependency></dependencies>

2.修改logback-spring.xml的配置

<?xml version="1.0" encoding="UTF-8" ?>
<!-- 级别从高到低 OFF 、 FATAL 、 ERROR 、 WARN 、 INFO 、 DEBUG 、 TRACE 、 ALL -->
<!-- 日志输出规则 根据当前ROOT 级别,日志输出时,级别高于root默认的级别时 会输出 -->
<!-- 以下 每个配置的 filter 是过滤掉输出文件里面,会出现高级别文件,依然出现低级别的日志信息,通过filter 过滤只记录本级别的日志 -->
<!-- scan 当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true。 -->
<!-- scanPeriod 设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。 -->
<!-- debug 当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 --><configuration scan="true" scanPeriod="60 seconds" debug="false"><contextName>springboot-security</contextName><include resource="org/springframework/boot/logging/logback/defaults.xml"/><springProperty scope="context" name="APP_PORT" source="server.port"/><springProperty scope="context" name="springAppName" source="spring.application.name"/><springProperty scope="context" name="log.home_dir" source="logging.path"/><!-- 日志输出格式 --><property name="CONSOLE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS}[${springAppName}-${APP_PORT}][%clr(${PID:-}) %X{X-B3-TraceId:-},%X{X-B3-SpanId:-}] [%thread] %-5level %logger{50} - %msg%n"/><!-- 定义日志文件 输出位置 --><!--<springProfile name="dev">--><!--<property name="log.home_dir" value="${logging.path}"/>--><!--</springProfile>--><!--<springProfile name="test">--><!--<property name="log.home_dir" value="${logging.path}"/>--><!--</springProfile>--><!--<springProfile name="prod">--><!--<property name="log.home_dir" value="${logging.path}"/>--><!--</springProfile>--><!-- 日志最大的历史 30天 --><property name="log.maxHistory" value="30"/><!-- 打印debug级别日志及以上级别日志 --><property name="log.level" value="info"/><!-- ConsoleAppender 控制台输出日志 start -->
<!--    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">-->
<!--        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">-->
<!--            <level>INFO</level>-->
<!--        </filter>-->
<!--        <encoder>-->
<!--            <pattern>-->
<!--                <pattern>${CONSOLE_LOG_PATTERN}</pattern>-->
<!--                &lt;!&ndash;<charset>utf8</charset>&ndash;&gt;-->
<!--            </pattern>-->
<!--        </encoder>-->
<!--    </appender>--><!-- ConsoleAppender 控制台输出日志 end --><!-- errorAppender 控制台输出日志 start -->
<!--    <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
<!--        &lt;!&ndash; 过滤器,只记录WARN级别的日志 &ndash;&gt;-->
<!--        &lt;!&ndash; 果日志级别等于配置级别,过滤器会根据onMath 和 onMismatch接收或拒绝日志。 &ndash;&gt;-->
<!--        <filter class="ch.qos.logback.classic.filter.LevelFilter">-->
<!--            &lt;!&ndash; 设置过滤级别 &ndash;&gt;-->
<!--            <level>ERROR</level>-->
<!--            &lt;!&ndash; 用于配置符合过滤条件的操作 &ndash;&gt;-->
<!--            <onMatch>ACCEPT</onMatch>-->
<!--            &lt;!&ndash; 用于配置不符合过滤条件的操作 &ndash;&gt;-->
<!--            <onMismatch>DENY</onMismatch>-->
<!--        </filter>-->
<!--        &lt;!&ndash; 最常用的滚动策略,它根据时间来制定滚动策略.既负责滚动也负责触发滚动 &ndash;&gt;-->
<!--        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">-->
<!--            &lt;!&ndash;日志输出位置 可以是相对和绝对路径 &ndash;&gt;-->
<!--            <fileNamePattern>-->
<!--                ${log.home_dir}/error/%d{yyyy-MM-dd}/errorLog-%i.log-->
<!--            </fileNamePattern>-->
<!--            &lt;!&ndash; 可选节点,控制保留的归档文件的最大数量,超出数量就删除旧文件假设设置每个月滚动,且<maxHistory>是6, 则只保存最近6个月的文件,删除之前的旧文件。注意,删除旧文件是,那些为了归档而创建的目录也会被删除 &ndash;&gt;-->
<!--            <maxHistory>${log.maxHistory}</maxHistory>-->
<!--            <TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">-->
<!--                &lt;!&ndash; 单个log文件超过该大小就会重新建一个log文件 &ndash;&gt;-->
<!--                <MaxFileSize>2MB</MaxFileSize>-->
<!--            </TimeBasedFileNamingAndTriggeringPolicy>-->
<!--        </rollingPolicy>-->
<!--        <encoder>-->
<!--            <pattern>-->
<!--                <pattern>${CONSOLE_LOG_PATTERN}</pattern>-->
<!--                <charset>utf8</charset>-->
<!--            </pattern>-->
<!--        </encoder>-->
<!--    </appender>--><!-- errorAppender 控制台输出日志 end --><!-- warnAppender 控制台输出日志 start -->
<!--    <appender name="warn" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
<!--        <filter class="ch.qos.logback.classic.filter.LevelFilter">-->
<!--            <level>WARN</level>-->
<!--            <onMatch>ACCEPT</onMatch>-->
<!--            <onMismatch>DENY</onMismatch>-->
<!--        </filter>-->
<!--        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">-->
<!--            <fileNamePattern>-->
<!--                ${log.home_dir}/warn/%d{yyyy-MM-dd}/warnLog-%i.log-->
<!--            </fileNamePattern>-->
<!--            <maxHistory>${log.maxHistory}</maxHistory>-->
<!--            <TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">-->
<!--                <MaxFileSize>2MB</MaxFileSize>-->
<!--            </TimeBasedFileNamingAndTriggeringPolicy>-->
<!--        </rollingPolicy>-->
<!--        <encoder>-->
<!--            <pattern>-->
<!--                <pattern>${CONSOLE_LOG_PATTERN}</pattern>-->
<!--                <charset>utf8</charset>-->
<!--            </pattern>-->
<!--        </encoder>-->
<!--    </appender>--><!-- warnAppender 控制台输出日志 end --><!-- infoAppender 控制台输出日志 start -->
<!--    <appender name="info" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
<!--        <filter class="ch.qos.logback.classic.filter.LevelFilter">-->
<!--            <level>INFO</level>-->
<!--            <onMatch>ACCEPT</onMatch>-->
<!--            <onMismatch>DENY</onMismatch>-->
<!--        </filter>-->
<!--        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">-->
<!--            <fileNamePattern>${log.home_dir}/info/%d{yyyy-MM-dd}/infoLog-%i.log</fileNamePattern>-->
<!--            <maxHistory>${log.maxHistory}</maxHistory>-->
<!--            <TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">-->
<!--                <MaxFileSize>2MB</MaxFileSize>-->
<!--            </TimeBasedFileNamingAndTriggeringPolicy>-->
<!--        </rollingPolicy>-->
<!--        <encoder>-->
<!--            <pattern>-->
<!--                <pattern>${CONSOLE_LOG_PATTERN}</pattern>-->
<!--                <charset>utf8</charset>-->
<!--            </pattern>-->
<!--        </encoder>-->
<!--    </appender>--><!-- infoAppender 控制台输出日志 end --><!-- debugAppender 控制台输出日志 start -->
<!--    <appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
<!--        <filter class="ch.qos.logback.classic.filter.LevelFilter">-->
<!--            <level>DEBUG</level>-->
<!--            <onMatch>ACCEPT</onMatch>-->
<!--            <onMismatch>DENY</onMismatch>-->
<!--        </filter>-->
<!--        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">-->
<!--            <fileNamePattern>${log.home_dir}/debug/%d{yyyy-MM-dd}/debugLog-%i.log</fileNamePattern>-->
<!--            <maxHistory>${log.maxHistory}</maxHistory>-->
<!--            <TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">-->
<!--                <MaxFileSize>2MB</MaxFileSize>-->
<!--            </TimeBasedFileNamingAndTriggeringPolicy>-->
<!--        </rollingPolicy>-->
<!--        <encoder>-->
<!--            <pattern>-->
<!--                <pattern>${CONSOLE_LOG_PATTERN}</pattern>-->
<!--                <charset>utf8</charset>-->
<!--            </pattern>-->
<!--        </encoder>-->
<!--    </appender>--><!-- debugAppender 控制台输出日志 end --><!--日志发送到logstash=>elasticSearch=>kibana start--><!--<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">--><!--<destination>localhost:9601</destination>--><!--<queueSize>1048576</queueSize>--><!--<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder" />--><!--</appender>--><!--<logger name="kibanaLog" level="DEBUG" additivity="false">--><!--<appender-ref ref="LOGSTASH"/>--><!--</logger>--><!--日志发送到logstash=>elasticSearch=>kibana end --><!-- 1、控制台输出 --><property name="CONSOLE_PATTERN"value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level[%tid][%blue(%thread)][%cyan(%logger)] - %m%n"/><appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender"><encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"><layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"><Pattern>${CONSOLE_PATTERN}</Pattern></layout></encoder></appender><!-- 异步输出 --><appender name="console-async" class="ch.qos.logback.classic.AsyncAppender"><discardingThreshold>0</discardingThreshold><queueSize>1024</queueSize><neverBlock>true</neverBlock><appender-ref ref="consoleLog"/></appender><!-- 2、使用gRpc将日志发送到Skywalking服务端 --><!-- 日志输出格式 --><property name="RPC_PATTERN"value="%d{yyyy-MM-dd HH:mm:ss.SSS} [${appName}] %-5p [%tid] [%thread] %logger{36} - %m%n"/><appender name="grpc-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>${RPC_PATTERN}</Pattern></layout></encoder></appender><root>
<!--        <level value="${log.level}"/>--><!-- 控制台输出 -->
<!--        <appender-ref ref="console"/>-->
<!--        <appender-ref ref="consoleLog"/>--><appender-ref ref="console-async" /><appender-ref ref="grpc-log" /><!-- 文件输出 -->
<!--        <appender-ref ref="error"/>-->
<!--        <appender-ref ref="warn"/>-->
<!--        <appender-ref ref="info"/>-->
<!--        <appender-ref ref="debug"/>--></root><!-- 文件不输出 --><Logger name="org.springframework" level="ERROR"></Logger><Logger name="org.hibernate" level="ERROR"></Logger><Logger name="org.apache" level="ERROR"></Logger><Logger name="com.netflix" level="ERROR"></Logger><Logger name="ch.qos.logback" level="ERROR"></Logger><Logger name="com.alibaba.cloud.nacos" level="INFO"></Logger>
</configuration>

这样日志就会打印到SkyWalking中,不需要在输出到日志文件中

这篇关于项目集成SkyWalking,基于k8s搭建的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/997924

相关文章

使用Python实现快速搭建本地HTTP服务器

《使用Python实现快速搭建本地HTTP服务器》:本文主要介绍如何使用Python快速搭建本地HTTP服务器,轻松实现一键HTTP文件共享,同时结合二维码技术,让访问更简单,感兴趣的小伙伴可以了... 目录1. 概述2. 快速搭建 HTTP 文件共享服务2.1 核心思路2.2 代码实现2.3 代码解读3.

MySQL双主搭建+keepalived高可用的实现

《MySQL双主搭建+keepalived高可用的实现》本文主要介绍了MySQL双主搭建+keepalived高可用的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、测试环境准备二、主从搭建1.创建复制用户2.创建复制关系3.开启复制,确认复制是否成功4.同

springboot简单集成Security配置的教程

《springboot简单集成Security配置的教程》:本文主要介绍springboot简单集成Security配置的教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录集成Security安全框架引入依赖编写配置类WebSecurityConfig(自定义资源权限规则

一文教你如何将maven项目转成web项目

《一文教你如何将maven项目转成web项目》在软件开发过程中,有时我们需要将一个普通的Maven项目转换为Web项目,以便能够部署到Web容器中运行,本文将详细介绍如何通过简单的步骤完成这一转换过程... 目录准备工作步骤一:修改​​pom.XML​​1.1 添加​​packaging​​标签1.2 添加

tomcat多实例部署的项目实践

《tomcat多实例部署的项目实践》Tomcat多实例是指在一台设备上运行多个Tomcat服务,这些Tomcat相互独立,本文主要介绍了tomcat多实例部署的项目实践,具有一定的参考价值,感兴趣的可... 目录1.创建项目目录,测试文China编程件2js.创建实例的安装目录3.准备实例的配置文件4.编辑实例的

springboot集成Deepseek4j的项目实践

《springboot集成Deepseek4j的项目实践》本文主要介绍了springboot集成Deepseek4j的项目实践,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价... 目录Deepseek4j快速开始Maven 依js赖基础配置基础使用示例1. 流式返回示例2. 进阶

SpringBoot项目启动报错"找不到或无法加载主类"的解决方法

《SpringBoot项目启动报错找不到或无法加载主类的解决方法》在使用IntelliJIDEA开发基于SpringBoot框架的Java程序时,可能会出现找不到或无法加载主类com.example.... 目录一、问题描述二、排查过程三、解决方案一、问题描述在使用 IntelliJ IDEA 开发基于

SpringBoot项目使用MDC给日志增加唯一标识的实现步骤

《SpringBoot项目使用MDC给日志增加唯一标识的实现步骤》本文介绍了如何在SpringBoot项目中使用MDC(MappedDiagnosticContext)为日志增加唯一标识,以便于日... 目录【Java】SpringBoot项目使用MDC给日志增加唯一标识,方便日志追踪1.日志效果2.实现步

Spring Boot 集成 Quartz 使用Cron 表达式实现定时任务

《SpringBoot集成Quartz使用Cron表达式实现定时任务》本文介绍了如何在SpringBoot项目中集成Quartz并使用Cron表达式进行任务调度,通过添加Quartz依赖、创... 目录前言1. 添加 Quartz 依赖2. 创建 Quartz 任务3. 配置 Quartz 任务调度4. 启

Ubuntu中Nginx虚拟主机设置的项目实践

《Ubuntu中Nginx虚拟主机设置的项目实践》通过配置虚拟主机,可以在同一台服务器上运行多个独立的网站,本文主要介绍了Ubuntu中Nginx虚拟主机设置的项目实践,具有一定的参考价值,感兴趣的可... 目录简介安装 Nginx创建虚拟主机1. 创建网站目录2. 创建默认索引文件3. 配置 Nginx4