Lê Gia Hoàng Thiện
Intern
1. Giới thiệu công cụ
1.1. Fluent Bit
- Là agent nhẹ cài đặt trực tiếp trên máy chủ (Linux, Windows).
- Chức năng: thu thập log hệ thống, ứng dụng, container.
- Ưu điểm: hiệu năng cao, sử dụng ít tài nguyên, phù hợp để chạy ở nhiều endpoint.
1.2. Fluentd
- Là log aggregator (bộ gom và xử lý log).
- Chức năng: filter, buffer, routing log đến nơi lưu trữ.
- Đóng vai trò pipeline trung tâm, nhận log từ nhiều Fluent Bit, chuẩn hóa và chuyển tiếp sang OpenSearch.
1.3. OpenSearch
- Là nền tảng lưu trữ và phân tích log.
- Chức năng:
- Lưu trữ dữ liệu dạng index.
- Cung cấp công cụ tìm kiếm nhanh (search engine).
- Trực quan hóa dữ liệu bằng dashboard.
- Thiết lập cảnh báo bảo mật (alert).
2. Mô hình hệ thống

Sơ đồ thể hiện rõ 3 lớp:
- Lớp thu thập (Collecting log):
- Fluent Bit chạy trên Linux và Windows để lấy log từ hệ điều hành, ứng dụng.
- Log raw được đóng gói và gửi đi.
- Lớp xử lý (Routing log):
- Fluentd nhận log từ nhiều Fluent Bit.
- Thực hiện filter (lọc), buffer (lưu tạm), routing (chuyển tiếp).
- Đảm bảo dữ liệu log được chuẩn hóa trước khi gửi đi.
- Lớp phân tích (Search, Analytics, Visualization, Alert):
- OpenSearch lưu trữ log.
- Người quản trị có thể tìm kiếm, phân tích sự kiện.
- Dashboard giúp trực quan hóa log.
- Có thể thiết lập rule để cảnh báo bảo mật.
3. Chức năng chính
- Thu thập log từ nhiều nguồn: Linux, Windows, ứng dụng, container.- Xử lý & chuẩn hóa log: Fluentd hỗ trợ plugin để định dạng dữ liệu.
- Lưu trữ & tìm kiếm: OpenSearch cho phép query nhanh, hiệu quả.
- Phân tích bảo mật: phát hiện sự kiện bất thường qua alert.
- Trực quan hóa dữ liệu: dashboard hiển thị log theo thời gian thực.
4. Điểm mạnh – Điểm yếu
4.1. Điểm mạnh
- Fluent Bit nhẹ, dễ cài trên nhiều server.
- Fluentd linh hoạt, hỗ trợ nhiều plugin filter/output.
- OpenSearch mã nguồn mở, chi phí thấp.
- Hỗ trợ phân tích bảo mật cơ bản.
4.2. Điểm yếu
- Fluentd và OpenSearch tốn tài nguyên khi log lớn.
- Cần cấu hình TLS/SSL để bảo mật đường truyền.
- Thiếu tính năng SIEM nâng cao so với Splunk/Elastic SIEM.
5. Cấu hình căn bản với 1 Server thu thập log và 2 host Linux và Windown
5.1. Cấu hình server (10.30.192.3)
- Cài đặt docker và docker-compse
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) \
signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker $USER
newgrp docker
- Tạo file docker-compose.yml
version: '3'
services:
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=Password # Đảm bảo mật khẩu đã được thiết lập
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
volumes:
- opensearch-data1:/usr/share/opensearch/data
networks:
- opensearch-net
ports:
- "9200:9200"
- "9600:9600"
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=Password
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
volumes:
- opensearch-data2:/usr/share/opensearch/data
networks:
- opensearch-net
opensearch-dashboards:
image: opensearchproject/opensearch-dashboards:3
container_name: opensearch-dashboards
ports:
- "5601:5601"
expose:
- '5601'
environment:
OPENSEARCH_HOSTS: '["https://opensearch-node1:9200","https://opensearch-node2:9200"]'
networks:
- opensearch-net
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:
image: fluentd:latest
container_name: fluentd
volumes:
- nginx-logs:/var/log/fluentd
- ./fluent.conf:/fluentd/etc/fluent.conf
environment:
- FLUENTD_CONF=fluent.conf
ports:
- "24224:24224"
- "24225:24225"
expose:
- '24224'
- '24225'
networks:
- opensearch-net
user: root
command: [ "sh", "-c", "gem install fluent-plugin-opensearch && fluentd -c /fluentd/etc/fluent.conf" ]
volumes:
opensearch-data1:
opensearch-data2:
nginx-logs:
networks:
opensearch-net:
- Tạo file fluent.conf và default.conf cùng thư mục
# --- 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 Password
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 Win ---
<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 Password
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>
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;
}
}
- Chạy di chuyển đến thư mục chứa 3 file đó chạy docker-compose up -d và truy cập vào ip:5601 vd: http://10.30.192.3:5601 để truy cập vào dashboard
Username: admin
Password : password


5.2. Cài đặt host Linux
- Cài đặt fluent bit và chạy dưới nền dịch vụ cho chúng
/usr/bin/sudo apt update
/usr/bin/sudo apt install -y curl gnupg lsb-release
cd /tmp
curl -LO https://packages.fluentbit.io/fluent-bit/v4.0/fluent-bit-4.0.7-linux-x86_64.tar.gz
sudo mkdir -p /opt/fluent-bit
sudo tar -xzf fluent-bit-4.0.7-linux-x86_64.tar.gz -C /opt/fluent-bit --strip-components=1
cat <<'EOF' | sudo tee /usr/lib/systemd/system/fluent-bit.service
[Unit]
Description=Fluent Bit
Documentation=https://docs.fluentbit.io/manual/
After=network.target
[Service]
Type=simple
ExecStart=/opt/fluent-bit/bin/fluent-bit -c /etc/fluent-bit/fluent-bit.conf
Restart=always
RestartSec=2
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
- Chỉnh sửa file config tại /etc/fluent-bit/fluent-bit.conf để thu thập và gửi log đến fluentd
[SERVICE]
# 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 Off
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
# CPU
[INPUT]
Name cpu
Tag linux.cpu
Interval_Sec 10
# Memory
[INPUT]
Name mem
Tag linux.mem
Interval_Sec 10
# Disk I/O per device (không có tham số Path)
[INPUT]
Name disk
Tag linux.disk
Interval_Sec 10
# Dev_Exclude loop*,ram*
# Network interface (đúng plugin là netif)
[INPUT]
Name netif
Tag linux.net
Interface ens33
Interval_Sec 10
# Gửi sang Fluentd (10.30.192.3:24224)
[OUTPUT]
Name forward
Match linux.*
Host 10.30.192.3
Port 24224
- Khởi động và kiểm tra logs trạng thái service
sudo systemctl enable fluent-bit
sudo systemctl start fluent-bit
sudo systemctl status fluent-bit
journalctl -u fluent-bit -f
5.3. Cài đặt host Windown
- Cài đặt fluentbit qua đường dẫn :
- Thay đổi file fluent-bit.conf ở đường dẫn C:\Program Files\fluent-bit\conf (nếu cài đặt mặt định )
[SERVICE]
# 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 Off
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 winevtlog
Tag win.host
Channels Application,System,Security,Setup,Windows PowerShell
Interval_Sec 1
Read_Existing_Events On
[OUTPUT]
Name forward
Match win.*
Host 10.30.192.3
Port 24225
- Di chuyển qua đường dẫn C:\Program Files\fluent-bit\bin chạy lệnh .\fluent-bit.exe -c ..\conf\fluent-bit.conf (có thể triển khai dạng dịch vụ )

5.4. Tạo index và check kết quả đạt được



Đính kèm
Bài viết liên quan
Bài viết mới