initial: db_log_exporter v1.0

This commit is contained in:
QClaw Bot
2026-05-12 19:02:46 +08:00
commit 7cd8f78404
6 changed files with 1364 additions and 0 deletions

41
db_log_exporter.service Normal file
View File

@@ -0,0 +1,41 @@
[Unit]
Description=Database Log Exporter — 从 MySQL/PostgreSQL 拉取日志写入文本文件
Documentation=https://github.com/example/db_log_exporter
After=network.target mysql.service postgresql.service
Wants=mysql.service postgresql.service
[Service]
# 以专门的用户/组运行推荐先创建示例useradd -r -s /sbin/nologin db_exporter
User=root
Group=root
# 程序路径
ExecStart=/usr/bin/python3 /opt/db_log_exporter/db_log_exporter.py \
--config /etc/db_log_exporter/config.yaml \
--log-file /var/log/db_exporter/exporter.log \
--log-level INFO
# 重启策略
Restart=on-failure
RestartSec=10
StartLimitBurst=5
# 安全加固
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=/var/log/db_exporter /var/lib/db_exporter
# 环境变量(可选,敏感信息可用 systemd secret 或环境文件)
# EnvironmentFile=/etc/db_log_exporter/env
# 日志输出systemd journal
StandardOutput=journal
StandardError=journal
SyslogIdentifier=db_log_exporter
# 优雅停止超时
TimeoutStopSec=30
[Install]
WantedBy=multi-user.target