Logrotate separates log files

Source: Internet
Author: User

Yesterday, the online project we participated in was launched. After reading the log file, we did not split it. Considering that the log file may cause a large number of log files to cause performance degradation, we quickly split the log file. In Linux, there is a logrotate tool that can assist log segmentation. You only need to configure the parameters, which is very convenient. Therefore, you can directly configure this method.

I used to split nginx log files. My configuration file is as follows:

Create a configuration file, such as nginx, in the/etc/logrotate. d/directory. The file content is as follows:

/Search/nginx/logs/access_log/search/nginx/logs/error. Log {
Daily
Dateext
Extension. Log
Create
Rotate 60
Notifempty
Sharedscripts
Postrotate
[! -F/usr/local/nginx/sbin/nginx. pid] | kill-usr1 'cat/usr/local/nginx/sbin/nginx. PID'
Endscript

}

The field meanings are as follows:

The daily is separated once a day.

Dateext indicates that the log file is represented in the log format, so that the log name is changed to access-20140626.

Extension. log indicates that the. log extension is added after the log name to the well-known programming access-20140626.log.

"Create" indicates that access. log is created after a new log file is created.

Rotate 60 indicates backing up so many copies

Receivempty indicates that log files are not separated if they are empty.

Sharedscripts indicates that logrotate is executed only once between multiple log files.

Postrotate
[! -F/usr/local/nginx/sbin/nginx. pid] | kill-usr1 'cat/usr/local/nginx/sbin/nginx. PID'
Endscript

Indicates the command that is executed after logrotate is executed

There are many other parameters, which can be viewed by man logrotate.

After configuring logrotate, I thought that I had to set the crontab file to regularly execute logrotate, so:

Crontab-e

59 23 ***/usr/sbin/logrotate-F/etc/logrotate. d/nginx

The result is that the logrotate is automatically executed at and, when the time is, you can also modify the configuration file to modify the time, so you do not need to set the crontab file.

There is a time difference between copying and clearing, so some log data may be lost.

 

 

 

 

 

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.