There are many log files on the Linux system, syslog message mail cron and so on, and application logs and access logs, which, under a lot of accesses, can grow rapidly, consume lots of private disk space and consume Io, The Access_log and catalina.out files of Nginx and Tomcat are now split by crontab using shell scripts on the wire.
Today accidentally think of logrotate, small tried, or good, record ...
Looking at the logs under the log directory, you can see that the logs about crontab are split, and we don't define this, what's the implementation? Is logrotate.
LL/VAR/LOG/-RW-------1 root root 0 February 03:21 cron-20150301-rw-------1 root root 0 March 1 03:20 CRO N-20150308-RW-------1 root root 0 March 8 03:19 cron-20150315-rw-------1 root root 0 March 03:35 cron- 20150322-RW-------1 root root 5740 March 22:10 cron-20150328
Look at the logrotate configuration file
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5B/F1/wKiom1UWt-aDYiegAAIGmQPAWG8645.jpg "title=" configuration file. jpg "alt=" wkiom1uwt-adyiegaaigmqpawg8645.jpg "/>
Configuration file is very simple, but also easy to understand, one will say the meaning of each parameter, you can see INCLUDE/ETC/LOGROTATE.D, look at this directory has a BAA?
[email protected] /var/log# ll /etc/logrotate.d/total dosage 40-rw-r--r--. 1 root root 103 10 Month 3 2012 dracut-rw-r--r-- 1 root Root 185 8 Moon 15 2014 httpd-rw-r--r--. 1 root root 173 6 Month 22 2012 iscsiuiolog-rw-r--r-- 1 root root 112 3 Month 28 22:05 market-rw-r----- 1 root named 170  10 Month 15 21:28 named-rw-r--r-- 1 root root 136 8 Month 23 2010 ppp-rwxr-xr-x 1 root root 452 11 month 8 03:43 salt-rw-r--r-- 1 root root 210 12 Month 10 18:05 syslog-rw-r--r-- 1 root root 100 2 Month 4 2013 wpa_supplicant-rw-r--r--&nbSp; 1 root root 87 10 Month 16 23:15 yum
The log for crontab is written in the syslog, so let's keep looking at the syslog configuration file.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5B/EB/wKioL1UWueGj0S1cAADwNxEXTJ8773.jpg "title=" 2.jpg " alt= "Wkiol1uwuegj0s1caadwnxextj8773.jpg"/> We all know that Syslog Manager cron mail message secure these logs
It seems that the main configuration file of the logrotate is not complete haha, that said a strength bar a tomcat log split, a nginx log segmentation
vim /etc/etc/logrotate.d/tomcat/data/market_tomcat/logs/catalina.out { #定义日志的位置, Of course you can write more than just like the syslog rotate 30 #保留归档30天 ~ Do not explain, you know is divided after the retention of one months daily #每天分割 copytruncate #表示此方法采用的是先拷贝再清空的方式 missingok #表示如果找不到log文件也没OK notifempty #表示如果log文件是空的, do not rotate}
Save exit, we perform the next/usr/sbin/logrotate-f/etc/logrotate.conf under look at the log file under the Tomcat directory
[email protected]/data/market_tomcat/logs# ll catalina.out-20150328-rw-r--r--1 root root 233079086 March 22:05 Catalina . out-20150328
Examples of Nginx:
/data/logs/qa.qding.qdingnet_accesslog {daily Missingok rotate 5 notifempty Sharedscripts postrotate [!-f/var/run/nginx.pid] | | KILL-USR1 ' Cat/var/run/nginx.pid ' Endscript}
Just add a shell command, restart the Nginx drop. You know
Parameter description
Parameter function
Compress post-dump log after gzip compression
Nocompress when compression is not required, use this parameter
Copytruncate for log files that are still open, to back up and truncate the current log
Nocopytruncate backing up log files but not truncation
Create Mode owner group dump file, creating a new log file with the specified file mode
Nocreate do not create a new log file
When Delaycompress and compress are in use, the dump log file is compressed until the next dump
Nodelaycompress overrides the delaycompress option, the dump is compressed at the same time.
Errors error message sent to the specified email address when the address is stored
Ifempty even empty files are dumped, this is the default option for Logrotate.
Notifempty if it's an empty file, don't dump it.
Mail address sends dump log files to the specified e-mail addresses
Log file not sent when Nomail dump
Olddir directory dumps the log file into the specified directory and must be in the same file system as the current log file
Noolddir dump log file and current log file in the same directory
Prerotate/endscript commands that need to be executed before dumping can be placed in this pair, these two keywords must be taken separately
Postrotate/endscript commands that need to be executed after the dump can be placed in this pair, these two keywords must be taken separately
Daily Specify a dump cycle of daily
Weekly specify the dump cycle as weekly
Monthly specify a dump cycle of monthly
Rotate count Specifies the number of dumps before the log file was deleted, 0 means no backup, 5 means 5 backups reserved
Tabootext [+] list lets logrotate not dump files with the specified extension, the default extension is:. Rpm-orig,. Rpmsave, V, and ~
Size size is not dumped when the log file reaches the specified size, and size can specify bytes (default) and KB (Sizek) or MB (sizem).
Oh, that's right. We can take a look at the/etc/cron.daily/logrotate script, which is a daily backup to help with the log.
This article from "Qiu Anxiaoqiu" blog, please be sure to keep this source http://heygirl32895.blog.51cto.com/7623150/1626043
Linux systems use Logrotate for log backups