Contents
see List작성일 2025. 11. 30.
Linux 로그 분석 - journalctl, tail, grep
Linux 시스템에서 로그 파일을 분석하고 문제를 진단하는 방법입니다.
주요 명령어
tail -f /var/log/syslog # 실시간 로그 모니터링
journalctl -xe # systemd 로그 확인
zgrep "error" *.gz # 압축 로그 검색tail - 실시간 로그 모니터링
# 마지막 10줄 (기본)
tail /var/log/syslog
# 마지막 N줄
tail -n 50 /var/log/syslog
# 실시간 모니터링 (follow)
tail -f /var/log/syslog
# 여러 파일 동시 모니터링
tail -f /var/log/syslog /var/log/auth.log
# 특정 키워드 필터링하며 모니터링
tail -f /var/log/syslog | grep --line-buffered "error"
# 로그 로테이션 추적
tail -F /var/log/myapp.logjournalctl - systemd 로그
# 전체 로그
journalctl
# 오류와 설명 함께 보기
journalctl -xe
# 특정 서비스 로그
journalctl -u nginx
journalctl -u tomcat
# 실시간 추적
journalctl -f
# 오늘 로그만
journalctl --since today
# 특정 기간
journalctl --since "2024-01-01" --until "2024-01-02"
journalctl --since "1 hour ago"
# 부팅 이후 로그
journalctl -b
# 이전 부팅 로그
journalctl -b -1
# 우선순위별 (에러만)
journalctl -p err
# 커널 로그
journalctl -k
# JSON 형식 출력
journalctl -o json-prettygrep - 로그 검색
# 기본 검색
grep "error" /var/log/syslog
# 대소문자 무시
grep -i "error" /var/log/syslog
# 줄 번호 표시
grep -n "error" /var/log/syslog
# 전후 컨텍스트
grep -B 3 -A 3 "error" /var/log/syslog
# 재귀 검색
grep -r "error" /var/log/
# 파일명만 출력
grep -l "error" /var/log/*.log
# 정규표현식
grep -E "error|fail|warn" /var/log/syslog
# 제외 검색
grep -v "DEBUG" /var/log/myapp.log압축 로그 검색
# gzip 압축 파일 검색
zgrep "error" /var/log/syslog.*.gz
# 모든 압축 로그에서 검색
zcat /var/log/syslog.*.gz | grep "error"
# bzip2 압축 파일
bzgrep "error" file.bz2주요 로그 파일 위치
| /var/log/syslog | 시스템 로그 (Debian계열) |
| /var/log/messages | 시스템 로그 (RHEL계열) |
| /var/log/auth.log | 인증 로그 |
| /var/log/kern.log | 커널 로그 |
| /var/log/nginx/ | Nginx 로그 |
| /var/log/httpd/ | Apache 로그 |
실전 활용
# 최근 에러 찾기
journalctl -p err --since "10 min ago"
# 특정 시간대 로그
awk "/^Jan 14 10:/ {print}" /var/log/syslog
# 로그 통계
grep -c "error" /var/log/syslog
cat /var/log/access.log | cut -d" " -f1 | sort | uniq -c | sort -rn | head
# SSH 접속 실패 확인
grep "Failed password" /var/log/auth.logos
| No | 작성일 | Title |
|---|---|---|
| 245 | 2015. 03. 11. | [ centos ] centos /lib/ld-linux.so.2: bad ELF interpreter: 그런 파일이나 디렉터리가 없습니다 오류 |
| 244 | 2015. 03. 10. | [ centos ] centos 7 apache 설치 및 tomcat 연동 |
| 243 | 2015. 03. 10. | [ CentOS ] centos 7 console boot |
| 226 | 2015. 03. 09. | [ centos ] centos 7 에 tomcat 서비스등록 ( systemclt ) |
| 225 | 2015. 03. 08. | [ centos ] centos 7 samba 설치하기 공유 폴더 윈도우에서 사용하기 |
| 224 | 2015. 03. 08. | [ centos ] centos 7 service 관리 ( systemctl ) |
| 223 | 2015. 03. 08. | [ centos ] centos 7 firewall ( 방화벽 ) 설정 |
| 183 | 2015. 03. 08. | [ centos ] centos 7 nfs 설정 |
| 147 | 2015. 02. 10. | [ OS ] 로드밸런싱 ( load balancing ) 과 세션 클러스트링 ( session clustering )의 개념 |
| 146 | 2015. 01. 30. | [ windows ] 윈도우 서버 원격 접속시 라이선스 문제 발생할때 |