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

推荐订阅源

量子位
博客园_首页
罗磊的独立博客
云风的 BLOG
云风的 BLOG
J
Java Code Geeks
Last Week in AI
Last Week in AI
D
DataBreaches.Net
Jina AI
Jina AI
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
V
V2EX
D
Docker
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
宝玉的分享
宝玉的分享
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
H
Help Net Security
T
The Blog of Author Tim Ferriss

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!