Periodically generate logs with logrotate and delete them periodically for all logs on the system

Source: Internet
Author: User

Detailed Introduction http://blog.csdn.net/hepeng597/article/details/7768615

Reference http://www.linuxidc.com/Linux/2011-04/34116.htm

1 For example we want to cut Nginx log, first we enter/etc/logrotate.d/this directory, and then build nginx this file

VI Nginx

/data/wwwlogs/*nginx.log {# #日志所在的目录dailyrotate 5missingokdateextcompressnotifemptysharedscriptspostrotate [-E/ Var/run/nginx.pid] && kill-usr1 ' cat/var/run/nginx.pid ' Endscript}


Parameter description:

Monthly specify a dump cycle of monthly

Daily Specify a dump cycle of daily

Weekly specify the dump cycle as weekly

Rotate count Specifies the number of times the log file was dumped before it was deleted, 0 means no backup, 5 means 5 backups reserved (this means a 5-day backup is reserved)

Compress post-dump log after gzip compression

Copytruncate The log file is emptied after the current log file is copied, instead of renaming the current log file to create a new

Notifempty if it's an empty file, don't dump it.

Dateext the log file after switching appends the date of the previous dash and YYYYMMDD format.

[-e/var/run/nginx.pid] && kill-usr1 ' cat/var/run/nginx.pid ' endscript This parameter is for Nginx to regenerate the log

2. Restart the SYSLOGD service


Service Rsyslog Restart



3 Testing

#强制执行某个日志的切换, Nginx is the filename of the file under/ETC/LOGROTATE.D

Logrotate-f/etc/logrotate.d/nginx

#如果在存放日志的目录下发现了切换的日志文件, the switch is successful


This article is from the "Drifting Away" blog, make sure to keep this source http://825536458.blog.51cto.com/4417836/1812252

Periodically generate logs with logrotate and delete them periodically for all logs on the system

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.