惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
I
InfoQ
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 【当耐特】
小众软件
小众软件
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
Engineering at Meta
Engineering at Meta
人人都是产品经理
人人都是产品经理
Microsoft Security Blog
Microsoft Security Blog
Last Week in AI
Last Week in AI
H
Help Net Security
爱范儿
爱范儿
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Microsoft Azure Blog
Microsoft Azure Blog
L
LangChain Blog
WordPress大学
WordPress大学
GbyAI
GbyAI
Google DeepMind News
Google DeepMind News
腾讯CDC

Posts on Noah Bailey

How to turn anything into a router Deploy to Cloudfront from GitHub using OpenID Connect Backup Postgres databases with Kubernetes CronJobs The spelling error made 200 billion times a day Restarting Kubernetes pods using a CronJob You've just bought a new domain. Now what? Who Sawed My Motherboard??? Linux on the P8 Aliexpress Mini Laptop Recovering Mysql/Mariadb after a nasty crash Using EXIF data to pick my next lens Converting and developing RAW photos on Linux automatically Thank you, 2016 iPhone Don't Make It Work Self-hosted Surveillance with ZoneMinder Backups, Monitoring, and Security for small Mastodon servers Block web scanners with ipset & iptables Executing commands over SSH with GitHub Actions Debian Sid on encrypted ZFS Protect your dangerously insecure redis server Debian: the luxurious boring lifestyle Monitor radiation with a Raspberry Pi Simple Linux server alerts: Know your performance, errors, security, syslog, and security NUC crashes on debian 11 - How I fixed it Basic Linux server security with fail2ban, ossec, and firewall Windows 11 will create heaps of needless trash Domesticated Kubernetes Networking The Cursed Certificate Our mostly disposable and entirely stupid world Trying out OpenBSD (as a Linux geek) Making VoIP Calls with Antique Rotary Phones
Cleanup Systemd Journald Storage
2019-07-10 · via Posts on Noah Bailey

With the move from sysvinit to systemd, there were lots of small but important changes to the Linux ecosystem. One of them was the move from traditional syslog daemons to Systemd Journald. Now I’m not going to say this is a good or bad thing, as it entirely depends on your old habits and new optimism. What it does mean is a move to a faster and more flexible system log format but at the cost of some added complexity.

Historically, logrotate could be used to squash log files that got big over time. However, since Systemd Journald stores logs in a new binary format that approach doesn’t really work anymore. It’s best to let it do it’s own thing. Sometimes, though, you need to step in…

First, the wrong way:

The wrong thing to do is delete the files in /var/log/journal. Since the systemd journal is essentially a database, this is a pretty bad idea. It’s probably going to be okay, but it’s so easy to do it correctly that it’s not worth the risk.

Now, the right way:

Purge logs by size

Here’s a new command I learned today; how to force journald to manually squash the logs:

journalctl --vacuum-size=500M

And just like that, journald will purge old logs until it’s under the size you requested. In my case, my Linux laptop was using over a gig of space in /var/log/journal, which is a sizable portion of my frugal 120 gig solid state drive. Here’s what that looked like:

$ sudo journalctl --vacuum-size=500M

Deleted archived journal /var/log/journal/f8dfbb5a095c4855a5f326d99bb598a6/[email protected]~ (24.0M).
....
Vacuuming done, freed 672.1M of archived journals from /var/log/journal/f8dfbb5a095c4855a5f326d99bb598a6.

Purge logs by date

Alternatively, it might be desired to only retain a few days of logs. I don’t really mind losing some data retention from my beater laptop, so this isn’t an issue. Obviously, you shouldn’t do this on a server unless you have a reliable log collector. I only need the last two days of logs, so let’s see how much space can be reclaimed:

$ sudo journalctl --vacuum-time=2d

Deleted archived journal /var/log/journal/f8dfbb5a095c4855a5f326d99bb598a6/[email protected]~ (16.0M).
....
Vacuuming done, freed 488.1M of archived journals from /var/log/journal/f8dfbb5a095c4855a5f326d99bb598a6.

After chopping off all those logs, the entire journal is only taking up 33 MB!

$ sudo du -cksh /var/log/journal/*

33M	journal/f8dfbb5a095c4855a5f326d99bb598a6
8.0K	journal/remote
33M	total

Hopefully this can help somebody else adjust to the new way of logging!