Linux system / var / log / journal / log garbage clean-up

CentOS log system has two services, respectively, and traditional systemd-journal rsyslog

systemd-journald an improved log management service, you can collect logs from the kernel, the early start-up phase of the system, the standard output system daemons up and running and in an error message, and syslog logging.

The log service merely logs centrally stored in a single structure of the log file / run / log, because the log is a binary data compression and formatting of experienced, so it quickly check and when.

This switched meters flutter blog: Linux system / var / log / journal / log garbage clean-up

By default, the log does not persistently saved, only save one month's journal. In addition, some rsyslog not collected logs will be recorded in the journal.

rsyslog as a traditional system logging service, all collected logs are recorded in various log files in / var / log / directory.

Common log file as follows:

The vast majority of / var / log / messages system log to record all the file
/ var / log / secure all with the security and authentication authorization log will record this file
/ var / log / maillog mail service log
/ var / log / cron crond planned tasks log
/var/log/boot.log system startup relevant log

 

Someone once said: Linux is not junk files, Windows only junk files, in fact not the case, both of which have junk files.

Operating system, is the operating system of various documents, it can not be without a log file, but could not generate temporary files, just like paper cutting, provisional produce some waste is the most natural thing.

Linux in the end there is no space junk files, to see how this determination, and several years ago, for example, log files a few months ago, system files, basically useless, considered junk files?

ls -lhm --full-time /var/log/journal/f9d400c5e1e8c3a8209e990d887d4ac1_bk_20190122/ | sort -k6 | head -n30

# ls -lhm --full-time /var/log/journal/f9d400c5e1e8c3a8209e990d887d4ac1_bk_20190122/ | sort -k6 | head -n30
total 3.5G
-rw-r-x---+ 1 root systemd-journal 64M 2018-03-28 01:36:01.010275802 +0800 system@00000000000000000000000000000000-00000000000002ca-000567d28f35cca7.journal
-rw-r-x---+ 1 root systemd-journal 8.0M 2018-03-28 01:36:01.100275802 +0800 user-65534@4ee96b2fbd8b4a82beee0402402fee03-0000000000005419-000567f7fd08bd2f.journal
-rw-r-x---+ 1 root systemd-journal 72M 2018-04-02 19:16:41.644934707 +0800 system@00000000000000000000000000000000-0000000000010a47-0005686852f561be.journal
-rw-r-x---+ 1 root systemd-journal 8.0M 2018-04-02 19:16:41.714934707 +0800 user-65534@4ee96b2fbd8b4a82beee0402402fee03-0000000000011f98-00056872cab77761.journal
RX-+. 1 --- -rw the root-TECHNOLOGY systemd 72M 2018-04-08 05: 48: 01.673026304 +0800 system@00000000000000000000000000000000-0000000000021c40-000568dbb97116ae.journal
-rw-RX. 1 --- + the root-TECHNOLOGY 72M systemd 2018 18 is -04-13: 25: 01.967846109 +0800 system@00000000000000000000000000000000-0000000000033800-00056949207ae8a1.journal
-rw-RX. 1 --- + the root-TECHNOLOGY systemd 72M 2018-04-18 04: 12 is: 35.385621922 +0800 System @ 00000000000000000000000000000000- 0000000000045c3e-000569b848f6f86c.journal
view junk files method

No clean up before the hard disk root partition found space in an emergency, to see with du -t 100M / var or journalctl --disk-usage command, found / var / log / journal log files are taking up nearly 3G space, each log file size up to 8- 128M, these log file records systemd situation a long time, and worthless, with journalctl --vacuum-size = 10M command to clean up after, freeing up space of 2.7G. Df command with a check, / root partition really spacious lot.

 

View a directory and sorting the file size (in MB)

You -Hm --max-depth = 1 / where / | Species -n

# You -Hm --max-depth = 1 / where / | Species -n
1 / var / adm
1 / was / crash
1 / was / db
1 / was / Empty
1 / was / games
1 / where / gopher
1 / was / Kerberos
1 / var / local
1 / where / nis
1 / was / opt
1 / was / preserve
1 / var / spool
1 / var / tmp
1 / where / y P
131 / var / www
198 / var / lib
486 / var / cache
3695 / was / log
8513 / was /
清空/ was / log / log文件的方法

1, with the echo command, will be redirected to an empty string content specified file

echo "" > system.journal

Description: This method will only be cleared once again after a period of time but also manually clear a lot of trouble, where you can make journalctl automatically maintain space with the following command

 

2, journalctl command automatically maintain the file size

1) retain only nearly a week of logs

journalctl --vacuum-time=1w

 

2) retain only 500MB of logs

journalctl --vacuum-size=500M

 

3) delete the log files in / var / log / journal / directory

rm -rf /var/log/journal/f9d400c5e1e8c3a8209e990d887d4ac1

 

And analyze and solve problems

Journalctl error when executing the command: Error was encountered while opening journal files: Input / output error

Time-journalctl --vacuum = # 1W
Error encountered the while Opening TECHNOLOGY WAS Files: the Input / Output error
Analysis: log files are damaged

Solution: Delete the previous logs, and restart the service journalctl

mv journal/f9d400c5e1e8c3a8209e990d887d4ac1 journal/f9d400c5e1e8c3a8209e990d887d4ac1_bk_20190122

systemctl restart systemd-journald.service

Check / var / log / journal / log directory as follows:

# ll /var/log/journal/
drwxr-sr-x 2 root systemd-journal 4096 Jan 22 11:26 f9d400c5e1e8c3a8209e990d887d4ac1
drwxr-sr-x+ 2 root systemd-journal 12288 Jan 14 15:37 f9d400c5e1e8c3a8209e990d887d4ac1_bk_20190122
 

Then, perform journalctl restrictions log command:

Time-journalctl --vacuum = # 1W
Vacuuming DONE, Freed 0B of Archived Journals ON Disk.
# 500M = journalctl --vacuum-size
Vacuuming DONE, Freed 0B of Archived Journals ON Disk.
 
---------- -----------
author: sunshine main island
source: CSDN
original: https: //blog.csdn.net/ithomer/article/details/89530790
copyright: This article is a blogger original article, please reprint Bowen attached link!

Guess you like

Origin www.cnblogs.com/zuokun/p/10996044.html