11.2 Analyze and Store Logs
11.2 Analyze and Store Logs
To locate and accurately interpret relevant system log files for troubleshooting purposes. Linux
logs provide a timeline of events for the Linux operating system, applications, and system, and
are a valuable troubleshooting tool when you encounter issues. Essentially, analyzing log files is
the first thing an administrator needs to do when an issue is discovered.
Logs File:
A log file is a file that records events that occur in an operating system, applications & services.
Logging is the act of keeping a log. There are different log files for different information. The
files are stored in plain text to make them easy to read.
System Logging:
Processes and the Operating System kernel need to be able to record a log of events that
happen. These logs can be useful for auditing the system and troubleshooting problems. Almost
all logfiles are located under /var/log directory and its sub-directories on Linux. You need be
the root user to view or access log files on Linux. You can use less, more, cat, grep, tail, etc
commands to see the log files. There are different log files for different information.
Log File Purpose
/var/log The main log files directory
/var/log/messages Most syslog messages are logged in this file. Such as system error
messages, system startups & shutdowns, change in network config
/var/log/cron.log The log file related to periodically executed tasks
/var/log/maillog The log file with mail server related messages such as sendmail
/var/log/boot.log Messages related to system startup are logged here starting service
/var/log/secure The log file for security & Authentication related such ssh
Syslog Files:
The Syslog protocol is supported by a wide range of devices and can be used to log different
types of events. Many programs use the syslog protocol to log events to the system. Each log
message is categorized by a facility (Type of Message) and a priority (Severity of the Message).
Syslog Priorities:
Priority Code Severity
Emergency 0 System-Unusable
Alert 1 Action Must be Taken Immediately
Critical 2 Critical Condition
Error 3 Non-Critical Error Condition
Warning 4 Warning Condition
Notice 5 Normal but Significant Events
Informational 6 Information Events
Debug 7 Debug Level Messages
Introduction to Journald:
Log files can also be managed by the journald daemon – a component of systemd. Logging data
is collected, stored, and processed by the Journal's journald service. It creates and maintains
binary files called journals based on logging information that is received from the kernel, from
user processes, from standard output, and standard error output of system services. These
journals are structured and indexed, which provides relatively fast seek times. Journal entries
can carry a unique identifier. The journald service collects numerous meta data fields for each
log message. The actual journal files are secured, and therefore cannot be manually edited.
Log files produced by journald are by default not persistent, log files are stored only in memory
in the /run/log/journal/ directory. The amount of logged data depends on free memory, when
you reach the capacity limit, the oldest entries are deleted. The journald daemon is the primary
tool for troubleshooting.
Logger:
logger is a command-line application that sends messages to the system logger. In addition to
being a good diagnostic tool. By default, it sends the message to the facility user with severity
notice (user. notice) unless specified otherwise with the -p option. It is especially useful to test
changes to the rsyslog configuration. Logger facilities are auth, authpriv, cron, daemon, ftp,
kern, lpr, mail, news, security, syslog, user and uucp.
# logger -p daemon.warn "This is only a warning test."
# logger -p user.notice "This is only a notice test."
# logger -p security.warn "This is only a security test."
# logger "Log entry created locally"
Commands Description
# timedatectl status Display the current time and date of system
# timedatectl Current Timezone
# timedatectl set-time 22:31:14 Set time only, we can use set-time
# timedatectl set-time "2015-04-15 Set both date and time
22:37:22"
# timedatectl set-timezone Set your local timezone
America/New_York
# timedatectl list-timezones View all available timezones
# timedatectl set-ntp yes Synchronization with remote NTP server
# timedatectl set-ntp false Disable NTP time synchronization date
# timedatectl set-timezone UTC Set the coordinated universal time, UTC
# timedatectl | grep local Hardware clock is set to local timezone
# timedatectl set-local-rtc 1 Set hardware clock to local timezone