Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use logrotate to cut nginx logs

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Configuration:

1. Create a nginx configuration file "nginx" in the / etc/logrotate.d directory as follows

# vim / etc/logrotate.d/nginx

/ usr/local/nginx/logs/*.log {

Daily

Rotate 5

Missingok

Notifempty

Sharedscripts

Postrotate

If [- f / usr/local/nginx/logs/nginx.pid]; then

Kill-USR1 `cat / usr/local/nginx/logs/ nginx.pid`

Fi

Endscript

}

Save exit.

2. Execute logrotate

# / usr/sbin/logrotate-f / etc/logrotate.d/nginx

Will be generated in the / usr/local/nginx/logs directory

Error.log

Error.log.1

This indicates that the logrotate configuration is successful.

3. Let logrotate scroll once a day and add a timed script to crontab.

# crontab-e

59 23 * / usr/sbin/logrotate-f / etc/logrotate.d/nginx

Log scrolling takes place at 23:59 every day.

4. Configuration file description

Daily: log files are scrolled every day

Rotate: keep the log that scrolls up to 5 times

Notifempty: log files are empty and do not scroll

Sharedscripts: run the postrotate script

Here is a script

Postrotate

If [- f / usr/local/nginx/logs/nginx.pid]; then

Kill-USR1 `cat / usr/local/nginx/logs/ nginx.pid`

Fi

Endscript

The script asks nginx to regenerate the log file.

Reference blog post: http://linux008.blog.51cto.com/2837805/555829/

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report