The Logrotate program is a log file management tool. Used to split the log file, delete the old log file, and create a new log file that acts as a "dump". You can save disk space.
logrotate command format:
Logrotate [OPTION ...] <configfile>
-D,--debug:debug mode, Test the configuration file for errors.
-F,--force: Forced dump file.
-M,--mail=command: Sends the log to the specified mailbox.
-S,--state=statefile: uses the specified state file.
-V,--verbose: Displays the dump process.
Logrotate is/etc/logrotate.conf. To view the default configuration:
Cat/etc/logrotate.conf
Shown below:
# see ' Man logrotate ' for details
# Rotate log Files Weekly
Weekly
# Keep 4 weeks worth of backlogs
Rotate 4
# Create new (empty) log files after rotating old ones
Create
# Uncomment this if you want your log files compressed
#compress
# RPM Packages Drop log rotation information into this directory
Include/etc/logrotate.d
# no packages own wtmp--we'll rotate them here
/var/log/wtmp {
Monthly
MinSize 1M
Create 0664 Root utmp
Rotate 1
}
# system-specific logs May is also is configured here.
Brief description:
Weekly: All log files are dumped once a week.
Rotate 4: The dump file is divided into 4 parts.
Create:logrotate automatically creates a new log file.
Compress: Compresses the log file. The default is commented out.
INCLUDE/ETC/LOGROTATE.D: Read into the log dump parameter in the/ETC/LOGROTATE.D directory, when the RPM package is installed in the system, the log dump parameters of the RPM packet are usually automatically established in the/ETC/LOGROTATE.D directory.
/VAR/LOG/WTMP segment: Configuration of the/var/log/wtmp log dump.
Use Logrotate management Lnmp to install the connection log for Nginx in the package, lnmp the log file in the/home/wwwlogs directory.
To create a configuration file:
Vim/etc/logrotate.d/nginx
Enter as follows:
/home/wwwlogs/access.log/home/wwwlogs/nginx_error.log {
Notifempty
Daily
Rotate 5
sharedscripts
postrotate
/bin/kill-hup '/bin/cat/usr/local/nginx/logs/nginx.pid '
Endscript
}
Description
Notifempty: If it is an empty file, do not dump it.
Daily: Log files are dumped once a day.
Rotate 5; The dump file is divided into 5 parts.
Postrotate/endscript: script executed after the log dump. This is used to let Nginx regenerate the log file. The nginx.pid is the main process number of nginx.
Execution Logrotate:
/usr/sbin/logrotate-vf/etc/logrotate.conf
If there is no error, generated a dump file, Nginx normal access, OK.
How the logrotate automatically executes:
There are scripts executed by logrotate in the/etc/cron.daily directory. Executed once a day through the crontab program.
This article is from the "track to record work learning" blog, so be sure to keep this source http://stephenliu.blog.51cto.com/6470474/1564553
CentOS Linux uses logrotate to split management logs