首页 » SEO优化 » PHP怎么实现刊出日记技巧_日志切割的方法

PHP怎么实现刊出日记技巧_日志切割的方法

访客 2024-10-29 0

扫一扫用手机浏览

文章目录 [+]

一、logrotate日志切割是linux自带的

二、logrotate配置文件分为主配置和子配置

PHP怎么实现刊出日记技巧_日志切割的方法

主配置:/etc/logrotate.conf

PHP怎么实现刊出日记技巧_日志切割的方法
(图片来自网络侵删)

子配置:/etc/logrotate.d/下面的文件

三、logrotate是基于CRON运行的,其脚本为/etc/cron.daily/logrotate

[root@localhost ~]# cat /etc/cron.daily/logrotate #!/bin/sh/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.confEXITVALUE=$?if [ $EXITVALUE != 0 ]; then /usr/bin/logger -t logrotate \"大众ALERT exited abnormally with [$EXITVALUE]\公众fiexit 0

实际运行时会调用配置文件/etc/logrotate.conf

四、logrotate基于CRON运行,以是实行韶光由CRON掌握

ubuntu查看/etc/crontab

centos查看/etc/anacrontab

root@qqq:/etc/logrotate.d# cat /etc/crontab # /etc/crontab: system-wide crontab# Unlike any other crontab you don't have to run the `crontab'# command to install the new version when you edit this file# and files in /etc/cron.d. These files also have username fields,# that none of the other crontabs do.SHELL=/bin/shPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin# m h dom mon dow user command17 root cd / && run-parts --report /etc/cron.hourly25 6 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )47 6 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )52 6 1 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )#

没错,run-parts是运行一个目录中的所有脚本或程序,--report的功能与--verbose功能类似,自己去领悟

没错,logrotate脚本是/etc/cron.daily/目录下面的脚本,CRON每天06:25运行/etc/cron.daily/目录下面的所有脚本

五、logrotate命令:

logrotate命令格式:logrotate [OPTION...] <configfile>-d, --debug :debug模式,测试配置文件是否有缺点。
-f, --force :逼迫转储文件。
-m, --mail=command :压缩日志后,发送日志到指定邮箱。
-s, --state=statefile :利用指定的状态文件。
-v, --verbose :显示转储过程。

六、logrotate配置文件常见参数

compress 通过gzip 压缩转储往后的日志nocompress 不做gzip压缩处理copytruncate 用于还在打开中的日志文件,把当前日志备份并截断;是先拷贝再清空的办法,拷贝和清空之间有一个韶光差,可能会丢失部分日志数据。
nocopytruncate 备份日志文件不过不截断create mode owner group 轮转时指定创建新文件的属性,如create 0777 nobody nobodynocreate 不建立新的日志文件delaycompress 和compress 一起利用时,转储的日志文件到下一次转储时才压缩nodelaycompress 覆盖 delaycompress 选项,转储同时压缩。
missingok 如果日志丢失,不报错连续滚动下一个日志errors address 专储时的缺点信息发送到指定的Email 地址ifempty 纵然日志文件为空文件也做轮转,这个是logrotate的缺省选项。
notifempty 当日志文件为空时,不进行轮转mail address 把转储的日志文件发送到指定的E-mail 地址nomail 转储时不发送日志文件olddir directory 转储后的日志文件放入指定的目录,必须和当前日志文件在同一个文件系统noolddir 转储后的日志文件和当前日志文件放在同一个目录下sharedscripts 运行postrotate脚本,浸染是在所有日志都轮转后统一实行一次脚本。
如果没有配置这个,那么每个日志轮转后都会实行一次脚本prerotate 在logrotate转储之前须要实行的指令,例如修正文件的属性等动作;必须独立成行postrotate 在logrotate转储之后须要实行的指令,例如重新启动 (kill -HUP) 某个做事!
必须独立成行daily 指定转储周期为每天weekly 指定转储周期为每周monthly 指定转储周期为每月rotate count 指定日志文件删除之前转储的次数,0 指没有备份,5 指保留5 个备份dateext 利用当期日期作为命名格式dateformat .%s 合营dateext利用,紧跟不才一行涌现,定义文件切割后的文件名,必须合营dateext利用,只支持 %Y %m %d %s 这四个参数size(或minsize) log-size 当日志文件到达指定的大小时才转储,log-size能指定bytes(缺省)及KB (sizek)或MB(sizem).当日志文件 >= log-size 的时候就转储。
以下为合法格式:(其他格式的单位大小写没有试过)size = 5 或 size 5 (>= 5 个字节就转储)size = 100k 或 size 100ksize = 100M 或 size 100M

七、附上生产环境的几个配置文件

root@web1:/etc/logrotate.d# cat nginx/var/log/nginx/.log { daily missingok rotate 14 compress delaycompress notifempty create 0640 www-data adm sharedscripts prerotate if [ -d /etc/logrotate.d/httpd-prerotate ]; then \ run-parts /etc/logrotate.d/httpd-prerotate; \ fi \ endscript postrotate invoke-rc.d nginx rotate >/dev/null 2>&1 endscript}

zabbix这个

root@web1:/etc/logrotate.d# cat zabbix-agent /var/log/zabbix/zabbix_agentd.log { weekly rotate 12 compress delaycompress missingok notifempty create 0640 zabbix zabbix}

php这个慢查询和缺点日志

root@web1:/etc/logrotate.d# cat php7.0-fpm /var/log/php7.0-fpm.log { rotate 12 weekly missingok notifempty compress delaycompress postrotate /usr/lib/php/php7.0-fpm-reopenlogs endscript}/var/log/php/.log { rotate 12 daily missingok notifempty compress delaycompress }

相关文章

介绍百度网盘,云端存储时代的创新先锋

随着互联网技术的飞速发展,云计算已经成为现代生活不可或缺的一部分。而在这其中,百度网盘作为国内领先的云存储服务提供商,以其卓越的性...

SEO优化 2025-01-03 阅读1 评论0

介绍监控屏蔽技术,守护个人隐私的利器

随着科技的发展,监控设备已经深入到我们生活的方方面面。在享受便利的隐私安全问题也日益凸显。如何有效屏蔽监控,保护个人隐私,成为人们...

SEO优化 2025-01-03 阅读1 评论0

介绍番号观看方法,轻松驾驭影视世界

随着互联网的普及,网络影视资源日益丰富,番号作为影视作品的标识码,已经成为广大观众了解、搜索和观看影视作品的重要途径。如何正确地使...

SEO优化 2025-01-03 阅读1 评论0

介绍盗微信号黑幕,网络安全的严峻挑战

在数字化时代,微信已成为人们生活中不可或缺的通讯工具。随着微信用户数量的激增,盗微信号的事件也日益增多。本文将深入剖析盗微信号的方...

SEO优化 2025-01-03 阅读1 评论0