Upgrade to Pro — share decks privately, control downloads, hide ads and more …

elastic stack in operation

elastic stack in operation

Dùng elastic stack để phân tích log, trực quan hóa dữ liệu trong vận hành

thanhgit

June 21, 2020
Tweet

More Decks by thanhgit

Other Decks in Technology

Transcript

  1. ELASTIC STACK IN OPERATION
    By Thanh Nguyen

    View Slide

  2. Nội dung
    1. Tìm hiểu về elastic stack
    2. Một số đầu việc cụ thể
    3. Best practice trong vận hành

    View Slide

  3. 1. Tìm hiểu về elastic stack
    - Beats: dùng để lấy dữ liệu file log hoặc metrics, sau
    đó đẩy về logstash hoặc elasticsearch
    ● Filebeat: lấy dữ liệu từ file log
    ● Metricbeat: lấy dữ liệu cpu, memory, filesystem trên
    máy host

    View Slide

  4. 1. Tìm hiểu về elastic stack
    - Logstash: xử lý dữ liệu và định nghĩa index data lên
    elasticsearch
    ● input module: định nghĩa dữ liệu đầu vào
    ● filter: lọc data, cũng như transform data
    ● output: đẩy data đến một repository khác, thông
    thường là elasticsearch

    View Slide

  5. 1. Tìm hiểu về elastic stack
    - Elasticsearch: lưu trữ dữ liệu, index data
    ● Nơi lấy dữ liệu, đáp ứng nhu cầu của những ứng
    dụng khác
    ● Hỗ trợ kibana visualize data

    View Slide

  6. 1. Tìm hiểu elastic stack
    - Kibana: khám phá, visualize, tạo dashboard đối với dữ
    liệu
    ● Index data, transform data hỗ trợ cho những chức
    năng liên quan như visualize, tìm insight
    ● Hỗ trợ cấu hình elasticsearch
    ● Elastalert plugin cho cảnh báo

    View Slide

  7. 2. Một số đầu việc cụ thể
    1. Cấu hình filebeat và metricbeat
    2. Cấu hình logstash
    3. Một số thứ cần làm trong kibana
    4. Tạo cảnh báo trên kibana
    5. Ảo hóa với vmware ESXi

    View Slide

  8. 2. 1.1Cấu hình metricbeat
    B1: download file metricbeat
    B2: cài đặt trên hệ thống
    B3: cấu hình
    ● Dùng metricbeat modules để biết số module nào
    đã enable và disable
    ● Dùng lệnh: [metricbeat test config] hoặc
    [metricbeat test output]

    View Slide

  9. 2.1.1 Cấu hình metricbeat
    - Cấu hình file ở /etc/metricbeat/metricbeat.yaml
    Output.logstash:
    hosts: ["localhost:5044"]
    hoặc
    Output.elasticsearch:
    hosts:["localhost:9200"]

    View Slide

  10. 2. 2.2Cấu hình filebeat
    B1: download file fiebeat
    B2: cài đặt trên hệ thống
    B3: cấu hình
    ● Xác định file logs
    ● Dùng lệnh: [filebeat test config] hoặc [filebeat test
    output]
    ● $ filebeat -c /etc/filebeat/filebeat.yml -e

    View Slide

  11. 2.1.2 Cấu hình filebeat
    - Cấu hình file ở /etc/filebeat/filebeat.yml

    View Slide

  12. 2.1.2 Cấu hình filebeat
    - Cấu hình file ở /etc/filebeat/filebeat.yaml
    Output.logstash:
    hosts: ["localhost:5044"]
    hoặc
    Output.elasticsearch:
    hosts:["localhost:9200"]

    View Slide

  13. 2. 2 Cấu hình logstash
    B1: download file logstash
    B2: cài đặt trên hệ thống
    B3: cấu hình gồm 3 phần trong thư mục
    /etc/logstash/conf.d/
    ● Input module
    ● Filter module
    ● Output module

    View Slide

  14. 2. 2 Cấu hình logstash
    1. Input module
    - Thường thì metricbeat hoặc filebeat bắn vào logstash
    qua cổng 5044

    View Slide

  15. 2. 2 Cấu hình logstash
    2. Filter module

    View Slide

  16. 2. 2 Cấu hình logstash
    2. Filter module: chú ý cần thử mỗi một mutate cho mỗi
    vai trò

    View Slide

  17. 2. 2 Cấu hình logstash
    2. Filter module

    View Slide

  18. Continuous
    if [source] =~ /all.log/ {
    split { field => "[data]"}
    split {field => "[data][Event]" }
    split { field => "[checkEvent][_source][Event]"}
    }

    View Slide

  19. Continuous
    mutate {
    Add_field => { “new_field” => 1 }
    }
    Mutate {
    Convert => { “new_field” => “integer” }
    }

    View Slide

  20. 2. 2Cấu hình logstash
    3. Output module

    View Slide

  21. Một số command trong logstash
    $ logstash -f logstash.conf --config.reload.automatic
    --config.reload.interval 3

    View Slide

  22. Một số chú ý
    - Từ version 6 trở về trước:
    + [source]
    - Từ version 7 trở đi:
    + [_source]

    View Slide

  23. Một số chú ý
    - Gọi trường bên trong json object source hoặc _source
    {
    ... _source { "position": "/var/log/demo/stations.log" } ...
    }
    logstash: => if [position] ==
    "/var/log/demo/stations.log" { ... }

    View Slide

  24. 3. Một số thứ cần làm trong kibana
    - Tạo index data cho dữ liệu:
    - Transform data
    - Thêm một field
    - Explore data để tìm insight data, bước chuẩn bị cho visualize data
    - Visualize data dựa trên các đặc tính data để trực quan hóa những gì ta
    cần biết với dữ liệu
    - Tạo dashboard đẹp với cấu trúc layout hợp lý, nhằm giúp cho người
    xem dễ hiểu
    - Note: mỗi khi bắn logs từ nguồn mới cần refresh index trước search

    View Slide

  25. input script
    {
    "script"; {
    "lang": "painless",
    "source": "_value*16.2"
    }
    }

    View Slide

  26. 4. Tạo cảnh báo với elastalert
    B1: cài kibana-plugin elastalert-kibana-plugin
    B2: cài đặt server elastalert
    B3: cấu hình cảnh báo

    View Slide

  27. Continuous
    Cấu hình elasticsearch (tập khảo sát)

    View Slide

  28. Continuous
    Khai báo những thuộc tính thông dụng trong elastalert
    như: kiểu event, tần số xuất hiện, thời gian, index nào
    khả dụng

    View Slide

  29. Continuous
    Một số thuộc tính lọc, cũng như detect event, khoảng
    thời gian alert lại

    View Slide

  30. Continuous
    Cấu hình alert sẽ đến đâu (ở đây là telegram) với thông điệp gì

    View Slide

  31. Continuous

    View Slide

  32. Continuous
    Các thuộc tính search, filter tương tự như elasticsearch
    nhưng cách khai báo theo chuẩn yaml

    View Slide

  33. Continuous

    View Slide

  34. 5. Ảo hóa với vmware ESXi
    https://masteringvmware.com/how-to-install-esxi-6-7-step-by-step/

    View Slide

  35. 6. Một số lệnh thông dụng thường dùng
    trong linux
    $ ping 8.8.8.8
    $ netstat -lnp | grep 9200
    $ netstat -antup
    $ curl -v --noproxy “*” http://192.168.10.5:9200

    View Slide