Hướng dẫn cài đặt SkyWalking từ đầu: Hướng dẫn chi tiết

Giới thiệu

SkyWalking là một dự án mã nguồn mở ban đầu được phát triển bởi Wu Sheng, một kỹ sư tài năng từ Huawei. Hiện tại, dự án đã tham gia vào Apache Incubator. Mục tiêu cốt lõi của SkyWalking là cung cấp giám sát hiệu suất ứng dụng và theo dõi chuỗi gọi phân tán cho kiến trúc vi dịch vụ, Cloud Native và containerized. SkyWalking hỗ trợ nhiều thành phần phổ biến như dubbo, motan, spring boot, spring cloud, v.v.

Kiến trúc tổng thể của SkyWalking bao gồm ba thành phần chính:

  1. skywalking-collector: Bộ thu thập dữ liệu chuỗi, có thể lưu trữ dữ liệu trong H2 hoặc ElasticSearch
  2. skywalking-web: Giao diện web quản lý, cho phép xem dữ liệu đã thu thập
  3. skywalking-agent: Agent để thu thập và gửi dữ liệu đến bộ thu thập

Cài đặt môi trường

Bây giờ chúng ta sẽ bắt đầu cài đặt môi trường SkyWalking từ đầu.

Bước 1: Cài đặt Elasticsearch

  1. Tải Elasticsearch
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.10.tar.gz
  1. Giải nén tệp
tar -vxf elasticsearch-5.6.10.tar.gz
  1. Cấu hình Elasticsearch
cd /elasticsearch-5.6.10/config
vim elasticsearch.yml

Cấu hình tham số:

cluster.name: CollectorDBCluster
node.name: CollectorDBCluster
network.host: 127.0.0.1
  1. Khởi động Elasticsearch
./bin/elasticsearch

Nếu gặp lỗi:

OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /home/elasticsearch-5.6.10/hs_err_pid1738.log

Đây là vấn đề về cấu hình bộ nhớ JVM. Cần sửa đổi cấu hình:

cd config
vim jvm.options

Đặt tham số -Xms4g và -Xmx4g, và comment các dòng -Xms2g và -Xmx2g.

Khởi động lại Elasticsearch, nếu gặp lỗi:

Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93)
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:144)
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:285)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
        Refer to the log for complete error details.

Lý do là Elasticsearch không cho phép khởi động bằng tài khoản root. Cần chuyển sang tài khoản khác trước khi khởi động.

Cuối cùng, Elasticsearch khởi động thành công:

[2019-03-26T23:40:37,583][INFO ][o.e.n.Node               ] [] initializing ...
[2019-03-26T23:40:37,677][INFO ][o.e.e.NodeEnvironment    ] [5DFSDCK] using [1] data paths, mounts [[/ (/dev/disk1s1)]], net usable_space [187.5gb], net total_space [233.4gb], spins? [unknown], types [apfs]
[2019-03-26T23:40:37,678][INFO ][o.e.e.NodeEnvironment    ] [5DFSDCK] heap size [1.9gb], compressed ordinary object pointers [true]
[2019-03-26T23:40:37,679][INFO ][o.e.n.Node               ] node name [5DFSDCK] derived from node ID [5DFSDCK_QhibMsJg734Ysg]; set [node.name] to override
[2019-03-26T23:40:37,679][INFO ][o.e.n.Node               ] version[5.6.10], pid[22167], build[b727a60/2018-06-06T15:48:34.860Z], OS[Mac OS X/10.13.6/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_191/25.191-b12]
[2019-03-26T23:40:37,679][INFO ][o.e.n.Node               ] JVM arguments [-Xms2g, -Xmx2g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/Users/xingwuxu/tools/elasticsearch-5.6.10]
[2019-03-26T23:40:38,317][INFO ][o.e.p.PluginsService     ] [5DFSDCK] loaded module [aggs-matrix-stats]
[2019-03-26T23:40:38,317][INFO ][o.e.p.PluginsService     ] [5DFSDCK] loaded module [ingest-common]
[2019-03-26T23:40:38,317][INFO ][o.e.p.PluginsService     ] [5DFSDCK] loaded module [lang-expression]
[2019-03-26T23:40:38,317][INFO ][o.e.p.PluginsService     ] [5DFSDCK] loaded module [lang-groovy]
[2019-03-26T23:40:38,317][INFO ][o.e.p.PluginsService     ] [5DFSDCK] loaded module [lang-mustache]
[2019-03-26T23:40:38,317][INFO ][o.e.p.PluginsService     ] [5DFSDCK] loaded module [lang-painless]
[2019-03-26T23:40:38,317][INFO ][o.e.p.PluginsService     ] [5DFSDCK] loaded module [parent-join]
[2019-03-26T23:40:38,317][INFO ][o.e.p.PluginsService     ] [5DFSDCK] loaded module [percolator]
[2019-03-26T23:40:38,317][INFO ][o.e.p.PluginsService     ] [5DFSDCK] loaded module [reindex]
[2019-03-26T23:40:38,317][INFO ][o.e.p.PluginsService     ] [5DFSDCK] loaded module [transport-netty3]
[2019-03-26T23:40:38,318][INFO ][o.e.p.PluginsService     ] [5DFSDCK] loaded module [transport-netty4]
[2019-03-26T23:40:38,318][INFO ][o.e.p.PluginsService     ] [5DFSDCK] no plugins loaded
[2019-03-26T23:40:39,595][INFO ][o.e.d.DiscoveryModule    ] [5DFSDCK] using discovery type [zen]
[2019-03-26T23:40:39,976][INFO ][o.e.n.Node               ] initialized
[2019-03-26T23:40:39,976][INFO ][o.e.n.Node               ] [5DFSDCK] starting ...
[2019-03-26T23:40:40,167][INFO ][o.e.t.TransportService   ] [5DFSDCK] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2019-03-26T23:40:43,226][INFO ][o.e.c.s.ClusterService   ] [5DFSDCK] new_master {5DFSDCK}{5DFSDCK_QhibMsJg734Ysg}{PFrWZNI9RHWNAneytiifdA}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)[, ]
[2019-03-26T23:40:43,242][INFO ][o.e.h.n.Netty4HttpServerTransport] [5DFSDCK] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2019-03-26T23:40:43,243][INFO ][o.e.n.Node               ] [5DFSDCK] started
[2019-03-26T23:40:43,248][INFO ][o.e.g.GatewayService     ] [5DFSDCK] recovered [0] indices into cluster_state

ElasticSearch khởi động thành công, lắng nghe trên cổng 9200. Bạn có thể mở trình duyệt và truy cập http://127.0.0.1:9200 để xem thông tin cơ bản của Elasticsearch.

Bước 2: Cài đặt SkyWalking

  1. Tải SkyWalking
curl -L -O https://mirrors.tuna.tsinghua.edu.cn/apache/incubator/skywalking/6.0.0-GA/apache-skywalking-apm-incubating-6.0.0-GA.tar.gz
  1. Giải nén tệp
tar -vxf apache-skywalking-apm-incubating-6.0.0-GA.tar.gz
  1. Cấu hình tệp cấu hình, chuyển từ H2 sang Elasticsearch
storage:
#  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}
  elasticsearch:
    # nameSpace: ${SW_NAMESPACE:""}
    clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:localhost:9200}
    indexShardsNumber: ${SW_STORAGE_ES_INDEX_SHARDS_NUMBER:2}
    indexReplicasNumber: ${SW_STORAGE_ES_INDEX_REPLICAS_NUMBER:0}
  1. Khởi động SkyWalking bằng lệnh start.sh trong thư mục bin
./start.sh

Log sẽ hiển thị:

SkyWalking OAP started successfully!
SkyWalking Web Application started successfully!

SkyWalking khởi động thành công. Mở trình duyệt và truy cập http://localhost:8080 để xem giao diện.

Mật khẩu mặc định cho giao diện quản trị SkyWalking là: admin/admin.

Sau khi đăng nhập, bạn sẽ thấy giao diện quản trị của SkyWalking.

Đến đây, môi trường cơ bản của SkyWalking đã được cài đặt hoàn chỉnh. Bây giờ chúng ta có thể bắt đầu khám phá các tính năng cụ thể của SkyWalking và cách sử dụng chúng trong thực tế.

Thẻ: Elasticsearch SkyWalking APM monitoring distributed tracing

Đăng vào ngày 25 tháng 5 lúc 23:31