Linux

[journalctl] service 로그 확인

비번변경 2022. 9. 12. 16:43

journalctl

Linux 서비스 매니저인 systemd는 로그 데이터를 journal이라는 바이너리 형식으로 저장한다.

journalctl은 journal에서 로그를 검색하고 조회할 수 있는 systemd 유틸리티 중 하나이다.

보통 systemctl status와 함께 사용한다.

systemctl status - journal

표시한 부분이 바로 로그 데이터에 해당한다.

systemctl status - journal

journalctl로 동일한 내용을 확인할 수 있다.

 

 

사용법

옵션 없이 실행하면 systemd의 로그를 확인할 수 있다.

journalctl

journalctl

 

최근 n개 메시지 확인

journalctl -n <num>

# 예시
journalctl -n		# 최근 10게
journalctl -n 20	# 최근 20개

 

message catalog로부터의 상세 설명 추가 확인

journalctl -x

journalctl -x

 

최신 에러 메시지부터 확인

옵션 없이 사용하면 journal의 처음부터 출력되는데 -e 옵션을 사용하면 -n 1000과 같이 동작한다.

journalctl -e

 

변경 사항 실시간 표시

-f 옵션을 사용하면 tail -f 와 동일하게 동작한다.

journalctl -f

 

특정 unit에 대한 로그 확인

journalctl -u <UNIT>

# 예시
journalctl -u ssh
journalctl -u kubelet
journalctl -u docker

 

보통 journalctl로 로그를 확인할 때는 아래와 같은 옵션을 세트로 주어 사용한다.

journalctl -xefu <UNIT>

 

 

journal 데몬 설정 파일

journald의 설정 파일 경로는 아래와 같다.

cat /etc/systemd/journald.conf

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See journald.conf(5) for details.

[Journal]
#Storage=auto
#Compress=yes
#Seal=yes
#SplitMode=uid
#SyncIntervalSec=5m
#RateLimitIntervalSec=30s
#RateLimitBurst=1000
#SystemMaxUse=
#SystemKeepFree=
#SystemMaxFileSize=
#SystemMaxFiles=100
#RuntimeMaxUse=
#RuntimeKeepFree=
#RuntimeMaxFileSize=
#RuntimeMaxFiles=100
#MaxRetentionSec=
#MaxFileSec=1month
#ForwardToSyslog=yes
#ForwardToKMsg=no
#ForwardToConsole=no
#ForwardToWall=yes
#TTYPath=/dev/console
#MaxLevelStore=debug
#MaxLevelSyslog=debug
#MaxLevelKMsg=notice
#MaxLevelConsole=info
#MaxLevelWall=emerg
#LineMax=48K
ReadKMsg=no

필요한 경우 각 설정을 조절하여 사용할 수 있다.

 

 

 

참고 문서

https://www.lesstif.com/system-admin/linux-journalctl-82215080.html

https://www.lesstif.com/system-admin/systemd-journal-82215092.html

https://www.freedesktop.org/software/systemd/man/journalctl.html

https://sysops.tistory.com/115

https://ko.linux-console.net/?p=2143#gsc.tab=0

728x90