Log files and journals are important to a system administrator's work. They reveal a great deal of information about a system and are instrumental during troubleshooting and auditing.
Log files contain events and messages generated by the kernel, applications, and users that log into the system.
Use rsyslog
Syslog and rsyslog have long been used to provide logging on Linux servers. Systemd became the default service manager with Red Hat Enterprise Linux (RHEL) 7, and it introduced its own logging system called systemd-journald. systemd-journald continues to be the logging mechanism on RHEL 8 and 9 while keeping rsyslog for backward compatibility.
The rsyslog service keeps various log files in the /var/log
directory. You can open these files using native commands such as tail
, head
, more
, less
, cat
, and so forth, depending on what you are looking for.
For example, to display boot and other kernel messages, view /var/log/messages
:
[server]$ cat /var/log/messages
Use grep
and other filtering tools to gather more specific events from a file. You can also use tail
to view files as they are updated:
[server]$ tail -f /var/log/messages
In the command above, the -f
option updates the output when new log file entries are added.
Check the /var/log/secure
file to view users and their activities:
[server]$ tail -f /var/log/secure
Use systemd-journald
The systemd-journald service does not keep separate files, as rsyslog does. The idea is to avoid checking different files for issues. Systemd-journald saves the events and messages in a binary format that cannot be read with a text editor. You can query the journal with the journalctl
command.
To show all event messages, use:
[server]$ journalctl
This is similar to the /var/log/messages
in the rsyslog service.
[ Download the free eBook Manage your Linux environment for success. ]
To view the last 10 event messages, use:
[server]$ journalctl -n
You can view the last n entries by using journalctl -n {number}
. For example, to view the last 20 entries, type:
[server]$ journalctl -n 20
To output new journal entries as they are written to the journal, use:
[server]$ journalctl -f
Run the following command to display the kernel message log from the last boot:
[server]$ journalctl -k
The journalctl
command has several choices that can make querying the journal easier. You can query the log based on applications, time frame, systemd units, priority, and many other options. Run the journalctl –help
command to list the available options.
To view journal entries based on their critical priority, use:
[server]$ journalctl -p crit
To query all messages related to a particular user, find the user's ID (UID) and use that to perform the query. For example, to check all logs related to the sadmin user, run:
[server]$ id sadmin
uid=1000(sadmin) gid=1000(sadmin) groups=1000(sadmin)
[server]$journalctl _UID=1000
To view journal entries for today, use:
[[server]$ journalctl --since today
To view journal entries related to the sshd daemon, run:
[server]$ journalctl -u sshd
The same applies to other services running under systemd that can be stopped and started with systemctl
.
To check for messages related to the httpd service for the past hour, you can run:
[server]$ journalctl -u httpd –since "1 hour ago"
Manage log forwarding
RHEL 8 and 9 servers use both rsyslog and systemd-journald, and they complement each other to perform logging. Systemd-journald does not have a mechanism to forward logs to external systems and monitoring applications. A configuration modifies this in the /etc/systemd/journald.conf
. The ForwardToSyslog
parameter defines whether entries in the journal should be forwarded to syslog. When enabled, syslog then captures the entries as they come through systemd-journald and forwards them accordingly.
Wrap up
Current RHEL distributions rely on systemd and the related journald logging tool. However, rsyslog still plays a major role in logging for many administrators—particularly when it comes to log forwarding and centralization. Sysadmins must know how to use both log mechanisms effectively. These commands will help you learn and use system logging for troubleshooting and audits. Work with them both and you will have a much better understanding of what is happening on your Linux systems.
저자 소개
I work as Unix/Linux Administrator with a passion for high availability systems and clusters. I am a student of performance and optimization of systems and DevOps. I have passion for anything IT related and most importantly automation, high availability, and security.
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
오리지널 쇼
엔터프라이즈 기술 분야의 제작자와 리더가 전하는 흥미로운 스토리