
我想使用 syslog-ng 將每個應用程式的日誌傳送到遠端收集器。
如果我有 Apache,我希望將 Apache 日誌傳送到文件中的遠端收集器/var/log/apache.log
。
我找不到任何關於此的資訊。我知道 rsyslog 是可能的,但我在這裡唯一能做的就是將所有日誌與以下內容一起發送:
destination remote { network("<collector_adress>" transport("udp") port(514)); };
答案1
若要使用 syslog-ng 從檔案收集日誌,您必須建立檔案來源,並將它們新增至日誌語句中。像這樣的東西:
source s_apache {
file("/var/log/apache.log");
};
log {
source(s_apache); destination(remote);
};
若要從其他檔案收集日誌,請定義其他來源並將它們新增至日誌語句。如果您的應用程式登入多個不同的日誌檔案(例如,登入帶有時間戳記的日誌檔案),則可以使用通配符檔案來源。檢查文件了解詳細資訊:https://www.syslog-ng.com/technical-documents/doc/syslog-ng-open-source-edition/3.21/administration-guide/16#TOPIC-1180423
答案2
我認為你可以使用與中相同的方法Syslog-ng - 從客戶端發送檔案名稱到伺服器。
syslog-ng 中的客戶端配置 -
file("/var/log/shell.log" log_prefix("shell: "));
syslog-ng 中的伺服器端配置 -
filter f_shell { match("shell" value("MSGHDR")); };
destination d_shell { file("/var/log/syslog-ng/shell.log"); };
log { source(demo_tls_src); filter(f_shell); destination(d_shell); flags(final); };