The logrotate program is a log file management tool. Used to split log files, delete old log files, and create new log files to play the role of “dump”. Can save disk space.
logrotate command format: logrotate [OPTION...] <configfile>-d, --debug :debug mode, test the configuration file for errors. -f, --force : Forces the dump file. -m, --mail=command : Send logs to the specified mailbox. -s, --state=statefile : Use the specified state file. -v, --verbose : Shows the dump process. The logrotate configuration file is /etc/logrotate.conf. Check the default configuration:
cat /etc/logrotate.conf
Show as follows:
# see "man logrotate" for details# rotate log files weeklyweekly
# keep 4 weeks worth of backlogsrotate 4
# create new (empty) log files after rotating old onescreate
# uncomment this if you want your log files compressed#compress
# RPM packages drop log rotation information into this directoryinclude /etc/logrotate.d
# no packages own wtmp -- we'll rotate them here/var/log/wtmp {monthlyminsize 1Mcreate 0664 root Utmprotate 1}
# system-specific logs may be also be configured here.
Simple description: weekly: All log files are dumped once a week. Rotate 4 : The dumped file is divided into 4 copies. Create :logrotate automatically creates a new log file. Compress : Compresses the log file. The default is commented out. Include /etc/logrotate.d : Read the log dump parameters in the /etc/logrotate.d directory. When the RPM package is installed in the system, the log dump parameters of the RPM package are automatically created in /etc/logrotate. Under the .d directory. /var/log/wtmp section: Configuration of the /var/log/wtmp log dump.
Use logrotate to manage the connection log of nginx in the lnmp one-click installation package. The lnmp log file is in the /home/wwwlogs directory.
Create a configuration file:
vim /etc/logrotate.d/nginx
Enter the following:
/home/wwwlogs/access.log /home /wwwlogs/nginx_error.log {notifemptydailyrotate 5sharedscriptspostrotate/bin/kill -HUP `/bin/cat /usr/local/nginx/logs/nginx.pid`endscript}
Note: notifempty: if it is an empty file , do not dump. Daily : The log file is dumped once a day. Rotate 5 ; The dump file is divided into 5 copies. Postrotate/endscript : The script executed after the log dump. This is used to let nginx regenerate the log file. The nginx.pid contains the main process number of nginx.
Execute logrotate:
/usr/sbin/logrotate -vf /etc/logrotate.conf
If no error is reported, a dump file is generated and nginx is accessed normally. Ok.
How to auto-execute logrotate: There are scripts executed by logrotate in the /etc/cron.daily directory. Executed once a day through the crontab program.
Everyone knows that shell script is like a batch file (.bat) in the early DOS era. The simplest fun
With the rapid development of the Internet, more and more people use computers to obtain information
There are WINDOWS on the computer and LINUX Some people like GRUB, and some people like NT Loader to
In the era of virtualization and cloud computing and the container, we migrated all the application
P2v migration linux server under xenserver
What does the Unix/linux kernel play in the system?
Teach you 5 steps to restore the password of Ubuntu system
How to use Gearman for distributed computing
How to create sosreport in linux (RHEL 5.X /RHEL 6.X)
Display multi-core mode method under Linux
Amazon amozon AMI instance automatically installs Nginx script
Network-based RedHat system unattended installation
Introduction to linux environment variables
Computer technology: Get IE6 program support under Win7
Teach you how to do disk cleaning
Vista system added a virtual scanner to remove
Essential Skills: Achievements of Word Master's Eight Stunts
Can't upgrade Windows 10 with low capacity on the C drive?
The latest operating system share: Win8 failed curtain call
What should I do if the Win10 system taskbar volume icon is missing? Workbar no volume icon solution
How does the official version of Win10 replace Xiaona search with Google search?