When you click on a link or refresh the interface on our web page , the Apache log file in the background will record a line or a few lines of information, if your site has a considerable amount of traffic, then after a period of time your Apache log files become bloated, and when the server has a problem, in a hundreds of trillion or even several G It becomes difficult to find useful information in the log file. So we need to regularly split enough log files into a small log, which is the log rotation. Log rotation is actually a combination of log cutting and log rotation 0
Log Cutting: The old log file is moved and renamed, and a new log file is created. So how to name it?
mainly rely on/ETC/LOGROTATE.COFof the configuration file"Dateext"
1.If the configuration file has "Dateext"parameter, the log will use the date as the suffix for the log file, for example"access_log-20150517". In this case, the log file will not overlap, so you do not need to rename the log file.
2.If the configuration file does not have "Dateext"parameter, the log file will need to be renamed when the first log rotation is current"Access_log"The log will be renamed to"Access_log.1", let's Create a new"Access_log"file, when making a second log rotation"Access_log.1"will be renamed to"access_log.2", and"Access_log"The file will be renamed to"Access_log.1"then new"Access_log"File to save the new log information. And so on
Log Replacement : When the old log exceeds the saved range, the oldest log is deleted.
apache Span style= "font-family: ' The song Body '; > distance to log rotation
note: rpm apache apache The own configuration file only supports log cutting, Without a log replacement, the old log is not deleted. This is required with the help of the system's log rotation tool logrotate
logrotate the configuration file is /etc/logrotate.conf There's a log file configuration that needs to be replaced in this file, and we just need to Apache log file can be written to this configuration file;
650) this.width=650; "title=" Adf.png "src=" http://s3.51cto.com/wyfs02/M01/6E/11/ Wkiol1vy5xgdj7mpaaghcxrg91g626.jpg "alt=" Wkiol1vy5xgdj7mpaaghcxrg91g626.jpg "/>
Detailed content
/usr/local/apache/logs/access_log {
Absolute path to #Apache log file
Daily
# The cycle of log rotation is day
Dateext
# use dates to log file suffix names
Notifempty
# If the log file is empty, no rotation will be made
Rotate 30
# Number of log files reserved. If write 0 means no backup
}
Save exit
when the above settings are complete Apache log file will be replaced by a rotation
logrotate configuration file Parameters:
daily |
The rotation cycle for the journal is | every day
weekly |
|
monthly |
The rotation period for the journal is | per month
rotate |
0 |
compress |
log rotation, old log compressed |
create mode owner group |
Create a new log, specifying the permissions of the new log and the owner and the owning group. such as create0600 root utmp |
mail address |
mail [email protected] |
missingok |
If the log does not exist, ignore the warning message for the log |
notifempty |
If the log is an empty file, do not log rotation |
minsize   |
|
dateext |
use date as the suffix of the journal rotation file. such as secure-20130605 |
sharedscripts |
|
prerotate/endscript |
execute the script command before the log rotation. endscript flag prerotate the script ends. |
Postrotate/endscript |
executes the script command after the log rotation. endscript Mark postrotate script End |
logrotate Command Introduction
logrotate [ options ] Profile Name
Option: If there is no option to follow the log rotation for the contents of the configuration file
- v : Show log rotation process
- F : Force log rotation, whether or not the conditions of the log rotation are met, forcing all the logs in the configuration file to be rotation
configuration files are generally /etc/logrotate.conf file
This article is from the "Aforetime for the King" blog, please be sure to keep this source http://zhanshanweiwang.blog.51cto.com/9764673/1659275
Introduction to Journal rotation