journald と logrotate による集中ロギングとローテーション
journalctl で systemd のログを読み、logrotate でログファイルによるディスクの圧迫を防ぎ、自動化システムを健全に保つ方法を学びます。
「journald と logrotate による集中ロギングとローテーション」はCoddyKit上の無料Linux Command Line Masteryレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはLinux Command Line Mastery学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Linux Command Line Masteryコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Automation Needs Logs
Cron jobs, systemd services, and shell functions all produce output. To run unattended systems you must capture, search, and rotate that output. Enter journalctl and logrotate.
What Is journald?
systemd-journald collects logs from services you manage with systemctl into a structured binary journal you query with journalctl.
Viewing Logs
Plain journalctl shows everything; -e jumps to the end (newest entries).
journalctl -eFiltering by Service
-u limits the journal to one unit, perfect for debugging a single service.
journalctl -u nginx.serviceFollowing Logs Live
-f streams new entries as they arrive, like tail -f for systemd.
journalctl -u nginx.service -fFiltering by Time and Priority
--since and -p narrow results. Here we show errors from the last hour.
journalctl --since '1 hour ago' -p errControlling Journal Size
Journals can grow large. --vacuum-size trims them to a target size.
sudo journalctl --vacuum-size=200MPlain-Text Logs and logrotate
Many apps still write to /var/log/*.log. logrotate rotates, compresses, and deletes these on a schedule so disks do not fill.
cat /etc/logrotate.confA logrotate Rule
Drop a config in /etc/logrotate.d/. This rotates daily, keeps 7 copies, and compresses old ones.
/var/log/myapp/*.log {
daily
rotate 7
compress
missingok
notifempty
}Testing logrotate
-d does a debug dry run that shows what would happen without changing files; -f forces an immediate rotation.
sudo logrotate -d /etc/logrotate.d/myappTying It to Automation
Have cron jobs and functions log to a dedicated file, manage that file with a logrotate rule, and use journalctl for everything run as a systemd service. Now nothing fills the disk silently.
Quick Check
Which journalctl option shows logs for a single systemd service?
Recap
You can keep automated systems observable and tidy:
journalctl -u,-f,--since,-pquery systemd logs--vacuum-sizetrims the journallogrotaterotates/compresses plain-text logs via/etc/logrotate.d/logrotate -ddry-runs your config
AI チューターと学ぶ Linux Command Line Mastery — 無料
ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。
- コース
- 12
- レッスン
- 48
よくある質問
「journald と logrotate による集中ロギングとローテーション」レッスンは無料ですか?
はい。「journald と logrotate による集中ロギングとローテーション」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Linux Command Line Masteryコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Linux Command Line Masteryコースには全4レッスンが含まれています。
「journald と logrotate による集中ロギングとローテーション」で何を学びますか?
journalctl で systemd のログを読み、logrotate でログファイルによるディスクの圧迫を防ぎ、自動化システムを健全に保つ方法を学びます。 ブラウザで直接実行するハンズオンコードでLinux Command Line Masteryを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Linux Command Line Masteryを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのLinux Command Line Masteryは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「journald と logrotate による集中ロギングとローテーション」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このLinux Command Line Masteryレッスンでコードを書いて実行できますか?
はい。すべてのLinux Command Line Masteryレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- ジョブのスケジューリング:`cron`と`at`
- サービス管理:`systemctl`(systemd)
- シェル関数によるタスクの自動化
- journald と logrotate による集中ロギングとローテーション