Linux log File Explorer--logrotate

Source: Internet
Author: User

1, Logrotate Introduction

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.

Logrotate is a useful tool that automatically truncates (or rounds) logs, compresses, and deletes old log files. For example, you can set Logrotate to have/var/log/foo log files every 30 days and delete logs for more than 6 months. Once configured, the logrotate is fully automated, without any further human intervention. In addition, old logs can also be sent by e-mail.

2, Logrotate installation

Logrotate packages are installed by default on mainstream Linux distributions, and if for some reason logrotate does not appear inside, you can use

Yum Install logrotate crontabs     # #本文只讲述centos的版本, other system versions please check your own
3. logrotate configuration file

A, logrotate.conf

The primary configuration file for Logrotate is/etc/logrotate.conf, and it is usually not necessary to modify it.

1[Email protected] logrotate.d]# cat/etc/logrotate.conf2# See"Mans Logrotate"  forDetails3 # rotate log files weekly4 Weekly5 6# Keep4weeks worth of backlogs7Rotate48 9# CreateNew(empty) log files after rotating old onesTen Create One  A# Use Date asa suffix of the rotated file - Dateext -  the# Uncomment This ifYou want your log files compressed - #compress -  -# RPM Packages Drop log rotation information into ThisDirectory +include/etc/LOGROTATE.D -  +# no packages own wtmp and btmp--we'll rotate them here A/var/log/wtmp { at Monthly -Create0664Root utmp - minsize 1M -Rotate1 - } -  in/var/log/btmp { - Missingok to Monthly +Create0600Root utmp -Rotate1 the } *  $# system-specific logs May is also is configured here.
View Code

B, LOGROTATE.D

The rotation of the log file is set in a separate configuration file, which is placed in the/etc/logrotate.d/directory. LOGROTATE.D is a directory in which all files in the directory are actively read into the/etc/logrotate.conf.
In addition, if there are no details in the file in/etc/logrotate.d/, the default value will be set to/etc/logrotate.conf the file.

[Email protected] logrotate.d]# cd/etc/logrotate.d/[[email protected] logrotate.d]# lsdracut  httpd  php -fpm  syslog  Yum

C, Script

Logrotate is based on Cron, and its script is/etc/cron.daily/logrotate, and the log rotation is done automatically by the system.
Logrotate will invoke the configuration file/etc/logrotate.conf when it is actually running.
A custom configuration file can be placed in the/ETC/LOGROTATE.D directory to overwrite the default values of the Logrotate.

1[Email protected] logrotate.d]# cat/etc/cron.daily/logrotate2#!/bin/SH3 4/usr/sbin/logrotate/etc/logrotate.conf5Exitvalue=$?6 if[$EXITVALUE! =0 ]; Then7/usr/bin/logger-t logrotate"ALERT exited abnormally with [$EXITVALUE]"8 fi9Exit0
View Code

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.