Syslog 確實主要用來傳送日誌,但它不只是單純地傳送資訊而已。它的核心功能包括:
RFC 5424 中定義的 Facility 和 Severity 分類看起來很複雜,但在實際應用上非常有用:
快速篩選和分類
自動化處理
資源分配
故障排除
法規遵循和稽核
日誌路由
優先順序處理
儲存管理
假設你正在管理一個大型網路:
當收到一個 PRI 值為 34 的日誌時:
設定日誌管理系統:
透過這種方式,看似複雜的分類系統實際上為日誌管理和系統監控提供了極大的彈性和效率。
PRI = Facility * 8 + Severity
PRI(Priority)值在 Syslog 訊息中扮演著關鍵角色:
訊息分類和優先級:
高效過濾:
資源分配:
自動化處理:
向後兼容:
日誌聚合和分析:
合規性和審計:
實際應用例子:
理解和有效利用 PRI 值可以大大提高日誌管理的效率和效果,尤其是在處理大量日誌資料的環境中。
給定 PRI 值,求 Facility 和 Severity:
給定 Facility 和 Severity,求 PRI:
如果 PRI = 165:
因此:
Value | Facility | 中文翻譯 | Value | Facility | 中文翻譯 | |
---|---|---|---|---|---|---|
0 | kernel messages | 核心訊息 | 8 | UUCP subsystem | UUCP 子系統 | |
1 | user-level messages | 使用者層級訊息 | 9 | clock daemon | 時鐘守護程序 | |
2 | mail system | 郵件系統 | 10 | security/authorization messages | 安全/授權訊息 | |
3 | system daemons | 系統守護程序 | 11 | FTP daemon | FTP 守護程序 | |
4 | security/authorization messages | 安全/授權訊息 | 12 | NTP subsystem | NTP 子系統 | |
5 | messages generated internally by syslogd | syslogd 內部產生的訊息 | 13 | log audit | 日誌稽核 | |
6 | line printer subsystem | 列印機子系統 | 14 | log alert | 日誌警報 | |
7 | network news subsystem | 網路新聞子系統 | 15 | clock daemon (note 2) | 時鐘守護程序(註 2) | |
16-23 | local use 0-7 (local0-local7) | 本地使用 0-7 |
Value | Severity | 中文翻譯 |
---|---|---|
0 | Emergency: system is unusable | 緊急:系統無法使用 |
1 | Alert: action must be taken immediately | 警報:必須立即採取行動 |
2 | Critical: critical conditions | 嚴重:嚴重的狀況 |
3 | Error: error conditions | 錯誤:錯誤狀況 |
4 | Warning: warning conditions | 警告:警告狀況 |
5 | Notice: normal but significant condition | 注意:正常但重要的狀況 |
6 | Informational: informational messages | 資訊:資訊性訊息 |
7 | Debug: debug-level messages | 除錯:除錯層級訊息 |
以下是一些模擬的核心路由器高嚴重性 Syslog 訊息例子。這些訊息的格式為:
<PRI>時間戳記 主機名稱 進程[PID]: 訊息內容
其中,PRI 值計算方式為:PRI = Facility * 8 + Severity
<0>Jun 15 14:23:15 core-router-01 kernel: EMERGENCY: Hardware failure detected on primary interface eth0. System is halting.
<1>Jun 15 15:45:22 core-router-01 kernel: ALERT: CPU temperature critically high (95°C). Immediate action required to prevent shutdown.
<2>Jun 15 16:10:03 core-router-01 kernel: CRITICAL: Multiple BGP sessions down. Potential network partition detected.
這些類型的日誌訊息通常會觸發即時通知,因為它們代表了需要立即關注和處理的嚴重問題。網路管理員可能會設置系統,當接收到這樣的訊息時立即發送簡訊、電子郵件或觸發其他警報機制。
以下是一些來自不同 Facility 的高嚴重性 Syslog 訊息例子。格式為:
<PRI>時間戳記 主機名稱 進程[PID]: 訊息內容
<9>Jun 16 10:15:30 fileserver-01 sshd[1234]: ALERT: Multiple failed root login attempts from IP 192.168.1.100
<18>Jun 16 11:30:45 mailserver-01 postfix/smtpd[5678]: CRITICAL: Mail queue full, new messages rejected
<24>Jun 16 13:45:22 webserver-01 httpd[9012]: Emergency: Out of worker threads, server not responding to requests
<33>Jun 16 15:20:10 firewall-01 iptables: ALERT: Possible DDoS attack detected, dropping all incoming traffic on port 80
<58>Jun 16 17:05:55 router-01 bgpd[3456]: CRITICAL: BGP peer 10.0.0.1 down, multiple routes unreachable
這些類型的日誌訊息通常會觸發即時通知和應對措施。IT 團隊可能會根據不同的 Facility 和 Severity 組合設置不同的警報級別和處理流程。