Linux log File Explorer--logrotate

Source: Internet
Author: User

Log files contain useful information about the events that occur in the system, which are often used during troubleshooting or during system performance analysis. For busy servers, the log file size grows extremely fast and the server consumes disk space quickly, which is a problem. In addition, dealing with a single large log file is often tricky.

If there is a log file:
/var/log/log-file
We cut this log file
Vim/etc/logrotate.d/log-file

/var/log/log-file {    monthly    size=50M    rotate 5    compress    delaycompress    missingok    notifempty    create 644 root root    dateext    postrotate        /usr/bin/killall -HUP rsyslogd    endscript}
    • Monthly: The log file will be round by month. Other available values are ' daily ', ' weekly ' or ' yearly '.
    • size=50m: Log file is larger than 50M for cutting
    • Rotate 5:5 archive logs will be stored at a time. For a sixth archive, the oldest archive will be deleted.
    • Compress: After a round-robin task is completed, the archived archive will be compressed using gzip.
    • Delaycompress: Always with the Compress option, the delaycompress option indicates * logrotate do not compress the most recent archive, and compression will take place in the next round-robin cycle. This is useful when you or any software still needs to read the latest archive.
    • Missingok: During log rotation, any errors will be ignored, such as "files cannot be found".
    • Notifempty: If the log file is empty, the round robin does not proceed.
    • Create 644 root root: Creates a completely new log file with the specified permissions, and logrotate renames the original log file.
    • Dateext: Renaming a backup file by date
    • Postrotate/endscript: After all other instructions have been completed, the commands specified inside postrotate and Endscript will be executed. In this case, the RSYSLOGD process will immediately read its configuration again and continue to run.
Logrotate can be called manually from the command line at any time.

To invoke Logrotate for all logs configured under/etc/lograte.d/:

#logrotate/etc/logrotate.conf
To call logrotate for a specific configuration:

#logrotate/etc/logrotate.d/log-file

Linux log File Explorer--logrotate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.