📊 Linux Log 監控自動化:整合 GoAccess、Systemd 與 Fail2Ban 報表分析
在 Linux 系統維運中,Log 分析往往決定了問題排查效率。 本篇教你如何結合 GoAccess、Systemd 與 Fail2Ban,打造一套自動化安全監控報表, 即時觀察連線行為、封鎖惡意 IP 並生成可視化儀表板。
一、環境與安裝
# 安裝 GoAccess
sudo apt install goaccess -y
# 安裝 Fail2Ban
sudo apt install fail2ban -y
二、整合 systemd-journal 與 GoAccess
使用 journalctl 匯出日誌並讓 GoAccess 即時分析:
journalctl -u nginx.service -f | goaccess -o /var/www/html/report.html --log-format=COMBINED
三、結合 Fail2Ban 與自動化封鎖
建立自動封鎖與通知機制:
[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 5
四、自動化報表排程
透過 systemd timer 定期輸出 GoAccess 報表:
# /etc/systemd/system/goaccess-report.service
[Service]
Type=oneshot
ExecStart=/usr/bin/goaccess /var/log/nginx/access.log -o /var/www/html/report.html --log-format=COMBINED
# /etc/systemd/system/goaccess-report.timer
[Timer]
OnCalendar=hourly
Persistent=true
WantedBy=timers.target
📘 結語
結合 GoAccess、systemd 與 Fail2Ban,不僅能自動化安全監控, 更能將系統維運轉為數據化與可視化管理, 是中小企業與實驗室環境中最具成本效益的方案之一。
🔗 延伸閱讀
— WWFandy・系統與網路筆記
沒有留言: