本篇說明如何在 Alpine 系統上配置日誌轉發至遠端 Log Server,範例中使用的 Log Server 為 10.20.2.30。
apk add rsyslog rc-service syslog stop rc-update del syslog boot
cp /etc/rsyslog.conf /etc/rsyslog.conf.bk
vim /etc/rsyslog.conf
: module(load="imuxsock") # 本地日誌 module(load="imklog" permitnonkernelfacility="on") # 核心日誌 :
mkdir -p /etc/rsyslog.d vim /etc/rsyslog.d/99-logserver.conf
# 轉發訊息至 Log Server (10.20.2.30:514) # 規則 1:轉發所有 info 級別以上的日誌(排除 mail、authpriv 和 cron) if ($syslogseverity <= 6 and $syslogfacility-text != 'mail' and $syslogfacility-text != 'authpriv' and $syslogfacility-text != 'cron') then { action(type="omfile" File="/var/log/syslog") action(type="omfwd" Target="10.20.2.30" Port="514" Protocol="udp") } # 規則 2:轉發 SSH 相關日誌(auth 和 authpriv) if ($syslogfacility-text == "auth" or $syslogfacility-text == "authpriv") then { action(type="omfile" File="/var/log/auth.log") action(type="omfwd" Target="10.20.2.30" Port="514" Protocol="udp") }
rc-service rsyslog start && rc-update add rsyslog
logger "Test message to log server"
rc-service rsyslog status