Video summary
The video focuses on the importance of managing log files in Linux systems to prevent storage issues while maintaining system health. Although Linux excels at automatically recording events and errors through logs, these accumulated records can consume significant disk space over time. The presenter introduces `journalctl` as a powerful command-line tool for viewing and managing systemd journal logs, demonstrating how it reports current usage and identifies missing data when run with the appropriate flags. He highlights that while his personal desktop has ample storage to absorb large log files, his web server operates on a much smaller 25-gigabyte partition where excessive logging can quickly approach capacity limits, necessitating proactive cleanup strategies.
To address space constraints, the presenter explains two primary methods for clearing old logs using `journalctl`. The first method involves specifying a time limit with the vacuum command to delete entries older than a set period, such as two weeks, which successfully freed up over three gigabytes in his demonstration. This approach is ideal for retaining recent data while discarding historical information that may no longer be relevant for troubleshooting current issues. Alternatively, users can enforce a hard size cap on their logs by setting a maximum limit using the vacuum size option; applying this to his server reduced log usage significantly and ensured it stayed well below critical thresholds without requiring frequent manual intervention or reboots.
The presenter concludes that while retaining longer logs might be necessary for investigating ongoing complex problems, most systems do not require more than two weeks of data or a few hundred megabytes of storage allocated specifically to journals. He shares his personal workflow where he monitors free space and receives alerts if it drops below one gigabyte, prompting either a reboot to clear temporary files or the execution of cleanup scripts every couple of weeks. By implementing these automated checks and size limits on constrained servers like his web host, administrators can maintain efficient disk usage without sacrificing essential diagnostic information for recent system events.
Read the full video transcript
Hello and welcome to a video from
filmsbychris.com. That's Chris with the
K. I'm Chris with the K. Today we're
going to be looking at cleaning up some
of your log files. So, a Linux system
does a real good job of keeping logs of
stuff that happens on your system, which
can come in really, really handy, but
can also take up some space. Let's look
at this command.
We got journalctl
here.
Sorry, journalctl,
so journal control, I would assume that
stands for. Let's go ahead and give it
the option of disk usage. So, dash dash
disk dash usage. It's going to give me
this message here. It's going to tell me
that there's currently 583 megabytes,
but it's also telling me that we're
missing some stuff. Let's run that same
command and run sudo. I've recently
typed in my password, so it's not going
to ask me for it again. Normally it
would ask you for your password. But you
can see I have almost 4 gigs worth of
journals, of logs on my Linux system.
Which isn't too bad on my current
system, cuz again I have like a terabyte
here on my desktop. But my filmsbychris
server I run my website on is only a 25
gig server. And I've been very close to
that limit for a long time, so I have to
keep things cleared out. And lately I've
had 2 to 3 gigs worth of space, but
every 2 weeks or so I have a little
script that checks and makes sure that
it doesn't get full. If it gets under a
gig of free space,
I get a message to my phone. And so
every like, like I said, we can have 2
weeks I get that message. I just reboot
the server, it clears out temporary
files.
But I was looking for ways to clear out,
and so when you only have 25 gigs, like
something like 4 gigs is a lot. And I
think when I ran this on my server, it
was, yeah, over 3 gigs or around 3 gigs
worth of space.
So, let's go ahead and clear that out.
So, what we could do is we can use that
same command, but this time we're going
to give it the dash dash vacuum dash
time equals 2 weeks. This will clear out
anything older than 2 weeks. So, right
now I have 4 gigs worth of log files,
and then I'm going to run that. I get
all this output, and then
we freed up 3.3 gigs worth of stuff. So,
let's go ahead and run this disk usage
command again, and you can see now I'm
only using 620 megs. Now, we can set a
limit here. We can run something like
this. We can do sudo. We can use that
journal control command vacuum {dash}
size, and we can limit the size of our
logs to 500 megabytes. I'm not going to
do that on my local system, but I ran
that on my filmsbychris system. After I
ran this on my filmsbychris system, it
actually brought down to like 120 some
megabytes of logs, and then I set the
max to 500 megabytes. I do want some
good logs on my web server, obviously.
So, I could always limit that more
later. But, if you are especially on a
limited system or just looking to clear
things out, this is a great way to clear
out some logs that are older,
which, you know, if you have ongoing
problems, you may want longer logs. But,
usually if you're having issues, you
know, 2 weeks or at least a couple
hundred megabytes should be enough. Do
whatever works for your system, but I
thought you might find this useful.
Hopefully, I'll get less of those
messages
to clear out space on my filmsbychris
server. Anyway, if you enjoy
filmsbychris, think about liking,
sharing, subscribing, and supporting me
over on Patreon.
And, you know, the cost of running a
website isn't very much,
but that's only because I keep a minimal
system there.
Maybe I can always upgrade it if I get
more supporters like you. So, thank you
for watching. As always, I hope that you
have a great day.