Log-cutting operation in operational dimension (Logrotate/python/shell script implementation)

Source: Internet
Author: User
Tags system log

The Logrotate program is a log file management tool. Used to split log files, delete old log files, and create new log files that play a "dump" role. can save disk space. The following is a logrotate log rotation operation to do a comb record:

1 Configuration file Introduction
The Linux system defaults to installing the Logrotate tool, which defaults to the configuration file in:
/etc/logrotate.conf
/etc/logrotate.d/

Logrotate.conf is the main configuration file, LOGROTATE.D is a directory, all the files in the directory will be actively read into the/etc/logrotate.conf execution.
In addition, if the/etc/logrotate.d/inside the file does not set some details, it will be/etc/logrotate.conf this file as the default value of the setting.

Logrotate is run based on Cron, whose script is/etc/cron.daily/logrotate, and the log rotation is automated by the system.
When you actually run, Logrotate invokes the configuration file/etc/logrotate.conf.
You can place a custom profile in the/ETC/LOGROTATE.D directory to override the Logrotate defaults.

1 2 3 4 5 6 7 8 9 [Root@huanqiu_web1 ~] # cat/etc/cron.daily/logrotate #!/bin/sh/usr/sbin/logrotate/etc/logrotate. conf >/dev/null 2>&1 exitvalue=$?  If [$EXITVALUE!= 0]; Then/usr/bin/logger-t logrotate "ALERT exited abnormally with [$EXITVALUE]" fi exit 0

If you can't wait for cron to automate the log rotation, you want to manually force the cut log, you need to add the-f parameter, but it's best to verify it with the Debug option before you do it (-D parameter), which is also important for debugging
#/usr/sbin/logrotate-f/etc/logrotate.d/nginx
#/usr/sbin/logrotate-d-f/etc/logrotate.d/nginx

Logrotate command format:
Logrotate [OPTION ...] <configfile>
-D,--debug:debug mode, test the configuration file for errors.
-F,--force: Force dump file.
-M,--mail=command: After compressing the log, send the log to the specified mailbox.
-S,--state=statefile: Using the specified state file.
-V,--verbose: Shows the dump process.

Action based on log cutting settings and display details
[Root@huanqiu_web1 ~]#/usr/sbin/logrotate-v/etc/logrotate.conf
[Root@huanqiu_web1 ~]#/usr/sbin/logrotate-v/etc/logrotate.d/php

Executes according to the log cutting settings and displays details, but does not do any specific work, debug mode
[Root@huanqiu_web1 ~]#/usr/sbin/logrotate-d/etc/logrotate.conf
[Root@huanqiu_web1 ~]#/usr/sbin/logrotate-d/etc/logrotate.d/nginx

View the individual log file implementation
[Root@fangfull_web1 ~]# Cat/var/lib/logrotate.status

2) Cutting Introduction
For example, the system log/var/log/message to do the cutting to simply explain:

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.