- [Instructor] Welcome to the next video of section eight,
Logfile Management with logrotate.
In the previous video, we have learned
about logging access to files and directories.
In this video, we're going to see how
to rotate logs and store them.
Logfiles are essential components of a Linux system
to keep track of events happening
on different services on the system.
This helps to debug issues
as well as provide statistics on the live machine.
Management of logfiles is required because, as time passes,
the size of a logfile gets bigger and bigger.
Therefore, we use techniques called rotation,
such that we limit the size of the logfile,
and if the logfile reaches a size beyond the limit,
it will strip the logfile with that size
and store the older entries in the logfile archived
in log directories.
Hence, older logs can be stored
and kept for future references.
Logrotate is a command every Linux system admin should know.
It helps restrict the size of the logfile to the given size.
In a logfile, the logger appends information to the logfile.
Hence, the recent information appears
at the bottom of the logfile.
Logrotate will scan specific logfiles
according to the configuration file.
It will keep the last 100 kilobytes,
for example, size equals 100k,
from the logfile and move rest of the data, older log data,
to a new file logfile_name.1 with older entries.
When more entries occur in the logfile, logfile_name.1,
and it exceeds the size,
it updates the logfile with recent entries
and creates logfile_name.2 with older logs.
This process can easily be configured with logrotate.
It can also compress the older logs as logfile_name.1.gz,
logfile_name2.gz,
and so on.
The option of whether older logfiles are
to be compressed or not is available
with the logrotate configuration.
Logrotate has the configuration directory at this location.
If you look at this directory by listing its contents,
many other logfile configurations can be found.
We can write our custom configuration
for our logfile as follows.
Now the configuration is complete.
This location in the configuration
specifies the logfile path.
It will archive old logs in the same directory path.
Let's see what each of the parameters
in the configuration means.
Missingok,
ignore if the logfile is missing
and return without rotating the log.
Notifempty,
only rotate the log if the source logfile is not empty.
Size 30k, limit the size of the logfile
for which the rotation is to be made.
It can be made one meg for one megabyte.
Compress, enable compression with gzip for older logs.
Weekly, specify the interval
at which the rotation is to be performed.
It can be weekly, yearly, or daily.
Rotate five, its number of older copies
of logfile archive to be kept.
Since five is specified, there will be a program like this.
Create 0600 root root,
specify the mode, user, and the group
of the logfile archive to be created.
The options specified in the table are optional.
We can specify the required options only
in the logrotate configuration file.
There are numerous options available with logrotate.
Please refer to the man pages
for more information on logrotate.
Awesome, we've successfully learned
logfile management with logrotate.
In the next video, we'll learn how to log with syslog.