目录
软件名称 版本
Nacos 下载地址 1.1.4
Skywalking 下载地址 6.5.0
Elasticsearch 下载地址 6.8.2

准备工作

搭建Nacos集群

在手记《 搭建生产可用的Nacos集群 》一文中有详细说明。

搭建Elasticsearch集群

详见 ElasticSearch-6.7.0之集群环境搭建

搭建Skywalking集群

准备工作完成后,下面来搭建一个2实例的Skywalking集群。由于我只有1台服务器,所以就把两个Skywalking实例搭建在一起了。实际项目中应当将不同Skywalking实例部署在不同服务器。

主机规划

实例 IP 占用端口
Skywalking 实例1 127.0.0.1 11800(gRPC)、12800(REST)、8080(UI)
Skywalking 实例2 127.0.0.1 11801(gRPC)、12801(REST)

TIPS

这里,我们只搭建了一个UI,实际项目也可搭建多个UI,然后在UI前面再挂个NGINX之类的反向代理工具。

开始搭建

解压

  • apache-skywalking-apm-6.5.0.tar 复制两份,并解压。

backend相关配置

  • 修改 config/application.yml ,找到类似如下的段落,按需修改IP和端口。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    core:
    default:
    # Mixed: Receive agent data, Level 1 aggregate, Level 2 aggregate
    # Receiver: Receive agent data, Level 1 aggregate
    # Aggregator: Level 2 aggregate
    role: ${SW_CORE_ROLE:Mixed} # Mixed/Receiver/Aggregator
    restHost: ${SW_CORE_REST_HOST:0.0.0.0}
    restPort: ${SW_CORE_REST_PORT:12800}
    restContextPath: ${SW_CORE_REST_CONTEXT_PATH:/}
    gRPCHost: ${SW_CORE_GRPC_HOST:0.0.0.0}
    gRPCPort: ${SW_CORE_GRPC_PORT:11800}

    注:gRPCHost、gRPCPort是agent发送数据的地址,restHost、restPort是UI请求的地址

  • 找到类似如下的段落,按需配置Nacos相关信息。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    cluster:
    # 注意,务必注释掉standalone这一行。默认情况下用的单机模式(standalone),现在要改成集群模式,所以得注释掉。否则Skywalking将无法启动!
    # standalone:
    nacos:
    # Skywalking在Nacos Server的服务名称
    serviceName: ${SW_SERVICE_NAME:"SkyWalking_OAP_Cluster"}
    # Nacos Server地址用http://ip:端口的形式
    hostPort: ${SW_CLUSTER_NACOS_HOST_PORT:localhost:8848}
    # Nacos的namespace
    namespace: 'public'
  • 找到类似如下的段落,按需配置Elasticsearch相关信息,一般配置clusterNodes即可。

    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
    storage:
    elasticsearch:
    # Elasticsearch的namespace
    nameSpace: ""
    # Elasticsearch集群的Node列表,多个用,分隔例如:localhost:9200,localhost:9201
    clusterNodes: localhost:9200
    # 和Elasticsearch集群通信的协议
    # protocol: ${SW_STORAGE_ES_HTTP_PROTOCOL:"http"}
    # 证书
    # trustStorePath: ${SW_SW_STORAGE_ES_SSL_JKS_PATH:"../es_keystore.jks"}
    # trustStorePass: ${SW_SW_STORAGE_ES_SSL_JKS_PASS:""}

    # user: ${SW_ES_USER:""}
    # password: ${SW_ES_PASSWORD:""}
    # indexShardsNumber: ${SW_STORAGE_ES_INDEX_SHARDS_NUMBER:2}
    # indexReplicasNumber: ${SW_STORAGE_ES_INDEX_REPLICAS_NUMBER:0}
    # Those data TTL settings will override the same settings in core module.
    # recordDataTTL: ${SW_STORAGE_ES_RECORD_DATA_TTL:7} # Unit is day
    # otherMetricsDataTTL: ${SW_STORAGE_ES_OTHER_METRIC_DATA_TTL:45} # Unit is day
    # monthMetricsDataTTL: ${SW_STORAGE_ES_MONTH_METRIC_DATA_TTL:18} # Unit is month
    # Batch process setting, refer to https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.5/java-docs-bulk-processor.html
    # bulkActions: ${SW_STORAGE_ES_BULK_ACTIONS:1000} # Execute the bulk every 1000 requests
    # flushInterval: ${SW_STORAGE_ES_FLUSH_INTERVAL:10} # flush the bulk every 10 seconds whatever the number of requests
    # 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}
  • 注释掉如下段落。这是因为默认情况Skywalking将数据存储在H2,但现在已经用Elasticsearch存储数据了,所以不需要用H2了。

    1
    2
    3
    4
    5
    h2:
    driver: ${SW_STORAGE_H2_DRIVER:org.h2.jdbcx.JdbcDataSource}
    url: ${SW_STORAGE_H2_URL:jdbc:h2:mem:skywalking-oap-db}
    user: ${SW_STORAGE_H2_USER:sa}
    metadataQueryMaxSize: ${SW_STORAGE_H2_QUERY_MAX_SIZE:5000}

    UI相关配置

  • 修改 webapp/webapp.yml ,找到类似如下段落,修改listofServers。

    1
    2
    3
    4
    5
    6
    7
    8
    server:
    port: 8080
    collector:
    path: /graphql
    ribbon:
    ReadTimeout: 10000
    # Point to all backend's restHost:restPort, split by ,
    listOfServers: 127.0.0.1:12800,127.0.0.1:12801

    启动

启动后端(2个实例)

1
sh bin/oapService.sh

启动UI(1个实例)

1
sh bin/webappService.sh

agent使用

  • 修改 agent/config/agent.config ,将 collector.backend_service 修改为 127.0.0.1:11800,127.0.0.1:11801
  • 启动应用 java -javaagent:/xxxx/skywalking-agent.jar -jar xxxx.jar

效果

Nacos Server上可以看到两个Skywalking实例:

Nacos Server

Skywalking UI首页:

Skywalking UI首页

Skywalking UI拓扑图:

Skywalking UI拓扑图

相关文章