In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "nginx log how to regularly cut", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "nginx log how to regularly cut" it!
Recently, there is a need to check the number of daily active users on our official website. I intend to check the nginx log, cut each log, filter out the ip, and then remove the duplicates through the set collection. The length of the collection set is the number of daily active users of the day. My nginx is installed through yum, and the nginx log is sliced by default, but not at 00:00 of the day, so the number of daily active users may not be accurate. I'm going to customize the cutting of nginx logs.
The so-called "cut" does not really "cut into two" a file, but renames the original "access.log" file, such as today's date "2020-05-17.log", and then creates a new file called "access.log" so that the newly generated log can still be written to a new file called "access.log". In this way, the effect of so-called "log scrolling" or "log cutting" can be achieved.
However, there are some problems with this. Let's do it manually. First, rename the file.
Mv access.log 2020-05-17.log
We have renamed the "access.log" file, but you will find that after renaming, the nginx log will still be written to the "2020-05-17.log" file, and will not automatically create a new "access.log" file, even if you manually create a new "access.log" file, nginx will still write the log to the renamed "2020-05-17.log" file.
The above situation, because the nginx process to read and write log files, is through the file descriptor to operate, although we modified the original "access.log" file name, but the original file descriptor and the corresponding relationship between the file itself still exists, so, just rename the file is not enough, we need to let nginx re-open a new file, in order to write the new log to the new file.
After installing nginx through the yum source, a log scrolling configuration file is installed by default, which is "/ etc/logrotate.d/nginx" and needs to be deleted. The default log path is "/ var/log/nginx/". I wrote a shell script, nginx_log_split.sh, under this folder.
Date $(date +% Y-%m-%d) # get the date of the day # move the file mv-f / var/log/nginx/access.log / var/log/nginx/$ {D} .logsleep 0.5s# restart nginx/usr/sbin/nginx-s reload
Use crontab to perform scheduled tasks, and edit one line after crontab-e
00 00 * / var/log/nginx/nginx_log_split.sh
Thank you for your reading, the above is the content of "how to regularly cut the nginx log". After the study of this article, I believe you have a deeper understanding of how to regularly cut the nginx log, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
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.