In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
It has been a headache for nginx logs to grow over time, but we can actually send a signal USR1 to the nginx main process to generate new log files, and then archive the old log files. Here is the script I used to split the logs.
[root@master ~] # cat / HomeAccord TestCharger binbinqqinxpostreloadlogfile.shandhelplash Bash # log_pathbase_path='/usr/local/nginx-1.12.1/logs'# get year and monthyear_month=$ (date-d yesterday + "% Y% m") # get yesterdayday=$ (date-d yesterday + "% d") # create backup directorymkdir-p $base_path/$year_month# copy logfile to backupmv $base_path/access.log $base_path/$year_month/access_$day .log # echo $base_path/$year_month/access_$day.log# reload logfilekill-USR1 `cat / usr/local/nginx-1.12.1/logs/ nginx.pid`
Add a scheduled task to crontab and execute the script to split the log at 23:59 every day
# nginx access log backup59 23 * sh / home/ysyf/bin/nginx_reload_logfile.sh
The effect of slicing is as follows, of course, you can also customize the path you like and modify the script.
[root@master / usr/local/nginx-1.12.1/logs] # ll Total usage 490828drwxr-xr-x 2 root root 4096 October 1 23:59 201909drwxr-xr-x 2 root root 4096 October 31 23:59 201910 error.log-rw-r--r-- error.log-rw-r--r-- 1 root-1 nobody root 2477169 November 1 23:24 access.log-rw-r--r-- 1 nobody root 499617441 November 1 23:24 Root 6 December 31 2018 nginx.pid [root@master / usr/local/nginx-1.12.1/logs] # cd 201910 [root@master / usr/local/nginx-1.12.1/logs/201910] # ll Total usage 64348 nobody root nobody root 955541 October 3 23:53 access_02.log-rw-r--r -- 1 nobody root 1328787 October 4 23:46 access_03.log-rw-r--r-- 1 nobody root 533591 October 5 23:54 access_04.log-rw-r--r-- 1 nobody root 1048041 October 6 23:59 access_05.log-rw-r--r-- 1 nobody root 402311 October 7 23:56 access_06.log-rw-r--r-- 1 nobody root 3036879 October 8 23:58 access_07.log-rw -nobody root nobody root 2848916 October 9 23:48 access_08.log-rw-r--r-- 1 nobody root 2814881 October 10 23:58 access_09.log-rw-r--r-- 1 nobody root 3424007 October 11 23:51 access_10.log
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: 265
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.