当前位置:网站首页>使用logrotate对宝塔的网站日志进行自动切割
使用logrotate对宝塔的网站日志进行自动切割
2022-06-28 10:54:00 【jwj】
默认情况下,宝塔的 WEB 软件记录日志时,不会按日期将日志储存到不同的文件里,长时间的日志都记录到一个文件里,很不方便查阅和管理。
一、安装 logrotate
大多 Linux 系统一般都自带 logrotate,如果刚好你的系统没有自带,可以在github下载源代码进行编译安装。
或者直接尝试用命令进行安装,例如:
- 红帽系统(Red Hat):
yum install logrotate或dnf install logrotate - 乌班图(Ubuntu):
sudo apt-get install logrotate或apt install logrotate
二、原理
其实“切割”二字并不对,具体我们来简单说说个人理解的工作原理。 1.logrotate 执行时,会对符合配置里设定的条件的文件进行处理。 2.然后重命名日志文件,并创建新的日志文件。 3.执行其它操作,如:压缩文件。
三、配置
新建并编辑配置文件
sudo vim /etc/logrotate.d/btweblogs配置内容
/www/wwwlogs/*.log {
# 间隔时间:daily=每天/weekly=每周/monthly=每月/yearly=每年
daily
# 保留份数,超过该数量的旧日志自动删除
rotate 14
# 忽略错误,如:文件不存在
missingok
# 使用日期格式重命名文件
dateext
# 对分离出来的文件进行压缩
compress
# 不压缩本次分离出来的文件
delaycompress
# 忽略空文件(即不分离空的文件)
notifempty
# 多个文件分离后只执行一次脚本
sharedscripts
# 文件分离后执行的脚本
postrotate
# 通知Nginx和Apache程序重载
# 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
}四、结束
logrotate 除了可以分离压缩文件,还可以将分离出来的文件通过邮件发送到指定邮箱,具体方法可以查阅 logrotate 的手册。
宝塔本身也有日志切割功能,如果没有压缩之类的需求,可以使用宝塔的功能。
边栏推荐
- Blue Bridge Cup Maze (dfs+ backtracking)
- Xshell和Xftp使用教程
- Realize an air conditioner with compose to bring you cool in summer
- Makefile简介
- SQL中的DQL、DML、DDL和DCL是怎么区分和定义的
- An idea plug-in that automatically generates unit tests, which improves the development efficiency by more than 70%!
- 乌国家安全与国防委员会秘书:将对俄境内目标进行精确打击
- JSON模块、hashlib、base64
- 移动命令
- JS基础3
猜你喜欢

Solve the problem of reading package listsdonebuilding dependency treereading state informationdone

Katalon framework tests web (XX) custom keywords and upload pop-up operations

Summary of characteristics of five wireless transmission protocols of Internet of things

动态库(共享库)的制作和使用

【monkey】monkey测试入门
![[practice] appium settings app is not running after 5000ms](/img/3c/5a7544561231a15a4bb5cfa9e102b3.png)
[practice] appium settings app is not running after 5000ms

JS foundation 1-js introduction and operator

JS基础3

远程登录sshd服务

DlhSoft Kanban Library for WPF
随机推荐
GCC简介
GEE:基于 MCD64A1 的 GlobFire 日常火灾数据集
DlhSoft Kanban Library for WPF
Remote connection of raspberry pie in VNC viewer mode without display
How to use K-line diagram for technical analysis
壓縮解壓
JS基础8
MySQL (III)
Wealth management for programmers
Katalon当中的使用循环for、while和if...else、break、continue
How to use output in katalon
SQL中的DQL、DML、DDL和DCL是怎么区分和定义的
[leetcode daily question] [December 19, 2021] 997 Find the town judge
【功能建议】多个工作空间启动时选择某个空间
【Qt】connect 语法参考实现
sentinel
[cloud resident co creation] detailed introduction to DWS alarm service DMS and cluster connection mode
Six fusion positioning technologies in wireless communication application of Internet of things
Does flink1.15 support MySQL views? I configured the view name at the table name to save, but the table could not be found. Think
appliedzkp zkevm(9)中的Bytecode Proof