DevOps AI
  • Home
  • Bảo mật
  • AI & Automation
  • DevOps & Cloud
  • Bộ đề luyện thi cloud
No Result
View All Result
DevOpsAI
  • Home
  • Bảo mật
  • AI & Automation
  • DevOps & Cloud
  • Bộ đề luyện thi cloud
No Result
View All Result
DevOpsAI
No Result
View All Result
Home DevOps & Cloud

Logging tomcat application trên ELK

Hiếu Tạ by Hiếu Tạ
30 Tháng 4, 2025
in DevOps & Cloud
0
Logging tomcat application trên ELK
Share on FacebookShare on Twitter

Logging Tomcat trên ELK (Elasticsearch, Logstash, Kibana) là quá trình tích hợp hệ thống ghi log của máy chủ Tomcat vào nền tảng ELK để thu thập, xử lý, trực quan hóa và phân tích dữ liệu log một cách hiệu quả.

  1. Elasticsearch (ES): Đây là nơi dữ liệu log được lưu trữ. ES giúp tìm kiếm và truy xuất dữ liệu nhanh chói thông qua cơ chế tìm kiếm phân tán.
  2. Logstash: Là thành phần trung gian, nó đảm nhận vai trò làm sạch và biến đổi dữ liệu log từ Tomcat trước khi gửi vào Elasticsearch. Logstash có các bộ lọc (filters) và ngõ vào/ra (input/output) phong phú, giúp tùy chỉnh quá trình tiếp nhận và xử lý log.
  3. Kibana: Giao diện người dùng đồ họa cho phép trực quan hóa dữ liệu log. Kibana cung cấp các biểu đồ, đồ thị, bản đồ, và công cụ truy vấn mạnh mẽ giúp hiểu rõ hơn về các sự kiện và xu hướng trong log.

Note: Trong bài này mình sẽ không hướng dẫn việc cài đặt Logstash/Kibana/Elasticsearch.

Setup Filebeat Agent

Download: https://www.elastic.co/downloads/beats/filebeat
Ở đây mình cài ở path: /u01/filebeat

Related Post

Tắt NLA trên Amazon EC2 Windows instance

Tắt NLA trên Amazon EC2 Windows instance

30 Tháng 4, 2025
Demo Tích Hợp Vault trong Kubernetes

Demo Tích Hợp Vault trong Kubernetes

30 Tháng 4, 2025

React Native: getting Started

4 Tháng 5, 2025

Hướng dẫn cài đặt Kubernetes trên Ubuntu 22.04

1 Tháng 5, 2025

Running Filebeat Service

With Centos version > 7

Path: /etc/systemd/system/filebeat.service

[Unit]
Description=Filebeat sends log files to Logstash or directly to Elasticsearch.
Documentation=https://www.elastic.co/beats/filebeat
Wants=network-online.target
After=network-online.target

[Service]

User=root
Group=root

UMask=0027
Environment="GODEBUG='madvdontneed=1'"
Environment="BEAT_LOG_OPTS="
Environment="BEAT_CONFIG_OPTS=-c /u01/filebeat/filebeat.yml"
Environment="BEAT_PATH_OPTS=--path.home /u01/filebeat --path.config /u01/filebeat --path.data /u01/filebeat/data --path.logs /u01/filebeat/logs"
ExecStart=/u01/filebeat/filebeat --environment systemd $BEAT_LOG_OPTS $BEAT_CONFIG_OPTS $BEAT_PATH_OPTS
Restart=always

[Install]
WantedBy=multi-user.target

systemctl daemon-reload 
systemctl start filebeat 
systemctl enabled filebeat

With Centos version < 7

the server hasn’t systemctl => run via init. Path: /etc/init.d/filebeat

#!/bin/sh
### BEGIN INIT INFO
# Provides:          filebeat
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Elastic Filebeat
### END INIT INFO
status() {
    pidfile=$(cat /u01/filebeat/filebeat.pid)
    if ps -p $pidfile > /dev/null 2>&1
    then
        echo "Filebeat is running"
    else
        echo "Filebeat is not running"
    fi
}
case $1 in
  status)
    status
    ;;
  start)
    nohup /u01/filebeat/filebeat --environment systemd -c /u01/filebeat/filebeat.yml -path.home /u01/filebeat -path.config /u01/filebeat -path.data /u01/filebeat/data -path.logs /u01/filebeat/logs >/dev/null 2>&1 &
    echo $! > /u01/filebeat/filebeat.pid
    ;;
  stop)
    kill $(cat /u01/filebeat/filebeat.pid)
    ;;
  restart)
    $0 stop
    sleep 1
    $0 start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|status}"
esac

exit 0

service filebeat start 
service filebeat stop 
service filebeat status

Send logs filebeat to Logstash

Path: /u01/filebeat/filebeat.yml (bởi vì mình đã cài filebeat ở path này)
Add filebeat follow format below: <project_name>-<SERVER_IP>

Lưu ý: phần output.logstash thì sẽ cấu hình ip:port của logstash mà filebeat sẽ send logs tới

- type: log
  enabled: true
  paths:
    - /path/file_log
  tag: ["<project_name>-<SERVER_IP>"]

- type: log
  enabled: true
  paths:
    - /path/file_log
  tag: ["<project_name>-<SERVER_IP>"]

systemctl restart filebeat or service filebeat restart

Logstash custom index for Elasticsearch

Ở logstash, mình tạo 2 file cho 2 môi trường khác nhau như preprod/test

Path:

  • preprod env: /etc/logstash/conf/preprod-conf
  • test env: /etc/logstash/conf/test-conf

Note: the tags should be same at filebeat.yml config

filter{
  grok {
    match => { "message" => "%" }
  }
}
output {
  if "<project_name>-<SERVER_IP>" in [tags]{
    elasticsearch {
      hosts => ["http://localhost:9200"]
      index => "<project_name>-<SERVER_IP>-%{+YYYY.MM.dd}"
    }
  } else if "<project_name>-<SERVER_IP>" in [tags] {
	 elasticsearch {
	   hosts => ["<http://localhost:9200>"]
	   index => "<project_name>-<SERVER_IP>-%{+YYYY.MM.dd}
	 }
  }

}
 

Trước đó, mình sẽ tạo 1 file input tên là

cat 02-beats-input.conf

input {
  beats {
    host => "0.0.0.0"
    port => 8100
  }
}

systemctl restart logstash

Create an index at Kibana

Waiting one moment for Logstash send logs to Elasticsearch

then create index follow format: <project_name>-<SERVER_IP>*

Quay lại Discover để add index đã tạo

Chúc các bạn thành công!

Tags: agentcentosdevelkenvironmentfilebeathttpkibananetworksetupversion
Hiếu Tạ

Hiếu Tạ

Graduated as a Software Engineer. I have more than 3-year experience in developing software and DevOps, used to many services of AWS, and Azure, K8S, and using Windows or Linux on-premies proficiently to set up servers, proxy, build and deploy multiple programming languages (Java, GO, NET,...)..... Experience with CMS such SiteCore, ElasticPath, AEM... Implement CICD via Jenkins scripting, infrastructure as code via Terraform, and AWS Cloud Formation.

Related Posts

Tắt NLA trên Amazon EC2 Windows instance
DevOps & Cloud

Tắt NLA trên Amazon EC2 Windows instance

by Hiếu Tạ
30 Tháng 4, 2025
Demo Tích Hợp Vault trong Kubernetes
DevOps & Cloud

Demo Tích Hợp Vault trong Kubernetes

by Hiếu Tạ
30 Tháng 4, 2025
React Native: getting Started
DevOps & Cloud

React Native: getting Started

by devopsify
4 Tháng 5, 2025
Next Post

Cấu hình build Docker trong Jenkins

Để lại một bình luận Hủy

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Recommended

Các website demo hay được sử dụng cho thực hành Automation Test

Các website demo hay được sử dụng cho thực hành Automation Test

11 Tháng 6, 2025
Hướng dẫn cài đặt Kubernetes trên Ubuntu 22.04

Hướng dẫn cài đặt Kubernetes trên Ubuntu 22.04

1 Tháng 5, 2025
Cài đặt Maven trên Windows

Cài đặt Maven trên Windows

11 Tháng 6, 2025
Cài đặt Grafana – Loki – Promtail monitoring log Container

Cài đặt Grafana – Loki – Promtail monitoring log Container

1 Tháng 5, 2025
Sử dụng VS Code và Playwright MCP tự động test demo website Demoblaze thông qua GitHub Copilot Agent

Sử dụng VS Code và Playwright MCP tự động test demo website Demoblaze thông qua GitHub Copilot Agent

16 Tháng 6, 2025
MCP server 2025 tốt nhất : Hướng dẫn chọn & bảo mật

MCP server 2025 tốt nhất : Hướng dẫn chọn & bảo mật

16 Tháng 6, 2025
DevOpsify Check Tool hỗ trợ MCP – Tự động hóa kiểm tra qua AI Claude & VS Code

DevOpsify Check Tool hỗ trợ MCP – Tự động hóa kiểm tra qua AI Claude & VS Code

13 Tháng 6, 2025
GitHub Action DevOpsify Check Tool – Tự động kiểm tra bảo mật & hiệu suất

GitHub Action DevOpsify Check Tool – Tự động kiểm tra bảo mật & hiệu suất

11 Tháng 6, 2025
DevOpsify

Cộng đồng DevOps Việt Nam chia sẽ kiến thức giúp tăng tốc quá trình phát triển ứng dụng và tự động hóa trong lĩnh vực Cloud DevOps & AI.

Bài viết mới

  • Sử dụng VS Code và Playwright MCP tự động test demo website Demoblaze thông qua GitHub Copilot Agent
  • MCP server 2025 tốt nhất : Hướng dẫn chọn & bảo mật
  • DevOpsify Check Tool hỗ trợ MCP – Tự động hóa kiểm tra qua AI Claude & VS Code

Categories

  • AI & Automation
  • Bảo mật
  • Chưa phân loại
  • DevOps & Cloud
  • Tin tức
No Result
View All Result
  • Home
  • Bảo mật
  • AI & Automation
  • DevOps & Cloud
  • Bộ đề luyện thi cloud

© 2025 DevOpsify