当前位置:网站首页>Use logrotate to automatically cut the website logs of the pagoda
Use logrotate to automatically cut the website logs of the pagoda
2022-06-28 11:38:00 【jwj】
By default , Of the pagoda WEB When the software logs , Logs are not stored in different files by date , Long time logs are recorded in a file , It is very inconvenient to consult and manage .
One 、 install logrotate
Most of the Linux The system usually comes with logrotate, If it happens that your system doesn't come with , Sure stay github Download source code Build and install .
Or try to install directly with the command , for example :
- Red hat system (Red Hat):
yum install logrotateordnf install logrotate - ubuntu (Ubuntu):
sudo apt-get install logrotateorapt install logrotate
Two 、 principle
Actually “ cutting ” The two words are not correct , Let's briefly talk about the working principle of personal understanding . 1.logrotate Execution time , Files that meet the conditions set in the configuration will be processed . 2. Then rename the log file , And create a new log file . 3. Perform other operations , Such as : Compressed files .
3、 ... and 、 To configure
Create and edit a profile
sudo vim /etc/logrotate.d/btweblogsConfigure the content
/www/wwwlogs/*.log {
# Time interval between :daily= Every day /weekly= Once a week /monthly= monthly /yearly= Every year,
daily
# Number of copies to be retained , Old logs exceeding this number will be deleted automatically
rotate 14
# Ignore mistakes , Such as : file does not exist
missingok
# Rename file using date format
dateext
# Compress the separated files
compress
# Do not compress the files separated this time
delaycompress
# Ignore empty files ( That is, do not separate empty files )
notifempty
# Execute the script only once after multiple files are separated
sharedscripts
# Script executed after file separation
postrotate
# notice Nginx and Apache routine overloading
# Nginx
[ -e /www/server/nginx/logs/nginx.pid ] && kill -USR1 `cat /www/server/nginx/logs/nginx.pid`
# Apache
[ -e /www/server/apache/logs/httpd.pid ] && kill -USR1 `cat /www/server/apache/logs/httpd.pid`
endscript
}Four 、 end
logrotate In addition to the ability to separate compressed files , You can also send the separated files to the specified mailbox by mail , For specific methods, please refer to logrotate Manuals .
The pagoda itself also has a log cutting function , If there is no need for compression , You can use the functions of the pagoda .
边栏推荐
猜你喜欢

Day36 JS notes ecma6 syntax 2021.10.09

Packaging and publishing application of jetpack compose desktop version

day34 js笔记 正则表达式 2021.09.29

Blue Bridge Cup Maze (dfs+ backtracking)

Day37 JS note motion function 2021.10.11

《运营之光3.0》全新上市——跨越时代,自我颠覆的诚意之作!

ThreadLocal的简单理解

Docker modifies the user name and password of MySQL

智联招聘基于 Nebula Graph 的推荐实践分享

Redis6 1: what problems can be solved by the introduction of NoSQL and redis?
随机推荐
Making and using of dynamic library (shared library)
2022 open source software security status report: over 41% of enterprises do not have enough confidence in open source security
Get current system date
SQL中的DQL、DML、DDL和DCL是怎么区分和定义的
soapui的菜鸟教程
js中this的默认指向及如何修改指向 2021.11.09
李宏毅《机器学习》丨7. Conclusion(总结)
[sciter]:sciter如何使用i18实现桌面应用多语言切换及其利弊
JS foundation 1-js introduction and operator
Dongyuhui, New Oriental and Phoenix Satellite TV
When an entity is converted to JSON, the field with null value is lost
mysql-.sql文件钓鱼上线
2022中国信通院首届业务与应用安全发展论坛成功召开!
实体转JSON时,值为null的字段的丢失问题
QML控件类型:TabBar
ThreadLocal的简单理解
无法重新声明块范围变量
day34 js笔记 正则表达式 2021.09.29
近况
Thesis reading (59):keyword based diverse image retrieval with variable multiple instance graph