로그 및 저널ctl
systemd-journald는 Ubuntu 26.04의 시스템 로깅 서비스입니다. 커널, 서비스, 애플리케이션의 모든 로그를 수집하고 관리합니다. journalctl은 이러한 로그를 쿼리하고 분석하기 위한 명령줄 도구입니다.
Journalctl 기본 사항
로그 보기
# View all logs
journalctl
# View the latest logs (tail)
journalctl -e
# Follow new logs in real time (similar to tail -f)
journalctl -f
# View the most recent N entries
journalctl -n 50
# Output without paging
journalctl --no-pager
# Reverse order (newest first)
journalctl -r출력 형식
# Short format (default)
journalctl -o short
# Verbose format (shows all fields)
journalctl -o verbose
# JSON format
journalctl -o json
# JSON format (one entry per line, convenient for scripting)
journalctl -o json-lines
# Message content only
journalctl -o cat로그 필터링
서비스별로 필터링
# View logs for a specific service
journalctl -u nginx.service
# View logs for multiple services
journalctl -u nginx.service -u php-fpm.service
# Follow a specific service's logs in real time
journalctl -u myapp.service -f시간으로 필터링
# View logs from the current boot
journalctl -b
# View logs from the previous boot
journalctl -b -1
# List all boot records
journalctl --list-boots
# Specify a time range
journalctl --since "2026-03-24 10:00:00"
journalctl --since "2026-03-24 10:00:00" --until "2026-03-24 12:00:00"
# Use relative time
journalctl --since "1 hour ago"
journalctl --since "30 min ago"
journalctl --since today
journalctl --since yesterday --until today우선순위로 필터링
로그 우선순위 수준의 범위는 0(가장 심각)부터 7(가장 자세한 정보)까지입니다.
| 레벨 | 이름 | 설명 |
|---|---|---|
| 0 | 출현하다 | 시스템을 사용할 수 없습니다 |
| 1 | 경고 | 즉각적인 조치가 필요함 |
| 2 | 치명타 | 심각한 오류 |
| 3 | 실수 | 오류 |
| 4 | 경고 | 경고 |
| 5 | 공지 | 정상적이지만 의미 있음 |
| 6 | 정보 | 정보 제공 |
| 7 | 디버그 | 디버그 |
# Show only errors and above
journalctl -p err
# Show only warnings
journalctl -p warning
# Show a range of priorities
journalctl -p warning..err기타 기준으로 필터링
# By process PID
journalctl _PID=1234
# By user ID
journalctl _UID=1000
# By executable path
journalctl _EXE=/usr/bin/python3
# Combine conditions
journalctl _SYSTEMD_UNIT=nginx.service -p err --since today
# Kernel logs
journalctl -k
journalctl --dmesg로그 내용 검색
# Filter with grep
journalctl -u nginx.service | grep "error"
# Use journalctl's built-in matching
journalctl -g "failed|error|timeout"로그 저장소 구성
구성 파일
저널 구성 파일은 /etc/systemd/journald.conf에 있습니다.
sudo nano /etc/systemd/journald.conf일반적인 구성 옵션:
[Journal]
# Log storage mode: persistent (to disk), volatile (memory only), auto (default)
Storage=persistent
# Maximum disk space for logs
SystemMaxUse=500M
# Maximum size of a single log file
SystemMaxFileSize=50M
# Maximum retention time
MaxRetentionSec=1month
# Maximum memory usage for logs
RuntimeMaxUse=100M
# Log compression
Compress=yes
# Forward to syslog
ForwardToSyslog=yes
# Rate limiting: max 10000 entries per service per 30 seconds
RateLimitIntervalSec=30s
RateLimitBurst=10000구성 변경 사항을 적용합니다.
sudo systemctl restart systemd-journald로그 지속성 보장
기본적으로 /var/log/journal/ 디렉터리가 없으면 로그는 메모리에만 보관됩니다. 지속성을 활성화하려면 다음을 수행하십시오.
# Create the persistent log directory
sudo mkdir -p /var/log/journal
sudo systemd-tmpfiles --create --prefix /var/log/journal
# Or set it in the configuration file
# Storage=persistent
# Restart the service
sudo systemctl restart systemd-journald로그 회전 및 정리
수동 정리
# Clean by time: keep only the last 7 days of logs
sudo journalctl --vacuum-time=7d
# Clean by size: keep only 500MB of logs
sudo journalctl --vacuum-size=500M
# Clean by file count: keep only the 5 most recent log files
sudo journalctl --vacuum-files=5
# View current disk usage by logs
journalctl --disk-usage로그 무결성 확인
# Check log file consistency
journalctl --verifysyslog와의 관계
systemd-journald는 기존 syslog(예: rsyslog)와 함께 작동할 수 있습니다.
# Check if rsyslog is installed
dpkg -l rsyslog
# rsyslog log files are located under /var/log/
ls /var/log/syslog
ls /var/log/auth.log
ls /var/log/kern.log기존 로그 파일
| 파일 | 설명 |
|---|---|
/var/log/syslog | 일반 시스템 로그 |
/var/log/auth.log | 인증로그 |
/var/log/kern.log | 커널 로그 |
/var/log/dpkg.log | 패키지 설치 로그 |
/var/log/apt/history.log | APT 운영 이력 |
/var/log/boot.log | 부팅 로그 |
rsyslog 구성
# Main configuration file
sudo nano /etc/rsyslog.conf
# Custom rules go in this directory
ls /etc/rsyslog.d/rsyslog 규칙 예(nginx 로그를 별도의 파일에 작성):
# /etc/rsyslog.d/nginx.conf
if $programname == 'nginx' then /var/log/nginx/syslog.log
& stoplogrotate 로그 회전
logrotate은 기존 로그 파일의 순환을 관리합니다.
# Main configuration file
cat /etc/logrotate.conf
# Application configurations directory
ls /etc/logrotate.d/사용자 정의 logrotate 구성 예:
sudo nano /etc/logrotate.d/myapp/var/log/myapp/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 0640 myapp myapp
sharedscripts
postrotate
systemctl reload myapp.service > /dev/null 2>&1 || true
endscript
}# Test logrotate manually
sudo logrotate -d /etc/logrotate.d/myapp # dry-run
sudo logrotate -f /etc/logrotate.d/myapp # force execution실용적인 팁
서비스 시작 실패 모니터링
# Create a script to monitor failed services
journalctl -p err -u "*.service" --since "5 min ago" --no-pager -o cat로그 내보내기
# Export as a text file
journalctl -u nginx.service --since today > /tmp/nginx-today.log
# Export in binary format (readable by journalctl)
journalctl -u nginx.service -o export > /tmp/nginx.export디스크 I/O 관련 로그 보기
journalctl -k | grep -i "i/o\|error\|disk\|sda"부팅 프로세스 분석
# View logs from the boot process
journalctl -b --no-pager | head -100