ThuanLeHiep
Intern
1. Giới thiệu công cụ
1.1 OpenSearch
1.2 Fluentd
Bằng cách hợp nhất log từ mọi nguồn, Fluentd giúp chúng ta có cái nhìn tổng quan, chẳng hạn như xác định liệu lỗi từ ứng dụng có bắt nguồn từ cơ sở dữ liệu, hay vấn đề của hệ điều hành gây ra
Chọn Logstash nếu bạn cần một giải pháp xử lý log toàn diện, có khả năng xử lý luồng dữ liệu phức tạp và ứng dụng các bộ lọc logic nâng cao. Đặc biệt, Logstash là lựa chọn tối ưu nếu hệ thống của bạn đã sử dụng hoặc có kế hoạch triển khai Elastic Stack, vì nó tích hợp hoàn hảo với các công cụ như Elasticsearch để tìm kiếm và phân tích log
1.3 Fluentbit
Đây là lý do Fluent Bit ra đời. Fluent Bit là một phiên bản rút gọn của Fluentd, với các tính năng đơn giản hơn, tập trung vào việc thu thập và gửi log đến hệ thống trung tâm để xử lý. Tại đó, Fluentd có thể thực hiện các công việc xử lý log phức tạp hơn, như lọc, chuyển đổi và làm giàu dữ liệu.
2. Mô hình hệ thống
Các thành phần trong mô hình:
3. Cấu hình và cài đặt
3.1 Cài đặt server (Ubuntu24.04/10.30.194.101)
Truy cập opensearch dashboard thông qua http://10.30.194.101:5601
Username: admin
Password: Thuan@123
3.2 Cài đặt host linux
Dùng lệnh do fluentbit để cài đặt nhanh chóng trên linux:
Dùng lệnh:
Khởi động fluentbit :
Kiểm tra trạng thái hoạt động của fluentbit :
Truy cập vào /etc/fluent-bit/fluent-bit.conf để cấu hình
Các section cấu hình
3.3 Cài đặt host Windows
Sau khi tải về chạy file exe để cài đặt
Khởi động service fluent-bit sc.exe start fluent-bit
Cài đặt cho fluent-bit khởi động tự động khi máy windows được bật
3.4 Tạo index và giám sát trên opensearch dashboard
Kiểm tra index của fluentd_win
Kiểm tra index của fluentd_linux
4. Tìm hiểu thêm
4.1 Fluentd UI
Thêm đường dẫn đến nới để lưu fluent.conf đã cấu hình. Sau đó start để áp dụng config đã được cấu hình trong fluent.conf
Logs từ khi chạy fluentd sẽ được thu thập và visualize trên dashboard
Thêm vao đó có thể cấu hình cho các config của fluentd thông qua config của fluentd UI
1.1 OpenSearch

- Khái niệm
- So sánh OpenSearch và Elasticsearch
Tiêu chí | OpenSearch | Elasticsearch |
---|---|---|
Giấy phép | Apache 2.0 (open-source thật sự) | Elastic License / SSPL (không còn OSI open-source) |
Bảo mật | RBAC, TLS, audit logs miễn phí, tích hợp sẵn | Có nhưng hầu hết nằm trong gói trả phí |
Tính năng chính | Search, visualization (Dashboards), alerting, anomaly detection, index management | Search, Kibana, Logstash, Beats, + nhiều module (APM, SIEM, ML, Fleet, Elastic Agent) |
Điểm mạnh | Miễn phí 100% Bảo mật tích hợp Tích hợp tốt với AWS Minh bạch, open-source cộng đồng | Hệ sinh thái lớn Nhiều tính năng nâng cao (APM, ML, SIEM) Hiệu năng cải tiến ở bản 8.x Tài liệu, plugin phong phú |
Điểm yếu | Bị dừng ở nhánh ES 7.10 Ít plugin, ecosystem nhỏ hơn Chủ yếu mạnh trên AWS | Không còn open-source Tính năng nâng cao phải trả phí Tốn tài nguyên, triển khai phức tạp Chi phí license cao |
Phù hợp | SME, lab học tập, nghiên cứu Doanh nghiệp nhỏ muốn tiết kiệm Môi trường AWS | Doanh nghiệp lớn, có ngân sách Cần APM, ML, SIEM nâng cao Tích hợp Elastic Cloud |
1.2 Fluentd
- Khái niệm
Bằng cách hợp nhất log từ mọi nguồn, Fluentd giúp chúng ta có cái nhìn tổng quan, chẳng hạn như xác định liệu lỗi từ ứng dụng có bắt nguồn từ cơ sở dữ liệu, hay vấn đề của hệ điều hành gây ra
- So sánh Fluentd và Logstash
Fluentd | Logstash | |
---|---|---|
Nhà phát triển chính và quản lý sản phẩm | Treasure Data được quản lý bởi CNCF | Elastic |
Hỗ trợ thương mại | Có | Có (lựa chọn mạnh hơn, hỗ trợ toàn bộ stack) |
Số lượng plugin | ~500 | ~200 |
Cách cấu hình | Khai báo—sử dụng các thẻ | Thủ tục—sử dụng cấu trúc if-then-else |
Hiệu suất | Tiêu thụ bộ nhớ thấp hơn so với Logstash | Tiêu thụ bộ nhớ cao hơn so với Fluentd |
Bộ nhớ đệm (Caching) | Tính tuỳ biến cao, hỗ trợ bộ nhớ đệm từ files và memory | Hàng đợi trong memory với kích thước cố định |
Ngôn ngữ/runtime machine | CRuby, không yêu cầu runtime để thực thi phần core của Fluentd | JRuby, phụ thuộc vào runtime của Java (JVM) |
- Kết luận
Chọn Logstash nếu bạn cần một giải pháp xử lý log toàn diện, có khả năng xử lý luồng dữ liệu phức tạp và ứng dụng các bộ lọc logic nâng cao. Đặc biệt, Logstash là lựa chọn tối ưu nếu hệ thống của bạn đã sử dụng hoặc có kế hoạch triển khai Elastic Stack, vì nó tích hợp hoàn hảo với các công cụ như Elasticsearch để tìm kiếm và phân tích log
1.3 Fluentbit
- Khái niệm
Đây là lý do Fluent Bit ra đời. Fluent Bit là một phiên bản rút gọn của Fluentd, với các tính năng đơn giản hơn, tập trung vào việc thu thập và gửi log đến hệ thống trung tâm để xử lý. Tại đó, Fluentd có thể thực hiện các công việc xử lý log phức tạp hơn, như lọc, chuyển đổi và làm giàu dữ liệu.
- So sánh Fluentd và Fluentbit
Fluentd | Fluentbit | |
---|---|---|
Ngôn ngữ phát triển | Viết bằng C & Ruby | Viết bằng C để tối ưu hóa kích thước triển khai |
Phụ thuộc | Phụ thuộc vào RubyGems | Không có phụ thuộc (trừ khi tùy chỉnh) |
Dung lượng bộ nhớ | Yêu cầu bộ nhớ ~20MB, tùy thuộc vào cấu hình và plugin | ~150KB |
Plugin sẵn có | Có thể sử dụng khoảng 300 plugin được tích hợp và từ bên thứ ba | Giới hạn ở các plugin tích hợp và 30 extension khác |
Hệ điều hành hỗ trợ | Cung cấp các bản cài đặt sẵn cho nhiều hệ điều hành, bao gồm hầu hết các phiên bản của Windows, OS X, và Linux | Một số biến thể Linux nhỏ gọn dựa trên CentOS, Debian (và các phiên bản như Raspbian), Ubuntu cho x86 và bộ xử lý AArch đã được phát triển. Các hệ điều hành khác như BSD-based Unixes có thể được hỗ trợ, nhưng không có đảm bảo về plugin |
2. Mô hình hệ thống
- Khái niệm All-in-One
- Mô hình xây dựng

Thành phần | Vai trò trong All-in-One |
---|---|
Fluentd | Agent nhận log từ các fluentbit trên các máy client → parse → gửi đến backend (OpenSearch). |
Fluentbit | Thu thập log từ các máy client (syslog, app, container, file) |
OpenSearch | Backend lưu trữ + tìm kiếm log. Hỗ trợ full-text search, query DSL, index management |
- Ưu điểm và nhược điểm của mô hình
Ưu điểm | Nhược điểm |
---|---|
Triển khai nhanh, đơn giản | Không scale tốt khi log lớn |
Chi phí thấp (open-source) | Dễ bị bottleneck (CPU, RAM, disk) |
Dùng tốt cho lab, SME | Không tách biệt được vai trò (collector / storage / dashboard) |
Dễ quản lý vì tập trung | Độ tin cậy thấp nếu server down → toàn hệ thống ngưng |
3. Cấu hình và cài đặt
3.1 Cài đặt server (Ubuntu24.04/10.30.194.101)
- Cài đặt Docker và Docker-compose
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
[SIZE=5]sudo apt-get update[/SIZE]
- Cấu hình file docker-compose.yml
opensearch-node1 / opensearch-node2[SIZE=5]version: "3.8"[/SIZE]
services:
# --- OpenSearch Node 1 ---
opensearch-node1:
image: opensearchproject/opensearch:3
container_name: opensearch-node1
environment:
- cluster.name=opensearch-cluster
- node.name=opensearch-node1
- discovery.seed_hosts=opensearch-node1,opensearch-node2
- cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2
- bootstrap.memory_lock=true
- OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=Thuan@123
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
volumes:
- opensearch-data1:/usr/share/opensearch/data
ports:
- "9200:9200"
- "9600:9600"
networks:
- opensearch-net
# --- OpenSearch Node 2 ---
opensearch-node2:
image: opensearchproject/opensearch:3
container_name: opensearch-node2
environment:
- cluster.name=opensearch-cluster
- node.name=opensearch-node2
- discovery.seed_hosts=opensearch-node1,opensearch-node2
- cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2
- bootstrap.memory_lock=true
- OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=Thuan@123
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
volumes:
- opensearch-data2:/usr/share/opensearch/data
networks:
- opensearch-net
# --- OpenSearch Dashboards ---
opensearch-dashboards:
image: opensearchproject/opensearch-dashboards:3
container_name: opensearch-dashboards
ports:
- "5601:5601"
environment:
OPENSEARCH_HOSTS: '["https://opensearch-node1:9200","https://opensearch-node2:9200"]'
networks:
- opensearch-net
# --- Nginx ---
nginx:
image: nginx:1.27.4-alpine
container_name: nginx
ports:
- "8080:80"
volumes:
- nginx-logs:/var/log/nginx
- ./default.conf:/etc/nginx/conf.d/default.conf
networks:
- opensearch-net
# --- Fluentd ---
fluentd:
image: fluent/fluentd:v1.17-debian
container_name: fluentd
user: root
command: >
sh -c "gem install fluent-plugin-opensearch &&
fluentd -c /fluentd/etc/fluent.conf"
volumes:
- nginx-logs:/var/log/fluentd
- ./fluent.conf:/fluentd/etc/fluent.conf
environment:
- FLUENTD_CONF=fluent.conf
ports:
- "24224:24224"
- "24225:24225"
networks:
- opensearch-net
# --- Fluentd UI ---
fluentd-ui:
image: balajibal/fluentd-ui:alpine3.6
container_name: fluentd-ui
environment:
- FLUENTD_HOST=fluentd
- FLUENTD_PORT=24224
command: fluentd-ui start
ports:
- "9292:9292" # chỉ web UI, không map 24224
volumes:
- ./fluentd-ui-data:/fluentd-ui
networks:
- opensearch-net
depends_on:
- fluentd
volumes:
opensearch-data1:
opensearch-data2:
nginx-logs:
fluentd-ui-data:
networks:
[SIZE=5] opensearch-net:[/SIZE]
- Vai trò: 2 nút tạo cluster OpenSearch để lưu trữ & tìm kiếm log (HA).
- Env chính: cluster.name, node.name, discovery.seed_hosts, cluster.initial_cluster_manager_nodes giúp các nút tìm thấy nhau và bầu cluster manager; OPENSEARCH_JAVA_OPTS giới hạn RAM JVM; bootstrap.memory_lock=true tránh swap.
- Bảo mật: OPENSEARCH_INITIAL_ADMIN_PASSWORD=Thuan@123 đặt mật khẩu admin lần đầu.
- Dữ liệu: volume opensearch-data1/2 gắn vào /usr/share/opensearch/data để persist.
- Cổng: 9200 (REST API), 9600 (Performance Analyzer).
- Vai trò: giao diện web để truy vấn/visualize dữ liệu trong OpenSearch.
- Kết nối: OPENSEARCH_HOSTS trỏ nội bộ tới https://opensearch-node1:9200 và ...node2.
- Cổng: 5601 (mở ra ngoài).
- Mẹo khi lỗi kết nối SSL/tự ký: thêm biến OPENSEARCH_SSL_VERIFICATION_MODE=none và (nếu cần) OPENSEARCH_USERNAME=admin, OPENSEARCH_PASSWORD=Thuan@123.
- Vai trò: web server phát sinh log (access/error) để pipeline của bạn có dữ liệu.
- Cấu hình: mount ./default.conf → /etc/nginx/conf.d/default.conf (bạn có thể chỉnh format log ở đây).
- Log: volume nginx-logs gắn vào /var/log/nginx để chia sẻ log với Fluentd.
- Cổng: 8080:80 (truy cập Nginx từ máy host ở 8080).
- Vai trò: thu thập log từ Nginx, parse/format rồi đẩy sang OpenSearch.
- Khởi chạy: cài plugin fluent-plugin-opensearch rồi chạy fluentd -c /fluentd/etc/fluent.conf.
- Cấu hình/Log in: mount ./fluent.conf vào /fluentd/etc/fluent.conf.
- Chia sẻ log: mount cùng volume nginx-logs nhưng tại đường dẫn /var/log/fluentd.
- Vì là cùng một volume, file access.log của Nginx sẽ thấy ở Fluentd dưới đường dẫn /var/log/fluentd/access.log. Hãy đảm bảo đường dẫn trong fluent.conf khớp như vậy.
- Cổng input: 24224, 24225 (để Fluentbit có thể gửi log trực tiếp vào Fluentd).
- Vai trò: Web UI quản lý Fluentd (tạo source, match, filter); không xử lý log runtime.
- Kết nối: FLUENTD_HOST=fluentd, FLUENTD_PORT=24224.
- Dữ liệu UI: ./fluentd-ui-data để lưu cấu hình UI/persistence.
- Cổng: 9292 (mở ra ngoài).
Host Linux# ==========================
# --- Host Linux ---
# ==========================
<source>
@type forward
@id in_forward_linux
port 24224
bind 0.0.0.0
tag linux
</source>
<match linux.**>
@type opensearch
@id out_os_linux
@log_level info
include_tag_key true
host opensearch-node1
port 9200
scheme https
ssl_verify false
ssl_version TLSv1_2
user admin
password Thuan@123
index_name fluentd_linux
logstash_format false
include_timestamp true
time_key_format %Y-%m-%dT%H:%M:%S.%N%z
time_key time
<buffer>
flush_thread_count 1
flush_mode interval
flush_interval 10s
chunk_limit_size 8M
total_limit_size 512M
retry_max_interval 30
retry_timeout 72h
retry_forever false
</buffer>
</match>
# ==========================
# --- Host Windows ---
# ==========================
<source>
@type forward
@id in_forward_win
port 24225
bind 0.0.0.0
tag win
</source>
<match win.**>
@type opensearch
@id out_os_win
@log_level info
include_tag_key true
host opensearch-node1
port 9200
scheme https
ssl_verify false
ssl_version TLSv1_2
user admin
password Thuan@123
index_name fluentd_win
logstash_format false
include_timestamp true
time_key_format %Y-%m-%dT%H:%M:%S.%N%z
time_key time
<buffer>
flush_thread_count 1
flush_mode interval
flush_interval 10s
chunk_limit_size 8M
total_limit_size 512M
retry_max_interval 30
retry_timeout 72h
retry_forever false
</buffer>
</match>
- Gửi log đến Fluentd qua cổng 24224.
- Fluentd gắn tag linux.
- Log được lưu trong OpenSearch tại index fluentd_linux
- Gửi log đến Fluentd qua cổng 24225.
- Fluentd gắn tag win.
- Log được lưu trong OpenSearch tại index fluentd_win
- Tạo file default.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
- Khởi chạy docker compose

Truy cập opensearch dashboard thông qua http://10.30.194.101:5601
Username: admin
Password: Thuan@123

3.2 Cài đặt host linux
Dùng lệnh do fluentbit để cài đặt nhanh chóng trên linux:
curl https://raw.githubusercontent.com/fluent/fluent-bit/master/install.sh | sh
Dùng lệnh:
systemctl enable fluentbit
để fluentbit tự động gửi log về khi máy client được khởi độngKhởi động fluentbit :
systemctl start fluent-bit
Kiểm tra trạng thái hoạt động của fluentbit :

Truy cập vào /etc/fluent-bit/fluent-bit.conf để cấu hình
[SIZE=5][SERVICE][/SIZE]
# Flush
# =====
# set an interval of seconds before to flush records to a destination
flush 1
# Daemon
# ======
# instruct Fluent Bit to run in foreground or background mode.
daemon Off
# Log_Level
# =========
# Set the verbosity level of the service, values can be:
#
# - error
# - warning
# - info
# - debug
# - trace
#
# by default 'info' is set, that means it includes 'error' and 'warning'.
log_level info
# Parsers File
# ============
# specify an optional 'Parsers' configuration file
parsers_file parsers.conf
# Plugins File
# ============
# specify an optional 'Plugins' configuration file to load external plugins.
plugins_file plugins.conf
# HTTP Server
# ===========
# Enable/Disable the built-in HTTP Server for metrics
http_server on
http_listen 0.0.0.0
http_port 2020
# Storage
# =======
# Fluent Bit can use memory and filesystem buffering based mechanisms
#
# - https://docs.fluentbit.io/manual/administration/buffering-and-storage
#
# storage metrics
# ---------------
# publish storage pipeline metrics in '/api/v1/storage'. The metrics are
# exported only if the 'http_server' option is enabled.
#
storage.metrics on
# storage.path
# ------------
# absolute file system path to store filesystem data buffers (chunks).
#
# storage.path /tmp/storage
# storage.sync
# ------------
# configure the synchronization mode used to store the data into the
# filesystem. It can take the values normal or full.
#
# storage.sync normal
# storage.checksum
# ----------------
# enable the data integrity check when writing and reading data from the
# filesystem. The storage layer uses the CRC32 algorithm.
#
# storage.checksum off
# storage.backlog.mem_limit
# -------------------------
# if storage.path is set, Fluent Bit will look for data chunks that were
# not delivered and are still in the storage layer, these are called
# backlog data. This option configure a hint of maximum value of memory
# to use when processing these records.
#
# storage.backlog.mem_limit 5M
[INPUT]
name CPU
tag linux.cpu
interval_sec 10
[INPUT]
name mem
Tag linux.mem
interval_sec 10
[INPUT]
name disk
tag linux.disk
interval_sec 10
[INPUT]
name netif
tag linux.net
interface ens33
# Read interval (sec) Default: 1
interval_sec 10
[OUTPUT]
name forward
match linux.*
host 10.30.194.101
[SIZE=5] port 24224[/SIZE]
Các section cấu hình
Tên Section | Mô tả | ||
---|---|---|---|
service | Mô tả cấu hình toàn cục cho dịch vụ Fluent Bit. Tùy chọn. Nếu không thiết lập, các giá trị mặc định sẽ được áp dụng. Chỉ có thể định nghĩa một section service. | ||
parsers |
| ||
multiline_parsers | Liệt kê các parser nhiều dòng, hoạt động tương tự như parsers. Có thể định nghĩa nhiều section, nằm ở root hoặc trong các file include. | ||
pipeline | Định nghĩa một pipeline bao gồm các input, processor, filter và plugin output. Bạn có thể định nghĩa nhiều section pipeline, nhưng chúng không hoạt động độc lập. Thay vào đó, tất cả các thành phần sẽ được gộp lại thành một pipeline duy nhất bên trong Fluent Bit | ||
plugins | Chỉ định đường dẫn đến các plugin bên ngoài (file .so) sẽ được Fluent Bit nạp khi chạy | ||
upstream_servers | Tham chiếu đến một nhóm endpoint của node có thể được các plugin output hỗ trợ sử dụng | ||
env | Thiết lập danh sách các biến môi trường cho Fluent Bit. Các biến môi trường của hệ thống có sẵn, trong khi các biến được định nghĩa trong cấu hình chỉ áp dụng cho Fluent Bit |
3.3 Cài đặt host Windows
- Cài đặt fluent-bit
Sau khi tải về chạy file exe để cài đặt

- Cấu hình fluent-bit
[SIZE=5][SERVICE][/SIZE]
Flush 5
Daemon Off
Log_Level info
# Hostname có thể tự nhận; muốn set tay thì mở dòng dưới:
# Hostname MY-WINDOWS
# --- (A) Thông tin cấu hình host tĩnh/quasi-tĩnh: chạy mỗi 5s qua PowerShell script ---
[INPUT]
Name exec
Tag win.hostconf
Command powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Program Files\fluent-bit\scripts\hostinfo.ps1"
Interval_Sec 5
# Script in ra đúng JSON 1 dòng, nên không cần Parser
# --- (B) Thống kê hệ thống realtime mỗi 5s (CPU, RAM, Disk, Net) ---
[INPUT]
Name winstat
Tag win.stat
Interval_Sec 5
# (Tuỳ chọn) Gộp thêm nhãn chung
[FILTER]
Name record_modifier
Match win.*
Record agent fluent-bit
Record platform windows
# Gửi về Fluentd (container) nghe ở cổng 24225
[OUTPUT]
Name forward
Match win.*
Host 10.30.194.101
Port 24225
[SIZE=5] tls Off[/SIZE]
- Tiến hành cài đặt fluent-bit dưới dạng services trên windows
[SIZE=4]sc.exe create fluent-bit binpath= "C:\Program Files\fluent-bit\bin\fluent-bit.exe -c C:\Program Files\fluent-bit\conf\fluent-bit.conf"[/SIZE]
Khởi động service fluent-bit sc.exe start fluent-bit

Cài đặt cho fluent-bit khởi động tự động khi máy windows được bật
[SIZE=4]sc.exe config fluent-bit start= auto[/SIZE]
3.4 Tạo index và giám sát trên opensearch dashboard

Kiểm tra index của fluentd_win

Kiểm tra index của fluentd_linux

4. Tìm hiểu thêm
4.1 Fluentd UI
- Khái niệm
- Cài đặt, gỡ bỏ và nâng cấp các plugin của Fluentd
- Khởi động/dừng/khởi động lại tiến trình Fluentd
- Cấu hình các thiết lập của Fluentd như file cấu hình, đường dẫn file PID, v.v.
- Xem log của Fluentd với trình xem lỗi đơn giản
- Cách hoạt động

Thêm đường dẫn đến nới để lưu fluent.conf đã cấu hình. Sau đó start để áp dụng config đã được cấu hình trong fluent.conf

Thêm vao đó có thể cấu hình cho các config của fluentd thông qua config của fluentd UI

Bài viết liên quan
Được quan tâm
Bài viết mới