前言
工作中遇到了系統所在分區被撐爆的情況,經排查,系統日志占了絕大部分,現在對系統日志做一下總結,並列出一些常用處理手段
1.
systemd 提供了自己的日志系統(logging system),稱為 journal。使用 systemd 日志,無需額外安裝日志服務(syslog)。讀取日志的命令:
root@ubuntu: journalctl
不過,一般大家更關心的不是本次啟動后的日志,而是上次啟動時的(例如,剛剛系統崩潰了)。可以使用 -b 參數:
journalctl -b -0 顯示本次啟動的信息
journalctl -b -1 顯示上次啟動的信息
journalctl -b -2 顯示上上次啟動的信息 journalctl -b -2
只顯示錯誤、沖突和重要告警信息
# journalctl -p err..alert
也可以使用數字, journalctl -p 3..1。If single number/keyword used, journalctl -p 3 - all higher priority levels also included.
顯示從某個日期 ( 或時間 ) 開始的消息:
# journalctl --since="2012-10-30 18:17:16"
顯示從某個時間 ( 例如 20分鍾前 ) 的消息:
# journalctl --since "20 min ago"
顯示最新信息
# journalctl -f
顯示特定程序的所有消息:
# journalctl /usr/lib/systemd/systemd
顯示特定進程的所有消息:
# journalctl _PID=1
顯示指定單元的所有消息:
# journalctl -u man-db.service
顯示內核環緩存消息r:
# journalctl -k
Show auth.log equivalent by filtering on syslog facility:
# journalctl -f -l SYSLOG_FACILITY=10
If your journal directory (by default located under /var/log/journal) contains huge amount of log data then journalctl can take several minutes in filtering output. You can speed it up significantly by using --file option to force journalctl to look only into most recent journal:
# journalctl --file /var/log/journal/*/system.journal -f