linux 按天压缩并切割日志

linux 按天压缩并切割日志,第1张

1、linux 自带的 logrotate 命令

2、定义切割文件相关信息

/var/log/nginx/*.log {

daily #按天打包

rotate 180 #保存周期为180以内的,超过180天的则删除

missingok

notifempty

dateext

compress

nodelaycompress

sharedscripts

postrotate

/etc/init.d/nginx reload

endscript

}

3、crontab 设置一个定时任务

59 23 * * * /usr/sbin/logrotate -f /var/logrotate/nginx >>/tmp/logrotate.log

使用过Windows的人都知道,在使用windows系统的.过程中系统会变得越来越慢。而对于Windows下饱受诟病的各种垃圾文件都需要自己想办法删除,不然系统将会变得越来越大,越来越迟钝!windows怎么清理垃圾相信大家都知道的,那么linux下怎么清理系统垃圾呢?

Linux的文件系统比Windows的要优秀,不会产生碎片,对于长时间运行的服务器来说尤为重要,而且Linux系统本身也不会像Windows一样产生大量的垃圾文件。不知道这个说法有没有可信度!至少我们可以确定的是linux系统的文件系统是比较优秀的!

错误

rm -f logfile

原因

应用已经打开文件句柄,直接删除会造成:

1.应用无法正确释放日志文件和写入

2.显示磁盘空间未释放

正确

cat /dev/null >logfile

把一下代码保存为.sh后缀脚本来运行即可清除Linux系统日志

#!/bin/sh

cat /dev/null >/var/log/syslog

cat /dev/null >/var/adm/sylog

cat /dev/null >/var/log/wtmp

cat /dev/null >/var/log/maillog

cat /dev/null >/var/log/messages

cat /dev/null >/var/log/openwebmail.log

cat /dev/null >/var/log/maillog

cat /dev/null >/var/log/secure

cat /dev/null >/var/log/httpd/error_log

cat /dev/null >/var/log/httpd/ssl_error_log

cat /dev/null >/var/log/httpd/ssl_request_log

cat /dev/null >/var/log/httpd/ssl_access_log

另外清理linux系统垃圾还有以下命令

sudo apt-get autoclean 清理旧版本的软件缓存

sudo apt-get clean 清理所有软件缓存

sudo apt-get autoremove 删除系统不再使用的孤立软件


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/8647238.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-19
下一篇2023-04-19

发表评论

登录后才能评论

评论列表(0条)

    保存