Lightweight
Kịch bản 3 Single receiver → Multiple exporters
Hướng dẫn cấu hình một nguồn log gửi tới nhiều destinations
Tổng quan
Kịch bản này được áp dụng khi hệ thống chỉ cần thu thập dữ liệu từ một nguồn log duy nhất trên máy chủ (ví dụ: Syslog hoặc Log ứng dụng), nhưng yêu cầu phải phân phối và đồng bộ luồng log đó tới nhiều điểm nhận (Destinations) khác nhau cùng một lúc.
Cấu hình chi tiết
1. Receivers (Bộ nhận) - Một nguồn
receivers:
filelog: # Receiver duy nhất
include:
- /var/log/syslog # Hoặc log khác theo nhu cầu
- /home/bacnt/logs/*.log
start_at: end
include_file_path: false
include_file_name: false
2. Processors (Bộ xử lý)
3. Exporters (Bộ gửi) - Nhiều điểm đến
Definition nhiều exporter với tên khác nhau và endpoint khác nhau.
exporters:
otlphttp/primary: # Exporter 1: Platform chính
endpoint: ${PRIMARY_ENDPOINT}
logs_endpoint: ${PRIMARY_ENDPOINT}
headers:
x-api-key: ${PRIMARY_API_KEY}
Content-Type: "application/json"
timeout: 30s
encoding: json
otlphttp/backup: # Exporter 2: Platform backup
endpoint: ${BACKUP_ENDPOINT}
logs_endpoint: ${BACKUP_ENDPOINT}
headers:
x-api-key: ${BACKUP_API_KEY}
Content-Type: "application/json"
timeout: 30s
encoding: json
syslog: # Exporter 3: Syslog server
endpoint: syslog-server.company.com:514
protocol: rfc5424
format: json
Quy tắc đặt tên Exporter:
- Format:
<loại>/<tên_logic>(ví dụ:otlphttp/primary,otlphttp/backup) - Mỗi exporter phải có tên duy nhất
- Sử dụng tên có ý nghĩa: primary/backup, main/archive, v.v.
4. Service Pipeline (Đường ống xử lý)
service:
pipelines:
logs:
receivers: [filelog] # Một receiver
exporters: [otlphttp/primary, otlphttp/backup] # Nhiều exporter
Lưu ý: Tất cả exporter sẽ nhận đồng thời log từ receiver.
Ví dụ thực tế
Ví dụ: Gửi Security log tới Platform chính + Backup + Archive
receivers:
filelog:
include:
- /var/log/auth.log
start_at: end
include_file_path: true
include_file_name: false
exporters:
otlphttp/primary:
endpoint: https://secops-main.company.com:4317
logs_endpoint: https://secops-main.company.com:4317
headers:
x-api-key: sk_live_primary_key
Content-Type: "application/json"
timeout: 30s
encoding: json
otlphttp/backup:
endpoint: https://secops-backup.company.com:4317
logs_endpoint: https://secops-backup.company.com:4317
headers:
x-api-key: sk_live_backup_key
Content-Type: "application/json"
timeout: 30s
encoding: json
file/archive:
path: /var/log/archive/auth-%Y%m%d.log
service:
pipelines:
logs:
receivers: [filelog]
exporters: [otlphttp/primary, otlphttp/backup, file/archive]
Lưu ý
- Độc lập của Exporter: Nếu một exporter gặp lỗi, nó sẽ retry; các exporter khác vẫn gửi bình thường.
- Độ trễ (Latency): Nếu một exporter chậm, nó có thể ảnh hưởng tới tất cả exporter khác; cân nhắc dùng buffering.
- Redundancy: Setup này giúp đảm bảo không mất log khi một destination down.
- Dung lượng: Gửi tới nhiều destination = gấp đôi hoặc gấp ba dung lượng mạng; cần tính toán kỹ.