docker(二十八)docker-compose部署链路追踪SkyWalking

157 阅读4分钟

Docker 插件部署继续,这里是docker 部署 skywalking链路追踪。它提供了对分布式系统的追踪、监控和诊断能力。

 

skyWalking存在多种数据存储:

1)     h2(默认的存储方式,重启后数据会丢失)

2)     Elasticsearch (最常用的数据存储方式)

3)     MySQL

4)     TiDB

 

我这里使用elasticsearch来存储数据,关于elasticsearch的部署请移步《docker(十五)docker-compose部署elasticsearch配置账号密码登录

 

一:下载skywalking源码包

下载地址:archive.apache.org/dist/skywal…

选择下载你使用的版本。我这里下载的是8.9.0

微信截图_20241226204952.png

主要是使用这个application.yml文件,从这个文件中我们可以获取对应参数的设置名称。

我这里使用elasticsearch来存储数据,我这里只展示application.yml中elasticsearch配置部分:

storage:
  selector: ${SW_STORAGE:h2}
  elasticsearch:
    namespace: ${SW_NAMESPACE:""}
    clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:localhost:9200}
    protocol: ${SW_STORAGE_ES_HTTP_PROTOCOL:"http"}
    connectTimeout: ${SW_STORAGE_ES_CONNECT_TIMEOUT:500}
    socketTimeout: ${SW_STORAGE_ES_SOCKET_TIMEOUT:30000}
    numHttpClientThread: ${SW_STORAGE_ES_NUM_HTTP_CLIENT_THREAD:0}
    user: ${SW_ES_USER:""}
    password: ${SW_ES_PASSWORD:""}
    trustStorePath: ${SW_STORAGE_ES_SSL_JKS_PATH:""}
    trustStorePass: ${SW_STORAGE_ES_SSL_JKS_PASS:""}
    secretsManagementFile: ${SW_ES_SECRETS_MANAGEMENT_FILE:""} # Secrets management file in the properties format includes the username, password, which are managed by 3rd party tool.
    dayStep: ${SW_STORAGE_DAY_STEP:1} # Represent the number of days in the one minute/hour/day index.
    indexShardsNumber: ${SW_STORAGE_ES_INDEX_SHARDS_NUMBER:1} # Shard number of new indexes
    indexReplicasNumber: ${SW_STORAGE_ES_INDEX_REPLICAS_NUMBER:1} # Replicas number of new indexes
    # Super data set has been defined in the codes, such as trace segments.The following 3 config would be improve es performance when storage super size data in es.
    superDatasetDayStep: ${SW_SUPERDATASET_STORAGE_DAY_STEP:-1} # Represent the number of days in the super size dataset record index, the default value is the same as dayStep when the value is less than 0
    superDatasetIndexShardsFactor: ${SW_STORAGE_ES_SUPER_DATASET_INDEX_SHARDS_FACTOR:5} #  This factor provides more shards for the super data set, shards number = indexShardsNumber * superDatasetIndexShardsFactor. Also, this factor effects Zipkin and Jaeger traces.
    superDatasetIndexReplicasNumber: ${SW_STORAGE_ES_SUPER_DATASET_INDEX_REPLICAS_NUMBER:0} # Represent the replicas number in the super size dataset record index, the default value is 0.
    indexTemplateOrder: ${SW_STORAGE_ES_INDEX_TEMPLATE_ORDER:0} # the order of index template
    bulkActions: ${SW_STORAGE_ES_BULK_ACTIONS:5000} # Execute the async bulk record data every ${SW_STORAGE_ES_BULK_ACTIONS} requests
    # flush the bulk every 10 seconds whatever the number of requests
    # INT(flushInterval * 2/3) would be used for index refresh period.
    flushInterval: ${SW_STORAGE_ES_FLUSH_INTERVAL:15}
    concurrentRequests: ${SW_STORAGE_ES_CONCURRENT_REQUESTS:2} # the number of concurrent requests
    resultWindowMaxSize: ${SW_STORAGE_ES_QUERY_MAX_WINDOW_SIZE:10000}
    metadataQueryMaxSize: ${SW_STORAGE_ES_QUERY_MAX_SIZE:5000}
    segmentQueryMaxSize: ${SW_STORAGE_ES_QUERY_SEGMENT_SIZE:200}
    profileTaskQueryMaxSize: ${SW_STORAGE_ES_QUERY_PROFILE_TASK_SIZE:200}
    oapAnalyzer: ${SW_STORAGE_ES_OAP_ANALYZER:"{"analyzer":{"oap_analyzer":{"type":"stop"}}}"} # the oap analyzer.
    oapLogAnalyzer: ${SW_STORAGE_ES_OAP_LOG_ANALYZER:"{"analyzer":{"oap_log_analyzer":{"type":"standard"}}}"} # the oap log analyzer. It could be customized by the ES analyzer configuration to support more language log formats, such as Chinese log, Japanese log and etc.
advanced: ${SW_STORAGE_ES_ADVANCED:""}

这里主要是知道参数名

 

二:docker-compose部署skywalking

docker-compose.yml

version: '3.8'
services:
  oap-server:
    image: apache/skywalking-oap-server:8.9.0
    # image: docker.io/apache/skywalking-oap-server:9.4.0
    container_name: oap-server
    ports:
      - "11800:11800"
      - "12800:12800"
    environment:
      # 配置数据库存储(我这里没有在github找到mysql对应的表)
      # - SW_STORAGE=mysql
      # - SW_JDBC_URL=jdbc:mysql://127.0.0.1:3306/skywalking?useSSL=false
      # - SW_DATA_SOURCE_USER=root
      # - SW_DATA_SOURCE_PASSWORD=xxxxxxxxxxx
      # 配置elasticsearch存储
      # skywalking 8.8之前不能自动感知存储源是什么,需要手动指定是es6还是7;
      # 8.8之后可以自动感知存储源的版本,不需要手动指定es6还是7,直接写es即可;
      - SW_STORAGE=elasticsearch
      - SW_STORAGE_ES_CLUSTER_NODES=127.0.0.1:9200
      - SW_ES_USER=elastic
      - SW_ES_PASSWORD=xxxxxxxx
      - SW_CORE_RECORD_DATA_TTL=15
      - SW_CORE_METRICS_DATA_TTL=15
      - SW_ENABLE_UPDATE_UI_TEMPLATE=true
      - TZ=Asia/Shanghai
    # 健康检查,他不健康,我就不检查了~
    # healthcheck:
    #   test: ["CMD", "curl", "-f", "http://localhost:12800/health_check"]
    #   interval: 30s
    #   timeout: 10s
    #   retries: 3
    restart: on-failure
 
  ui:
    image: apache/skywalking-ui:8.9.0
    # image: docker.io/apache/skywalking-ui:9.4.0
    container_name: skywalking-ui
    depends_on:
      - oap-server
    links:
      - oap-server
    ports:
      - "8888:8080"
    environment:
      SW_OAP_ADDRESS: http://oap-server:12800
      # SW_ZIPKIN_ADDRESS: http://oap-server:9412
    # 健康检查
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health_check"]
      interval: 30s
      timeout: 10s
      retries: 3
    restart: on-failure

 

运行docker-compose命令:

docker compose up -d

 

如果你修改了docker-compose.yml对应的参数之后,使用如下命令即可重启而不用删除已存在的容器:

docker compose up --force-recreate -d

 

需要将上方中的127.0.0.1换成你对应的ip。

 

在这个配置中,我们定义了两个服务:oap-server和skywalking-ui。oap-server服务是SkyWalking的核心服务器,负责处理数据收集和分析。skywalking-ui服务是SkyWalking的Web界面,它提供对监控数据的可视化。

 

可以通过访问http://localhost:8888来访问SkyWalking UI,并开始监控你的分布式系统。如下图所示:

微信截图_20241226212450.png

 

三:报错

我这里先安装的是8.9版本,之后,又尝试安装9.4版本。安装9.4版本之后启动报错:

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "composable template [sw_zipkin_span] template after composition is invalid"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "composable template [sw_zipkin_span] template after composition is invalid",
        "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "invalid composite mappings for [sw_zipkin_span]",
            "caused_by": {
                "type": "mapper_parsing_exception",
                "reason": "Failed to parse mapping [_doc]: analyzer [oap_analyzer] has not been configured in mappings",
                "caused_by": {
                    "type": "illegal_argument_exception",
                    "reason": "analyzer [oap_analyzer] has not been configured in mappings"
                }
            }
        }
    },
    "status": 400
}

这个报错在官方issue中找到解答,由于挂载的es目录为原来8.9.0版本生成及采集的数据,导致es初始化数据失败,需要删除原目录数据 /home/elasticsearch/data 或者重新指定文件目录即可。

 

到这里,docker-compose部署skywalking就可以运行了。

 

有好的建议,请在下方输入你的评论。