Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[Logstash] Install Logstash and send logs from Kong Gateway to Logstash. So fast and easy – ELK

Posted on January 19, 2022February 1, 2022 By nim No Comments on [Logstash] Install Logstash and send logs from Kong Gateway to Logstash. So fast and easy – ELK

Logstash is a free and open server-side data processing pipeline that ingests data from a multitude of sources, transforms it, and then sends it to your favorite “stash.”

Contents

Toggle
  • 1) Install Logstash
    • 1.1) Check version Elastic
    • 1.2) repair data before install
  • 2) Practise
    • 2.1) Config Kong to send UDP to Logstash
    • 2.2) Recheck result
    • 2.3) Custome index.

1) Install Logstash

https://www.elastic.co/downloads/logstash
https://github.com/deviantony/docker-elk
Ở link trên thì bạn sẽ thấy rất nhiều cách download cũng như cài đặt logstash.

Hiện tại mình run docker-compose cho nó nhanh và chúng ta cũng dễ dàng nâng version he!

1.1) Check version Elastic

Đầu tiên kiểm tra phiên bạn elastic mà bạn đang chạy là bao nhiều:
curl -XGET 'localhost:9200'

Nhớ version nhé.

1.2) repair data before install

root@elastic1-u20:~/docker# ls
docker-compose.yml  kibana
root@elastic1-u20:~/docker# mkdir logstash
root@elastic1-u20:~/docker# ls
docker-compose.yml  kibana  logstash
root@elastic1-u20:~/docker# cd logstash/
root@elastic1-u20:~/docker/logstash# mkdir config
root@elastic1-u20:~/docker/logstash# mkdir pipeline
root@elastic1-u20:~/docker/logstash# ls
config  pipeline

Giờ tiến hành tạo các file config.

và để cấu hình ngon nghẻ ngày từ đầu thì anh em có thể tham khao bài biết sao:
[Logstash] Multi config, input, filter, output trong 1 logstash mà không gây ra sung đột cấu hình receive logs

file config/logstash.yml cấu hình logstash kết nối với elastic.

vi config/logstash.yml

---
## Default Logstash configuration from Logstash base image.
## https://github.com/elastic/logstash/blob/master/docker/data/logstash/config/logstash-full.yml
#
http.host: "0.0.0.0"
xpack.monitoring.elasticsearch.hosts: [ "http://<IP-Elastic>:9200" ]

## X-Pack security credentials
#
# xpack.monitoring.enabled: true
# xpack.monitoring.elasticsearch.username: elastic
# xpack.monitoring.elasticsearch.password: xxxxxxx

file config/pipelines.yml dùng để chúng ta phân chia pipeline ra.
Con logstash nhận được nhiều loại logs và từ nhiều server hay nhiều dịch vụ.

Ví dụ tạo riêng pipeline.id và port cho 1 service log nào đó.
ý tưởng là như thế.

vi config/pipelines.yml

# This file is where you define your pipelines. You can define multiple.
# For more information on multiple pipelines, see the documentation:
#   https://www.elastic.co/guide/en/logstash/current/multiple-pipelines.html

- pipeline.id: kong
  path.config: "/usr/share/logstash/pipeline/kong.conf"

Bài này mình sẽ cấu hình thực tế nhận log từ Kong

vi pipeline/kong.conf

# See https://www.elastic.co/guide/en/logstash/current/configuration-file-structure.html for detail

# Input is from UDP port 5000
input {
  udp {
    port => "5000"
  }
}

# Original Kong log is on JSON format and will be send to elasticsearch in field “message”. 
# So we need to take the json from field “message”, and read the original format.
filter {
  json {
    source => "message"
    add_tag => ["kong"]
  }

#  mutate {
#     remove_field => [ "message" ]
#  }

  geoip {
    source => "client_ip"
  }
}

## Add your filters / logstash plugins configuration here

output {
        elasticsearch {
                hosts => "<IP-Elastic>:9200"
                ecs_compatibility => disabled
        }
}

Ở config trên:
Mình mở port 5000/UDP để Kong gửi vào.
Mình sử dụng filter JSON và có add thêm tag kong
Mình có sử dụng geoip để đổi IP ra vị trí

Dưới này là docker-compose

version: '3.2'

services:
  logstash:
    image: docker.elastic.co/logstash/logstash:7.16.3
    volumes:
      - ./logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml:ro,z
      - ./logstash/pipeline:/usr/share/logstash/pipeline:ro,z
      - ./logstash/config/pipelines.yml:/usr/share/logstash/config/pipelines.yml:ro,z
    ports:
      - "5000:5000/udp"
    environment:
      LS_JAVA_OPTS: "-Xmx512m -Xms512m"

docker-compose up -d và chờ kết quả.

2) Practise

2.1) Config Kong to send UDP to Logstash

Vào Kong -> plugin tạo 1 udp-log

Giờ trờ lại giao diện của kibana kiểm tra

2.2) Recheck result

Như này là có vẻ elastic đã nhận log của logstash

Để kiểm tra kĩ hơn chúng ta cần tạo Index patterns

Ở phân này có lưu ý:
việc show advance chỉ để cho dui thôi.
chứ bạn ko nên đúng vào các resource có dấu chấm ở đầu nhé
Vì đó là các resources hệ thống
bạn nhập logstash* thì bạn nó bao gồm 2 resource bên tay phải
thấy có chữ Kong là ok rồi nhận log Kong òi

2.3) Custome index.

Như ở trên bạn sẽ thấy index sẽ là logstash*
và thường chúng ta hay tạo index theo từng loại server

# See https://www.elastic.co/guide/en/logstash/current/configuration-file-structure.html for detail

# Input is from UDP port 5000
input {
  udp {
    port => "5000"
  }
}

# Original Kong log is on JSON format and will be send to elasticsearch in field “message”. 
# So we need to take the json from field “message”, and read the original format.
filter {
  json {
    source => "message"
    add_tag => ["kong"]
  }

#  mutate {
#     remove_field => [ "message" ]
#  }

  geoip {
    source => "client_ip"
  }
}

## Add your filters / logstash plugins configuration here

output {
  elasticsearch {
    hosts => "<IP-Elastic>:9200"
    index => "kongapi-%{+YYYY.MM.dd}"
  }
}

Bạn thấy là chúng ta sẽ để như này: index => "kongapi-%{+YYYY.MM.dd}"

Nhưng mà khi bạn đổi sang index khác thì mình nhận ra là Kinana nó ko hiểu các field geoip.* để chúng ta vẽ bảng đồ
Các bạn cũng không cần lo vì mình sẽ hướng dẫn nhé

ELK, Logstash

Post navigation

Previous Post: [Helm-chart] Declare “template” in helm-chart – Kubernetes
Next Post: [Kibana] Tutorial export and import much data(dashboard,…) in Kibana – ELK

More Related Articles

[APM/Elastic] Install APM Elastic inside container WordPress. ELK
[Logstash] Discovering Pipeline inside Logstash ELK
[Elasticsearch] reason=Validation Failed: 1: this action would add [10] total shards, but this cluster currently has [1000]/[1000] maximum shards open;]]] ELK
[logstash/kibana] Draw a Map on Kibana by data from Logstash – Fix “Index pattern does not contain any geospatial fields” ELK
[Fortigate] Cấu hình firewall fortigate gửi syslog sang Logstash BareMetal
[Logstash] Multi config, input, filter, output inside a Logstash server and Not conflict ELK

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Azure] The subscription is not registered to use namespace ‘Microsoft.ContainerService’ May 8, 2025
  • [Azure] Insufficient regional vcpu quota left May 8, 2025
  • [WordPress] How to add a Dynamic watermark on WordPress. May 6, 2025
  • [vnet/Azure] VNet provisioning via Terraform. April 28, 2025
  • [tracetcp] How to perform a tracert command using a specific port. April 3, 2025

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.