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

Using nginx to divide logs at a fixed time every day under CentOS 7.0,

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

Share

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

As we all know, there is a file in the log generated by Nginx. With the longer the running time of the website, the size of the log file is also growing, so it is necessary to achieve timing segmentation at this time. This article mainly introduces the relevant information about nginx to achieve regular division of logs every day under CentOS 7.0. friends who need it can refer to it.

Environment description:

Operating system CentOS7.0, nginx is installed online by default.

Nginx profile path: / etc/nginx/nignx.conf

Nginx log file path: / var/log/nginx/access.log

Nignx.pid path: / run/nginx.pid

New timing script location / shell/nginx/logs.sh

1. Create a new script and execute

# mkdir / shell/nignx#cd / shell/nginx#vim logs.sh http://www.iis7.com/b/ssyqdq/

#! / bin/bashbase_path='/var/log/nginx'log_path= (date − d yesterday + "(date-d yesterday +"% Y% m ") day= (date − d yesterday +" (date-d yesterday + "% Y%m%d") mkdir-p base path/ base_path/ base path/ log_pathmv$base_path/access.log Base path/ base_path/ base path/ log_path/access_$day.log#echo base path/ base_path/ base path/ log_path/access_$day.logkill-USR1 cat / run/nginx.pid

# chmod a+X#./logs.sh

two。 Regular execution (0: 00 every day)

# crontab-eBay 0 0 * / bin/bash / shell/nginx/logs.sh#wq

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