Skip to content

Journalctl

systemd 로그를 확인할 수 있다.

Categories

logrotate with systemd

Increasing Storage

If you are storing to disk you can increase the amount of space used by changing SystemMaxUse and/or SystemKeepFree. Having more space would allow more entries to be stored.

By default the maximum use limit (SystemMaxUse) is 10% of the filesystem, and the minimum free space (SystemKeepFree) value is 15% - though they are both capped at 4G.

Journal Rotation

The journals should be rotated automatically when they reach the SystemMaxFileSize value, and the number of journals is controlled by SystemMaxFiles. If you prefer time based rotation you can set a MaxFileSec to set the maximum time entries are stored in a single journal.

Note on Storage Location/Type

With journald you can choose to store the journal entries either in memory (Storage=volatile) or on disk (Storage=persistent). The above assumes you are storing journals on disk - if this is not the case "System" will need to be replaced by "Runtime" in the above variables.

Further details are available in man journald.conf.

Alternative - Passing on the journal entries

If you are already familiar with the traditional SYSLOG daemon you can pass the journal events on by setting the ForwardToSyslog option (which forwards the messages immediately) or have the syslog daemon behave like a journal client and fetch the logs itself.

LogNamespace

이름 공간을 ssh라고 한다면, systemd의 [Service] 섹션에 LogNamespace=ssh 와 같이 추가하고 /etc/systemd/[email protected] 파일을 만든다.

서비스를 다시 시작하면 journalctl --namespace ssh 명령으로 로그를 볼 수 있다.

수동으로 저널 파일 정리

저널 파일은 /var/log/journal 폴더 안에 저장되므로 가서 직접 제거하거나

다양한 기준에 따라 다듬을 수 있습니다:

로그를 유지하는 크기가 100M 아래로 떨어질 때까지 아카이브된 저널 파일을 제거합니다.

journalctl --vacuum-size=100M

모든 저널 파일에 2주보다 오래된 데이터가 포함되지 않도록 합니다.

journalctl --vacuum-time=2weeks

Clear journal Logs

사용량 확인:

journalctl --disk-usage
sudo journalctl --rotate
sudo journalctl --vacuum-time=1s
sudo journalctl --rotate --vacuum-size=500M

Example

journalctl -xe
추가적인 메시지(에러 혹은 이벤트)와 함께 로그의 가장 끝 부분을 확인
  • -x, --catalog - 옵션은 로그 항목에 대한 추가 정보를 제공합니다. 예를 들어, 오류가 발생했을 때 가능한 원인이나 해결 방법에 대한 힌트를 포함할 수 있습니다.
  • -e, --pager-end - 옵션은 로그 파일의 끝에서부터 출력을 시작하여 최신 로그를 가장 먼저 보여줍니다. 이는 최근의 로그를 빠르게 확인할 수 있어 문제 발생 시 유용합니다.
journalctl -u [systemd unit name]
특정 유닛의 로그를 확인
journalctl -f
로그를 계속 확인하며 트래킹
journalctl -f -u [systemd unit name]
특정 유닛의 로그를 계속 확인하며 트래킹
journalctl -b
마지막 부팅 후 로그 보기
journalctl --since=today
오늘 날짜 로그 보기
journalctl --since "2017-05-25 00:00:00" --until "2017-05-30 10:30:00"
특정 기간별 로그 보기 (2017년 5월 25일 0시부터 2017년 5월 30일 오전 10시 30분까지의 Log 출력)
journalctl -u sshd
특정 서비스 데몬 로그 보기
journalctl -p crit
특정 이벤트 속성 조회 (critical 속성을 가진 이벤트만 출력)
journalctl -u libvirtd --since=yesterday -p err
특정 서비스데몬 및 속성과 날짜 로그 보기 (어제부터의 libvirtd 데몬의 Log 중 error만 출력)
journalctl -p err -o verbose
Error log에 대해 자세하게 출력
journalctl /sbin/crond
특정 이벤트 조회

See also

Favorite site